X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a84ece11fffdde5d1bbd254ba58ac3cee79c2e77..2ae8a353528c12be92dbaa699f2ffc670188ab5b:/src/msw/gsocket.c diff --git a/src/msw/gsocket.c b/src/msw/gsocket.c index fc5f87c83d..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 @@ -60,12 +58,6 @@ #include -/* don't use C++ TRUE/FALSE definition which we get from wx/defs.h */ -#undef TRUE -#undef FALSE -#define TRUE 1 -#define FALSE 0 - /* if we use configure for MSW SOCKLEN_T will be already defined */ #ifndef SOCKLEN_T # define SOCKLEN_T int @@ -109,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); @@ -145,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 */ @@ -154,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 */ @@ -331,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; } @@ -514,12 +510,11 @@ 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 */ } - return err; + return (GSocketError) err; } /* If connect failed with EWOULDBLOCK and the GSocket object @@ -538,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; } @@ -603,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; } @@ -1386,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