X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2804f77d88eb478f85a281b19d87e38cd96e0d0c..ff55f8377ba8965bee36d1221501a3868da952e9:/src/msw/gsockmsw.cpp diff --git a/src/msw/gsockmsw.cpp b/src/msw/gsockmsw.cpp index a1ada1918b..3ca8b48349 100644 --- a/src/msw/gsockmsw.cpp +++ b/src/msw/gsockmsw.cpp @@ -38,6 +38,9 @@ #include "wx/gsocket.h" #include "wx/apptrait.h" +#include "wx/link.h" + +wxFORCE_LINK_THIS_MODULE(gsockmsw) extern "C" WXDLLIMPEXP_BASE HINSTANCE wxGetInstance(); #define INSTANCE wxGetInstance() @@ -310,8 +313,21 @@ void GSocketMSWManager::Destroy_Socket(GSocket *socket) { /* Remove the socket from the list */ EnterCriticalSection(&critical); - if ( socket->IsOk() ) - socketList[(socket->m_msgnumber - WM_USER)] = NULL; + + const int msgnum = socket->m_msgnumber; + if ( msgnum ) + { + // we need to remove any pending messages for this socket to avoid having + // them sent to a new socket which could reuse the same message number as + // soon as we destroy this one + MSG msg; + while ( ::PeekMessage(&msg, hWin, msgnum, msgnum, PM_REMOVE) ) + ; + + socketList[msgnum - WM_USER] = NULL; + } + //else: the socket has never been created successfully + LeaveCriticalSection(&critical); } @@ -351,7 +367,7 @@ LRESULT CALLBACK _GSocket_Internal_WinProc(HWND hWnd, * destroyed) and for safety, check that the m_fd field * is what we expect it to be. */ - if ((socket != NULL) && (socket->m_fd == wParam)) + if ((socket != NULL) && ((WPARAM)socket->m_fd == wParam)) { switch WSAGETSELECTEVENT(lParam) { @@ -458,6 +474,6 @@ static struct ManagerSetter static GSocketMSWManager s_manager; wxAppTraits::SetDefaultSocketManager(&s_manager); } -} gsm_managerSetter; +} gs_managerSetter; #endif // wxUSE_SOCKETS