From a8981174ad9806348975beb65fcd77cccf4ff86d Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 16 May 2011 15:40:17 +0000 Subject: [PATCH] 2011-05-16 17:38 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbmisc/udpds.prg ! replaced previous workaround with one that doesn't need any delay in hb_UDPDS_Stop() --- harbour/ChangeLog | 5 +++++ harbour/contrib/hbmisc/udpds.prg | 20 ++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 118d8360d8..ee5660c5e1 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,11 @@ The license applies to all entries newer than 2009-04-28. */ +2011-05-16 17:38 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) + * contrib/hbmisc/udpds.prg + ! replaced previous workaround with one that doesn't need + any delay in hb_UDPDS_Stop() + 2011-05-16 09:33 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * include/harbour.hbx * src/vm/runner.c diff --git a/harbour/contrib/hbmisc/udpds.prg b/harbour/contrib/hbmisc/udpds.prg index 32542da61b..e431605c63 100644 --- a/harbour/contrib/hbmisc/udpds.prg +++ b/harbour/contrib/hbmisc/udpds.prg @@ -23,8 +23,6 @@ #include "hbsocket.ch" -STATIC s_lRunThread - /* Client */ FUNCTION hb_UDPDS_Find( nPort, cName ) @@ -59,7 +57,6 @@ FUNCTION hb_UDPDS_Start( nPort, cName, cVersion ) IF ! Empty( hSocket := hb_socketOpen( , HB_SOCKET_PT_DGRAM ) ) IF hb_socketBind( hSocket, { HB_SOCKET_AF_INET, "0.0.0.0", nPort } ) - s_lRunThread := .T. hb_threadDetach( hb_threadStart( @UDPDS(), hSocket, cName, cVersion ) ) RETURN hSocket ENDIF @@ -70,8 +67,6 @@ FUNCTION hb_UDPDS_Start( nPort, cName, cVersion ) PROCEDURE hb_UDPDS_Stop( hSocket ) - s_lRunThread := .F. - hb_idleSleep( 0.1 ) hb_socketClose( hSocket ) RETURN @@ -80,9 +75,16 @@ STATIC PROCEDURE UDPDS( hSocket, cName, cVersion ) LOCAL cBuffer, nLen, aAddr - DO WHILE s_lRunThread + DO WHILE .T. cBuffer := Space( 2000 ) - nLen := hb_socketRecvFrom( hSocket, @cBuffer, , , @aAddr, 1000 ) + BEGIN SEQUENCE WITH {| oErr | Break( oErr ) } + nLen := hb_socketRecvFrom( hSocket, @cBuffer, , , @aAddr, 1000 ) + RECOVER + nLen := NIL + END SEQUENCE + IF nLen == NIL + EXIT + ENDIF IF nLen == -1 IF hb_socketGetError() != HB_SOCKET_ERR_TIMEOUT RETURN @@ -94,7 +96,9 @@ STATIC PROCEDURE UDPDS( hSocket, cName, cVersion ) * Server response: ACK, ServerName, NUL, Version */ IF Left( cBuffer, nLen ) == Chr( 5 ) + cName + Chr( 0 ) - hb_socketSendTo( hSocket, Chr( 6 ) + cName + Chr( 0 ) + iif( cVersion == NIL, "", cVersion ), , , aAddr ) + BEGIN SEQUENCE WITH {| oErr | Break( oErr ) } + hb_socketSendTo( hSocket, Chr( 6 ) + cName + Chr( 0 ) + iif( cVersion == NIL, "", cVersion ), , , aAddr ) + END SEQUENCE ENDIF ENDIF ENDDO