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

@@ -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