From 12cc077e68bd83587bd00e957d54ed5682a808b7 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 12 Jun 2010 11:28:15 +0000 Subject: [PATCH] Avoid sending spurious socket read notifications in wxMSW. If a read notification is generated for a socket, it should be possible to read something from it without blocking but this doesn't seem to be always the case under MSW for some reason. And this results in all sorts of problems in wxSocket and wxIPC code, so check for this at wxSocketImpl level and not send the notification at all if there is no data to read. See #11528. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64565 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/sockmsw.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/msw/sockmsw.cpp b/src/msw/sockmsw.cpp index 1561c69f8f..998bc1118e 100644 --- a/src/msw/sockmsw.cpp +++ b/src/msw/sockmsw.cpp @@ -30,6 +30,7 @@ #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" @@ -336,9 +337,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 }; + + 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; -- 2.47.2