Beispiel #1
0
static long s_sockexWrite( PHB_SOCKEX pSock, const void * data, long len, HB_MAXINT timeout )
{
   if( pSock->sd == HB_NO_SOCKET )
   {
      hb_socketSetError( HB_SOCKET_ERR_INVALIDHANDLE );
      return -1;
   }
   return pSock->cargo ? hb_znetWrite( HB_ZNET_GET( pSock ), pSock->sd, data, len, timeout, NULL ) :
                         hb_socketSend( pSock->sd, data, len, 0, timeout );
}
Beispiel #2
0
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;
}