Beispiel #1
0
static HB_GARBAGE_FUNC( hb_inetSocketFinalize )
{
   PHB_SOCKET_STRUCT socket = ( PHB_SOCKET_STRUCT ) Cargo;

   if( socket->sd != HB_NO_SOCKET )
      hb_inetCloseSocket( socket, HB_TRUE );
   else
      hb_inetCloseStream( socket );

   if( socket->pPeriodicBlock )
   {
      hb_itemRelease( socket->pPeriodicBlock );
      socket->pPeriodicBlock = NULL;
   }
   if( socket->remote )
   {
      hb_xfree( socket->remote );
      socket->remote = NULL;
   }
   if( socket->buffer )
   {
      hb_xfree( socket->buffer );
      socket->buffer = NULL;
   }
}
Beispiel #2
0
static HB_GARBAGE_FUNC( hb_inetSocketFinalize )
{
   PHB_SOCKET_STRUCT socket = ( PHB_SOCKET_STRUCT ) Cargo;

   if( socket->sd != HB_NO_SOCKET )
   {
      hb_socketShutdown( socket->sd, HB_SOCKET_SHUT_RDWR );
      hb_inetCloseSocket( socket );
   }

   if( socket->pPeriodicBlock )
   {
      hb_itemRelease( socket->pPeriodicBlock );
      socket->pPeriodicBlock = NULL;
   }
   if( socket->remote )
   {
      hb_xfree( socket->remote );
      socket->remote = NULL;
   }
   if( socket->buffer )
   {
      hb_xfree( socket->buffer );
      socket->buffer = NULL;
   }
   hb_inetCloseStream( socket );
}
Beispiel #3
0
static void hb_inetConnectInternal( HB_BOOL fResolve )
{
   const char * szHost = hb_parc( 1 );
   char * szAddr = NULL;
   PHB_SOCKET_STRUCT socket = HB_PARSOCKET( 3 );
   PHB_ITEM pSocket = NULL;
   int iPort = hb_parni( 2 );

   if( szHost == NULL || iPort == 0 || ( socket == NULL && ! HB_ISNIL( 3 ) ) )
      hb_inetErrRT();
   else
   {
      if( ! socket )
         HB_SOCKET_INIT( socket, pSocket );
      else if( socket->sd != HB_NO_SOCKET )
         hb_inetCloseSocket( socket, HB_FALSE );

      if( fResolve )
         szHost = szAddr = hb_socketResolveAddr( szHost, HB_SOCKET_AF_INET );

      if( fResolve && ! szAddr )
      {
         hb_inetGetError( socket );
         if( socket->iError == 0 )
            socket->iError = HB_SOCKET_ERR_WRONGADDR;
      }
      else
      {
         /* Creates comm socket */
         socket->sd = hb_socketOpen( HB_SOCKET_PF_INET, HB_SOCKET_PT_STREAM, 0 );
         if( socket->sd == HB_NO_SOCKET )
            hb_inetGetError( socket );
         else
         {
            if( socket->remote )
               hb_xfree( socket->remote );
            if( hb_socketInetAddr( &socket->remote, &socket->remotelen,
                                   szHost, iPort ) )
            {
               hb_socketSetKeepAlive( socket->sd, HB_TRUE );
               if( hb_socketConnect( socket->sd, socket->remote, socket->remotelen,
                                     socket->iTimeout ) != 0 )
                  hb_inetGetError( socket );
               else
                  socket->iError = HB_INET_ERR_OK;
            }
            else
               hb_inetGetError( socket );
         }
         if( szAddr )
            hb_xfree( szAddr );
      }
      if( pSocket )
         hb_itemReturnRelease( pSocket );
      else
         hb_itemReturn( hb_param( 3, HB_IT_ANY ) );
   }
}