X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c9bccf239c1506c7eea0bddea44d9e4b76ad1d93..74b1f0b45e0f0bc7e25c5f32bb495e3e4bcd3392:/src/msw/sockmsw.cpp?ds=sidebyside diff --git a/src/msw/sockmsw.cpp b/src/msw/sockmsw.cpp index 33ce4ab540..1561c69f8f 100644 --- a/src/msw/sockmsw.cpp +++ b/src/msw/sockmsw.cpp @@ -33,6 +33,7 @@ #include "wx/apptrait.h" #include "wx/thread.h" #include "wx/dynlib.h" +#include "wx/link.h" #ifdef __WXWINCE__ /* @@ -179,8 +180,10 @@ public: { return new wxSocketImplMSW(wxsocket); } - virtual void Install_Callback(wxSocketImpl *socket, wxSocketNotify event); - virtual void Uninstall_Callback(wxSocketImpl *socket, wxSocketNotify event); + virtual void Install_Callback(wxSocketImpl *socket, + wxSocketNotify event = wxSOCKET_LOST); + virtual void Uninstall_Callback(wxSocketImpl *socket, + wxSocketNotify event = wxSOCKET_LOST); private: static wxDynamicLibrary gs_wsock32dll; @@ -209,9 +212,9 @@ bool wxSocketMSWManager::OnInit() // dependencies on it for all the application using wx even if they don't use // sockets #ifdef __WXWINCE__ - #define WINSOCK_DLL_NAME _T("ws2.dll") + #define WINSOCK_DLL_NAME wxT("ws2.dll") #else - #define WINSOCK_DLL_NAME _T("wsock32.dll") + #define WINSOCK_DLL_NAME wxT("wsock32.dll") #endif gs_wsock32dll.Load(WINSOCK_DLL_NAME, wxDL_VERBATIM | wxDL_QUIET); @@ -325,6 +328,11 @@ LRESULT CALLBACK wxSocket_Internal_WinProc(HWND hWnd, if ( !socket ) return 0; + // the socket may be already closed but we could still receive + // notifications for it sent (asynchronously) before it got closed + if ( socket->m_fd == INVALID_SOCKET ) + return 0; + wxASSERT_MSG( socket->m_fd == (SOCKET)wParam, "mismatch between message and socket?" ); @@ -402,7 +410,7 @@ void wxSocketMSWManager::Install_Callback(wxSocketImpl *socket_, * Disable event notifications (used when shutting down the socket) */ void wxSocketMSWManager::Uninstall_Callback(wxSocketImpl *socket_, - wxSocketNotify WXUNUSED(event)) + wxSocketNotify WXUNUSED(event)) { wxSocketImplMSW * const socket = static_cast(socket_); @@ -430,20 +438,16 @@ static struct ManagerSetter } } gs_managerSetter; +// see the relative linker macro in socket.cpp +wxFORCE_LINK_THIS_MODULE( mswsocket ); + // ============================================================================ // wxSocketImpl implementation // ============================================================================ -/* static */ -wxSocketImpl *wxSocketImpl::Create(wxSocketBase& wxsocket) -{ - return new wxSocketImplMSW(wxsocket); -} - void wxSocketImplMSW::DoClose() { - wxSocketManager::Get()-> - Uninstall_Callback(this, wxSOCKET_MAX_EVENT /* unused anyhow */); + wxSocketManager::Get()->Uninstall_Callback(this); closesocket(m_fd); }