2010-06-10 19:12 UTC+0300 Mindaugas Kavaliauskas (dbtopas/at/dbtopas.lt)

* harbour/examples/httpsrv/uhttpd.prg
  * harbour/examples/uhttpd2/umain.prg
    * optimized hb_socketRecv() calls
    * optimized (removed) hb_socketSelect() calls, current API
      has timeout parameter and make things simple

  * harbour/examples/commouse/commouse.prg
    ! fixed error reporting (missing hb_comGetError()) parameter

  * harbour/include/hbsocket.ch
    * adjusted comment text

  * harbour/contrib/hbtpathy/telepath.prg
    ! fixed missing nTimeout parameter in tp_send()

  * harbour/source/rtl/hbcomhb.c
    ! fixed typo in hb_comSend()
    ! fixed hb_storni() paramter order bugs
This commit is contained in:
Mindaugas Kavaliauskas
2010-06-10 16:12:39 +00:00
parent bf5511aa05
commit 508e2ec93f
7 changed files with 73 additions and 65 deletions

View File

@@ -16,6 +16,26 @@
The license applies to all entries newer than 2009-04-28.
*/
2010-06-10 19:12 UTC+0300 Mindaugas Kavaliauskas (dbtopas/at/dbtopas.lt)
* harbour/examples/httpsrv/uhttpd.prg
* harbour/examples/uhttpd2/umain.prg
* optimized hb_socketRecv() calls
* optimized (removed) hb_socketSelect() calls, current API
has timeout parameter and make things simple
* harbour/examples/commouse/commouse.prg
! fixed error reporting (missing hb_comGetError()) parameter
* harbour/include/hbsocket.ch
* adjusted comment text
* harbour/contrib/hbtpathy/telepath.prg
! fixed missing nTimeout parameter in tp_send()
* harbour/source/rtl/hbcomhb.c
! fixed typo in hb_comSend()
! fixed hb_storni() paramter order bugs
2010-06-10 18:00 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/include/hbclass.ch
! added missing TIMESTAMP class to ASSOCIATE CLASS command,

View File

@@ -288,7 +288,7 @@ FUNCTION tp_send( nPort, cString, nTimeout )
RETURN 0
ENDIF
RETURN hb_comSend( t_aPorts[ nPort, TPFP_HANDLE ], cString )
RETURN hb_comSend( t_aPorts[ nPort, TPFP_HANDLE ], cString,, nTimeout )
FUNCTION tp_sendsub( nPort, cString, nStart, nLength, nTimeout )

View File

@@ -22,12 +22,12 @@ LOCAL nPort, cBuf, cBuffer, nLen, nType, lL, lM, lR, nX, nY
ENDIF
IF ! hb_comOpen( nPort )
? "Unable to open port. Error:", hb_comGetError(), " OS error:", hb_comGetOsError()
? "Unable to open port. Error:", hb_comGetError( nPort ), " OS error:", hb_comGetOsError( nPort )
RETURN
ENDIF
IF ! hb_comInit( nPort, 1200, "N", 8, 1 )
? "Unable to initialize port. Error:", hb_comGetError(), " OS error:", hb_comGetOsError()
? "Unable to initialize port. Error:", hb_comGetError( nPort ), " OS error:", hb_comGetOsError( nPort )
hb_comClose( nPort )
RETURN
ENDIF

View File

