X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cd604d60721d274775f20bb280cd068b746e6c73..6151e1445bdca0dfca660e3851aa3705bfd543de:/src/msw/gsocket.c diff --git a/src/msw/gsocket.c b/src/msw/gsocket.c index 26388159d7..963bde9b9f 100644 --- a/src/msw/gsocket.c +++ b/src/msw/gsocket.c @@ -26,7 +26,6 @@ # pragma warning(disable:4100) #endif /* _MSC_VER */ - #ifndef __GSOCKET_STANDALONE__ # include "wx/defs.h" # include "wx/setup.h" @@ -50,7 +49,6 @@ # define _GSocket_Disable_Events(socket) #endif /* wxUSE_GUI */ - #include #include #include @@ -103,6 +101,13 @@ GSocket *GSocket_new(void) return socket; } +void GSocket_close(GSocket *socket) +{ + _GSocket_Disable_Events(socket); + closesocket(socket->m_fd); + socket->m_fd = INVALID_SOCKET; +} + void GSocket_destroy(GSocket *socket) { assert(socket != NULL); @@ -139,8 +144,7 @@ void GSocket_Shutdown(GSocket *socket) if (socket->m_fd != INVALID_SOCKET) { shutdown(socket->m_fd, 2); - closesocket(socket->m_fd); - socket->m_fd = INVALID_SOCKET; + GSocket_close(socket); } /* Disable GUI callbacks */ @@ -148,7 +152,6 @@ void GSocket_Shutdown(GSocket *socket) socket->m_cbacks[evt] = NULL; socket->m_detected = GSOCK_LOST_FLAG; - _GSocket_Disable_Events(socket); } /* Address handling */ @@ -325,8 +328,7 @@ GSocketError GSocket_SetServer(GSocket *sck) (SOCKLEN_T *)&sck->m_local->m_len) != 0) || (listen(sck->m_fd, 5) != 0)) { - closesocket(sck->m_fd); - sck->m_fd = INVALID_SOCKET; + GSocket_close(sck); sck->m_error = GSOCK_IOERR; return GSOCK_IOERR; } @@ -508,8 +510,7 @@ GSocketError GSocket_Connect(GSocket *sck, GSocketStream stream) if (err != GSOCK_NOERROR) { - closesocket(sck->m_fd); - sck->m_fd = INVALID_SOCKET; + GSocket_close(sck); /* sck->m_error is set in _GSocket_Connect_Timeout */ } @@ -532,8 +533,7 @@ GSocketError GSocket_Connect(GSocket *sck, GSocketStream stream) /* If connect failed with an error other than EWOULDBLOCK, * then the call to GSocket_Connect() has failed. */ - closesocket(sck->m_fd); - sck->m_fd = INVALID_SOCKET; + GSocket_close(sck); sck->m_error = GSOCK_IOERR; return GSOCK_IOERR; } @@ -597,8 +597,7 @@ GSocketError GSocket_SetNonOriented(GSocket *sck) sck->m_local->m_addr, (SOCKLEN_T *)&sck->m_local->m_len) != 0)) { - closesocket(sck->m_fd); - sck->m_fd = INVALID_SOCKET; + GSocket_close(sck); sck->m_error = GSOCK_IOERR; return GSOCK_IOERR; } @@ -792,7 +791,7 @@ void GSocket_SetTimeout(GSocket *socket, unsigned long millis) * operations do not clear this back to GSOCK_NOERROR, so use it only * after an error. */ -GSocketError WXDLLEXPORT GSocket_GetError(GSocket *socket) +GSocketError GSocket_GetError(GSocket *socket) { assert(socket != NULL); @@ -1380,3 +1379,5 @@ GSocketError GAddress_UNIX_GetPath(GAddress *address, char *path, size_t sbuf) typedef void (*wxDummy)(); #endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */ + +// vi:sts=4:sw=4:et