static long s_sockexFlush( PHB_SOCKEX pSock, HB_MAXINT timeout, HB_BOOL fSync ) { if( pSock->sd == HB_NO_SOCKET ) { hb_socketSetError( HB_SOCKET_ERR_INVALIDHANDLE ); return -1; } return pSock->cargo ? hb_znetFlush( HB_ZNET_GET( pSock ), pSock->sd, timeout, fSync ) : 0; }
static int s_sockexClose( PHB_SOCKEX pSock, HB_BOOL fClose ) { int iResult; if( pSock->cargo ) { if( pSock->sd != HB_NO_SOCKET ) hb_znetFlush( HB_ZNET_GET( pSock ), pSock->sd, HB_MAX( 15000, pSock->iAutoFlush ), HB_TRUE ); hb_znetClose( HB_ZNET_GET( pSock ) ); } iResult = hb_sockexRawClear( pSock, fClose ); hb_xfree( pSock ); return iResult; }
static long s_srvSendAll( PHB_CONSRV conn, void * buffer, long len ) { HB_BYTE * ptr = ( HB_BYTE * ) buffer; long lSent = 0, lLast = 1, l; HB_MAXUINT end_timer; if( ! conn->mutex || hb_threadMutexLock( conn->mutex ) ) { end_timer = conn->timeout > 0 ? hb_dateMilliSeconds() + conn->timeout : 0; while( lSent < len && ! conn->stop ) { if( conn->zstream ) l = hb_znetWrite( conn->zstream, conn->sd, ptr + lSent, len - lSent, 1000, &lLast ); else l = lLast = hb_socketSend( conn->sd, ptr + lSent, len - lSent, 0, 1000 ); if( l > 0 ) { lSent += l; conn->wr_count += l; } if( lLast <= 0 ) { if( hb_socketGetError() != HB_SOCKET_ERR_TIMEOUT || hb_vmRequestQuery() != 0 || ( end_timer != 0 && end_timer <= hb_dateMilliSeconds() ) ) break; } } if( conn->zstream && lLast > 0 && ! conn->stop ) { if( hb_znetFlush( conn->zstream, conn->sd, conn->timeout > 0 ? conn->timeout : -1 ) != 0 ) lSent = -1; } if( conn->mutex ) hb_threadMutexUnlock( conn->mutex ); } return lSent; }