@@ -599,32 +599,19 @@ FUNCTION MAIN( ... )
ENDIF
// Wait a connection
IF hb_socketSelect( { hListen },,,,,, 50 ) > 0
// reset remote values
aRemote := NIL
// Accept a remote connection
hSocket := hb_socketAccept( hListen, @aRemote )
IF hSocket == NIL
WriteToConsole( hb_StrFormat( "accept() error: %s", hb_socketGetError() ) )
IF EMPTY( hSocket := hb_socketAccept( hListen, @aRemote, 50 ) )
IF hb_socketGerError() == HB_SOCKET_ERR_TIMEOUT
// Checking if I have to quit
IF HB_FileExists( FILE_STOP )
FERASE( FILE_STOP )
EXIT
ENDIF
ELSE
// Send accepted connection to AcceptConnections() thread
hb_mutexNotify( s_hmtxQueue, hSocket )
WriteToConsole( hb_StrFormat( "accept() error: %s", hb_socketGetError() ) )
ENDIF
ELSE
// Checking if I have to quit
IF HB_FileExists( FILE_STOP )
FERASE( FILE_STOP )
EXIT
ENDIF
// Send accepted connection to AcceptConnections() thread
hb_mutexNotify( s_hmtxQueue, hSocket )
ENDIF
// Memory release
@@ -1700,12 +1687,12 @@ STATIC FUNCTION readRequest( hSocket, /* @ */ cRequest )
/* receive query */
cRequest := ""
DO WHILE .T.
cBuf := Space( 1 )
cBuf := Space( 4096 )
nLen := hb_socketRecv( hSocket, @cBuf )
IF nLen <= 0
EXIT
ENDIF
cRequest += cBuf
cRequest += LEFT( cBuf, nLen )
IF CR_LF + CR_LF $ cRequest
EXIT
ENDIF
@@ -1722,12 +1709,12 @@ STATIC FUNCTION readRequest( hSocket, /* @ */ cRequest )
*/
nPos -= Len( cRequest ) - At( CR_LF + CR_LF, cRequest ) - 3
WHILE nPos > 0
cBuf := Space( 1 )
cBuf := Space( nPos )
nLen := hb_socketRecv( hSocket, @cBuf, nPos )
IF nLen <= 0
EXIT
ENDIF
cRequest += cBuf
cRequest += LEFT( cBuf, nPos )
nPos -= nLen
ENDDO
ENDIF

View File

@@ -132,30 +132,29 @@ LOCAL nWaiters
Self:aSession := {=>}
DO WHILE .T.
IF (nI := hb_socketSelect({Self:hListen},,,,,, 1000)) > 0
hSocket := hb_socketAccept(Self:hListen)
IF hSocket == NIL
Self:LogError("[error] Accept error " + LTRIM(STR(hb_socketGetError())))
ELSE
hb_mutexQueueInfo( Self:hmtxQueue, @nWaiters )
? "New connection", hSocket
? "Waiters:", nWaiters
IF nWaiters < 2 .AND. LEN(aThreads) < THREAD_COUNT_MAX
/*
We need two threads in worst case. If first thread becomes a sessioned
thread, the second one will continue to serve sessionless requests for
the same connection. We create two threads here to avoid free thread count
check (and aThreads variable sync) in ProcessRequest().
*/
AADD(aThreads, hb_threadStart(@ProcessConnection(), Self))
AADD(aThreads, hb_threadStart(@ProcessConnection(), Self))
IF EMPTY( hSocket := hb_socketAccept(Self:hListen,, 1000) )
IF hb_socketGetError() == HB_SOCKET_ERR_TIMEOUT
EVAL(Self:bIdle, Self)
IF Self:lStop; EXIT
ENDIF
hb_mutexNotify(Self:hmtxQueue, {hSocket, ""})
ELSE
Self:LogError("[error] Accept error " + LTRIM(STR(hb_socketGetError())))
ENDIF
ELSE
EVAL(Self:bIdle, Self)
IF Self:lStop; EXIT
hb_mutexQueueInfo( Self:hmtxQueue, @nWaiters )
? "New connection", hSocket
? "Waiters:", nWaiters
IF nWaiters < 2 .AND. LEN(aThreads) < THREAD_COUNT_MAX
/*
We need two threads in worst case. If first thread becomes a sessioned
thread, the second one will continue to serve sessionless requests for
the same connection. We create two threads here to avoid free thread count
check (and aThreads variable sync) in ProcessRequest().
*/
AADD(aThreads, hb_threadStart(@ProcessConnection(), Self))
AADD(aThreads, hb_threadStart(@ProcessConnection(), Self))
ENDIF
hb_mutexNotify(Self:hmtxQueue, {hSocket, ""})
ENDIF
ENDDO
hb_socketClose(Self:hListen)
@@ -218,13 +217,14 @@ LOCAL hSocket, cRequest, cSend, aI, nLen, nI, nReqLen, cBuf
cRequest := ""
nLen := 1
DO WHILE AT(CR_LF + CR_LF, cRequest) == 0 .AND. nLen > 0
IF (nI := hb_socketSelect({hSocket},,,,,, 10000)) > 0 /* Timeout */
cBuf := Space( 1 )
nLen := hb_socketRecv(hSocket, @cBuf)
cRequest += cBuf
cBuf := Space( 4096 )
IF (nLen := hb_socketRecv(hSocket, @cBuf,,, 10000)) > 0 /* Timeout */
cRequest += LEFT(cBuf, nLen)
ELSE
nLen := 0
? "recv() timeout", hSocket
IF nLen == -1 .AND. hb_socketGetError() == HB_SOCKET_ERR_TIMEOUT
nLen := 0
? "recv() timeout", hSocket
ENDIF
ENDIF
ENDDO
@@ -263,9 +263,10 @@ LOCAL hSocket, cRequest, cSend, aI, nLen, nI, nReqLen, cBuf
/* receive query body */
DO WHILE LEN(cRequest) < nReqLen .AND. nLen > 0
cBuf := Space( 1 )
nLen := hb_socketRecv(hSocket, @cBuf)
cRequest += cBuf
cBuf := Space( 4096 )
IF (nLen := hb_socketRecv(hSocket, @cBuf,,, 500)) > 0
cRequest += LEFT( cBuf, nLen )
ENDIF
ENDDO
IF nLen == -1

