X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/786900097722e323c847db2d9e2d9b85fe3373ab..9ed99f82da680a40becbb4e72d03a30d4acb335e:/src/msw/sockmsw.cpp diff --git a/src/msw/sockmsw.cpp b/src/msw/sockmsw.cpp index bfac07191c..7bad1d450b 100644 --- a/src/msw/sockmsw.cpp +++ b/src/msw/sockmsw.cpp @@ -6,8 +6,7 @@ // Copyright: (C) 1999-1997, Guilhem Lavaux // (C) 1999-2000, Guillermo Rodriguez Garcia // (C) 2008 Vadim Zeitlin -// RCS_ID: $Id$ -// License: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -30,9 +29,11 @@ #include "wx/private/socket.h" #include "wx/msw/private.h" // for wxGetInstance() +#include "wx/private/fd.h" #include "wx/apptrait.h" #include "wx/thread.h" #include "wx/dynlib.h" +#include "wx/link.h" #ifdef __WXWINCE__ /* @@ -57,11 +58,9 @@ WX_DECLARE_HASH_MAP(int,bool,wxIntegerHash,wxIntegerEqual,SocketHash); # pragma warning(default:4115) /* named type definition in parentheses */ #endif -#define CLASSNAME TEXT("_wxSocket_Internal_Window_Class") +#include "wx/msw/private/hiddenwin.h" -/* implemented in utils.cpp */ -extern "C" WXDLLIMPEXP_BASE HWND -wxCreateHiddenWindow(LPCTSTR *pclassname, LPCTSTR classname, WNDPROC wndproc); +#define CLASSNAME TEXT("_wxSocket_Internal_Window_Class") /* Maximum number of different wxSocket objects at a given time. * This value can be modified at will, but it CANNOT be greater @@ -120,7 +119,7 @@ typedef struct thread_data{ #ifdef __WXWINCE__ /* This thread handles socket events on WinCE using WSAEventSelect() as * WSAAsyncSelect is not supported. When an event occurs for the socket, it is - * checked what kind of event happend and the correct message gets posted so + * checked what kind of event happened and the correct message gets posted so * that the hidden window can handle it as it would in other MSW builds. */ DWORD WINAPI SocketThread(LPVOID data) @@ -211,9 +210,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); @@ -335,9 +334,25 @@ LRESULT CALLBACK wxSocket_Internal_WinProc(HWND hWnd, wxASSERT_MSG( socket->m_fd == (SOCKET)wParam, "mismatch between message and socket?" ); - switch WSAGETSELECTEVENT(lParam) + switch ( WSAGETSELECTEVENT(lParam) ) { case FD_READ: + // We may get a FD_READ notification even when there is no data + // to read on the socket, in particular this happens on socket + // creation when we seem to always get FD_CONNECT, FD_WRITE and + // FD_READ notifications all at once (but it doesn't happen + // only then). Ignore such dummy notifications. + { + fd_set fds; + timeval tv = { 0, 0 }; + + wxFD_ZERO(&fds); + wxFD_SET(socket->m_fd, &fds); + + if ( select(socket->m_fd + 1, &fds, NULL, NULL, &tv) != 1 ) + return 0; + } + event = wxSOCKET_INPUT; break; @@ -437,16 +452,13 @@ 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);