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
This commit is contained in:
Vadim Zeitlin
2010-06-12 11:28:15 +00:00
parent bb9da4d3ca
commit 12cc077e68

View File

@@ -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;