View File

@@ -204,7 +204,7 @@
#define HB_SOCKET_IFINFO_HWADDR 8 /* hardware address */
#define HB_SOCKET_IFINFO_LEN 8
/* HB_SOCKETGETSOCKNAME(), HB_SOCKETGETPEERNAME() return value indexes */
/* Socket address array indexes */
#define HB_SOCKET_ADINFO_FAMILY 1
#define HB_SOCKET_ADINFO_ADDRESS 2 /* HB_SOCKET_AF_INET, HB_SOCKET_AF_INET6 */
#define HB_SOCKET_ADINFO_PATH 2 /* HB_SOCKET_AF_LOCAL */

View File

@@ -108,7 +108,7 @@ HB_FUNC( HB_COMFLOWCONTROL )
{
int iValue = 0;
hb_retl( hb_comFlowControl( hb_parni( 1 ), &iValue, hb_parni( 3 ) ) == 0 );
hb_storni( 2, iValue );
hb_storni( iValue, 2 );
}
HB_FUNC( HB_COMFLOWSET )
@@ -163,21 +163,21 @@ HB_FUNC( HB_COMLSR )
{
int iValue = 0;
hb_retl( hb_comLSR( hb_parni( 1 ), &iValue ) == 0 );
hb_storni( 2, iValue );
hb_storni( iValue, 2 );
}
HB_FUNC( HB_COMMCR )
{
int iValue = 0;
hb_retl( hb_comMCR( hb_parni( 1 ), &iValue, hb_parni( 3 ), hb_parni( 4 ) ) == 0 );
hb_storni( 2, iValue );
hb_storni( iValue, 2 );
}
HB_FUNC( HB_COMMSR )
{
int iValue = 0;
hb_retl( hb_comMSR( hb_parni( 1 ), &iValue ) == 0 );
hb_storni( 2, iValue );
hb_storni( iValue, 2 );
}
HB_FUNC( HB_COMOPEN )
@@ -237,5 +237,5 @@ HB_FUNC( HB_COMSEND )
if( lParam >= 0 && lParam < lLen )
lLen = lParam;
}
hb_retnl( hb_comSend( hb_parni( 1 ), hb_parc( 2 ), lLen, hb_parnint( 5 ) ) );
hb_retnl( hb_comSend( hb_parni( 1 ), hb_parc( 2 ), lLen, hb_parnint( 4 ) ) );
}