示例#1
0
文件: hbznet.c 项目: ggargano/hbtest2
/* create new stream structure
 */
PHB_ZNETSTREAM hb_znetOpen( int level, int strategy )
{
   PHB_ZNETSTREAM pStream = ( PHB_ZNETSTREAM ) hb_xgrab( sizeof( HB_ZNETSTREAM ) );

   memset( pStream, 0, sizeof( HB_ZNETSTREAM ) );

   if( level != Z_DEFAULT_COMPRESSION &&
       !( level >= Z_NO_COMPRESSION && level <= Z_BEST_COMPRESSION ) )
      level = Z_DEFAULT_COMPRESSION;

   if( strategy != Z_FILTERED     &&
#if defined( Z_RLE )
       strategy != Z_RLE          &&
#endif
#if defined( Z_FIXED )
       strategy != Z_FIXED        &&
#endif
       strategy != Z_HUFFMAN_ONLY )
      strategy = Z_DEFAULT_STRATEGY;

   if( deflateInit2( &pStream->wr, level,
                     Z_DEFLATED, -MAX_WBITS, HB_ZNET_MEM_LEVEL, strategy ) == Z_OK )
   {
      pStream->wr.next_out = pStream->outbuf = ( Bytef * ) hb_xgrab( HB_ZNET_BUFSIZE );
      pStream->wr.avail_out = HB_ZNET_BUFSIZE;

      pStream->rd.next_in = pStream->inbuf = ( Bytef * ) hb_xgrab( HB_ZNET_BUFSIZE );
      if( inflateInit2( &pStream->rd, -MAX_WBITS ) == Z_OK )
         return pStream;
   }

   hb_znetClose( pStream );
   return NULL;
}
示例#2
0
文件: netiosrv.c 项目: abebuch/core
static void s_consrv_disconnect( PHB_CONSRV conn )
{
   if( conn->sd != HB_NO_SOCKET )
   {
      hb_socketClose( conn->sd );
      conn->sd = HB_NO_SOCKET;
   }

   if( conn->zstream )
   {
      hb_znetClose( conn->zstream );
      conn->zstream = NULL;
   }
}
示例#3
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;
}
示例#4
0
文件: netiosrv.c 项目: abebuch/core
static void s_consrv_close( PHB_CONSRV conn )
{
   int i = 0;

   if( conn->rpcFilter )
      hb_itemRelease( conn->rpcFilter );

   while( conn->streams )
   {
      PHB_CONSTREAM stream = conn->streams;
      conn->streams = stream->next;
      hb_xfree( stream );
   }

   if( conn->mutex )
      hb_itemRelease( conn->mutex );

   if( conn->sd != HB_NO_SOCKET )
      hb_socketClose( conn->sd );

   if( conn->zstream )
      hb_znetClose( conn->zstream );

   while( conn->filesCount > 0 )
   {
      if( i >= NETIO_FILES_MAX )
         break;   /* internal error, it should not happen */

      if( conn->fileTable[ i ] )
      {
         hb_fileClose( conn->fileTable[ i ] );
         conn->filesCount--;
      }
      ++i;
   }

   hb_xfree( conn );
}