static void s_fileClose( PHB_FILE pFile ) { hb_socketShutdown( pFile->sd, HB_SOCKET_SHUT_RDWR ); hb_socketClose( pFile->sd ); hb_fsSetError( hb_socketGetError() ); hb_xfree( pFile ); }
static int hb_inetCloseSocket( PHB_SOCKET_STRUCT socket ) { int ret = hb_socketClose( socket->sd ); socket->sd = HB_NO_SOCKET; socket->inbuffer = 0; return ret; }
static HB_GARBAGE_FUNC( hb_socket_destructor ) { HB_SOCKET * pSocket = ( HB_SOCKET * ) Cargo; if( *pSocket != HB_NO_SOCKET ) { hb_socketClose( *pSocket ); *pSocket = HB_NO_SOCKET; } }
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; } }
static int hb_inetCloseSocket( PHB_SOCKET_STRUCT socket, HB_BOOL fShutDown ) { int ret; hb_inetCloseStream( socket ); if( fShutDown ) hb_socketShutdown( socket->sd, HB_SOCKET_SHUT_RDWR ); ret = hb_socketClose( socket->sd ); socket->sd = HB_NO_SOCKET; socket->inbuffer = 0; return ret; }
static HB_GARBAGE_FUNC( s_listensd_destructor ) { PHB_LISTENSD * lsd_ptr = ( PHB_LISTENSD * ) Cargo; if( *lsd_ptr ) { PHB_LISTENSD lsd = *lsd_ptr; *lsd_ptr = NULL; if( lsd->sd != HB_NO_SOCKET ) { hb_socketClose( lsd->sd ); lsd->sd = HB_NO_SOCKET; } hb_xfree( lsd ); } }
int hb_sockexRawClear( PHB_SOCKEX pSock, HB_BOOL fClose ) { int iResult = 0; if( fClose && pSock->sd != HB_NO_SOCKET ) { if( pSock->fShutDown ) hb_socketShutdown( pSock->sd, HB_SOCKET_SHUT_RDWR ); iResult = hb_socketClose( pSock->sd ); } if( pSock->buffer ) hb_xfree( pSock->buffer ); memset( pSock, 0, sizeof( *pSock ) ); pSock->sd = HB_NO_SOCKET; return iResult; }
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 ); }
static PHB_FILE s_fileOpen( PHB_FILE_FUNCS pFuncs, const char * pszName, const char * pszDefExt, HB_FATTR nExFlags, const char * pPaths, PHB_ITEM pError ) { const char * pszHost = pszName + FILE_PREFIX_LEN, * ptr; PHB_FILE pFile = NULL; HB_ERRCODE errcode = 0; HB_SIZE nLen = 0; int iPort = 0; HB_MAXINT timeout = -1; HB_SYMBOL_UNUSED( pFuncs ); HB_SYMBOL_UNUSED( pszDefExt ); HB_SYMBOL_UNUSED( pPaths ); if( ( ptr = strchr( pszHost, ':' ) ) != NULL && ptr != pszHost ) { nLen = ptr - pszHost; ++ptr; while( HB_ISDIGIT( * ptr ) ) iPort = iPort * 10 + ( * ptr++ - '0' ); if( * ptr == ':' ) { ++ptr; while( HB_ISDIGIT( * ptr ) ) timeout = HB_MAX( timeout, 0 ) * 10 + ( * ptr++ - '0' ); } if( * ptr != 0 && * ptr != ':' ) iPort = 0; } if( iPort > 0 ) { char * pszAddr, * pszIpAddr; hb_socketAutoInit(); pszAddr = hb_strndup( pszHost, nLen ); pszIpAddr = hb_socketResolveAddr( pszAddr, HB_SOCKET_AF_INET ); hb_xfree( pszAddr ); if( pszIpAddr ) { HB_SOCKET sd = hb_socketOpen( HB_SOCKET_PF_INET, HB_SOCKET_PT_STREAM, 0 ); if( sd != HB_NO_SOCKET ) { void * pSockAddr; unsigned uiLen; if( hb_socketInetAddr( &pSockAddr, &uiLen, pszIpAddr, iPort ) ) { hb_socketSetKeepAlive( sd, HB_TRUE ); if( hb_socketConnect( sd, pSockAddr, uiLen, timeout ) == 0 ) { PHB_SOCKEX sock; switch( nExFlags & ( FO_READ | FO_WRITE | FO_READWRITE ) ) { case FO_READ: hb_socketShutdown( sd, HB_SOCKET_SHUT_WR ); break; case FO_WRITE: hb_socketShutdown( sd, HB_SOCKET_SHUT_RD ); break; } sock = hb_sockexNew( sd, NULL, NULL ); if( sock ) { hb_sockexSetShutDown( sock, HB_TRUE ); hb_sockexSetAutoFlush( sock, HB_TRUE ); pFile = s_fileNew( sock, timeout ); sd = HB_NO_SOCKET; } } hb_xfree( pSockAddr ); } if( sd != HB_NO_SOCKET ) { errcode = hb_socketGetError(); hb_socketClose( sd ); } } hb_xfree( pszIpAddr ); } if( errcode == 0 && pFile == NULL ) errcode = hb_socketGetError(); } else errcode = HB_SOCKET_ERR_WRONGADDR; hb_fsSetError( errcode ); if( pError ) { hb_errPutFileName( pError, pszName ); if( pFile == NULL ) { hb_errPutOsCode( pError, errcode ); hb_errPutGenCode( pError, ( HB_ERRCODE ) EG_OPEN ); } } return pFile; }