diff --git a/upnp/inc/UpnpInet.h b/upnp/inc/UpnpInet.h index 24c6cec..1d3b2ec 100644 --- a/upnp/inc/UpnpInet.h +++ b/upnp/inc/UpnpInet.h @@ -27,6 +27,7 @@ #endif #include + #include /* for close(). Do not include in WIN32. */ #define SOCKET int #define INVALID_SOCKET ((SOCKET)(-1)) #define UpnpCloseSocket close diff --git a/upnp/src/genlib/net/sock.c b/upnp/src/genlib/net/sock.c index 90bd514..6bc376f 100644 --- a/upnp/src/genlib/net/sock.c +++ b/upnp/src/genlib/net/sock.c @@ -122,37 +122,19 @@ sock_init_with_ip( OUT SOCKINFO * info, return UPNP_E_SUCCESS; } -/************************************************************************ -* Function : sock_destroy -* -* Parameters : -* INOUT SOCKINFO* info ; Socket Information Object -* int ShutdownMethod ; How to shutdown the socket. Used by -* sockets's shutdown() -* -* Description : Shutsdown the socket using the ShutdownMethod to -* indicate whether sends and receives on the socket will be -* dis-allowed. After shutting down the socket, closesocket is called -* to release system resources used by the socket calls. -* -* Return : int; -* UPNP_E_SOCKET_ERROR on failure -* UPNP_E_SUCCESS on success -* -* Note : -************************************************************************/ -int -sock_destroy( INOUT SOCKINFO * info, - int ShutdownMethod ) +int sock_destroy(INOUT SOCKINFO *info, int ShutdownMethod) { - if( info->socket != INVALID_SOCKET ) { - shutdown( info->socket, ShutdownMethod ); - if( UpnpCloseSocket( info->socket ) == -1 ) { - return UPNP_E_SOCKET_ERROR; - } - } + int ret = UPNP_E_SUCCESS; - return UPNP_E_SUCCESS; + if (info->socket != -1) { + shutdown(info->socket, ShutdownMethod); + if(sock_close(info->socket) == -1) { + ret = UPNP_E_SOCKET_ERROR; + } + info->socket = -1; + } + + return ret; } /************************************************************************ diff --git a/upnp/src/inc/sock.h b/upnp/src/inc/sock.h index 2a71022..5719bb1 100644 --- a/upnp/src/inc/sock.h +++ b/upnp/src/inc/sock.h @@ -152,27 +152,39 @@ int sock_write( IN SOCKINFO *info, IN char* buffer, IN size_t bufsize, INOUT int *timeoutSecs ); /************************************************************************ -* Function : sock_destroy -* -* Parameters : -* INOUT SOCKINFO* info ; Socket Information Object -* int ShutdownMethod ; How to shutdown the socket. Used by -* sockets's shutdown() -* -* Description : Shutsdown the socket using the ShutdownMethod to -* indicate whether sends and receives on the socket will be -* dis-allowed. After shutting down the socket, closesocket is called -* to release system resources used by the socket calls. -* -* Return : int; -* UPNP_E_SOCKET_ERROR on failure -* UPNP_E_SUCCESS on success -* -* Note : -************************************************************************/ + * Function: sock_destroy + * + * Parameters: + * INOUT SOCKINFO* info ; Socket Information Object + * int ShutdownMethod ; How to shutdown the socket. Used by + * sockets's shutdown() + * + * Description: Shutsdown the socket using the ShutdownMethod to + * indicate whether sends and receives on the socket will be + * dis-allowed. After shutting down the socket, closesocket is called + * to release system resources used by the socket calls. + * + * Return: int; + * UPNP_E_SOCKET_ERROR on failure + * UPNP_E_SUCCESS on success + * + * Note: + ************************************************************************/ int sock_destroy(INOUT SOCKINFO* info, int); +static inline int sock_close(int sock) +{ + int ret = -1; + + if (sock != -1) { + ret = UpnpCloseSocket(sock); + } + + return ret; +} + + #ifdef __cplusplus } /* #extern "C" */ #endif