From 6adff20fe6afe8d17db2d8183506abd2792789bd Mon Sep 17 00:00:00 2001 From: Alex Trotsenko Date: Thu, 15 Jun 2017 20:16:21 +0300 Subject: [PATCH] Fix bytesAvailable() on UDP under Windows When ::WSAIoctl() reports 1 byte available for reading, we are trying to peek an incoming datagram to ensure that the data is actually delivered. But, according to MSDN docs, we are not allowed to pass NULL as 'lpNumberOfBytesRecvd' parameter to ::WSARecvFrom() call, if 'lpOverlapped' parameter is also NULL. The case with an empty datagram is fixed accordingly. Change-Id: Id13038245332d3fb4bc18038d44a7cfd7ce04775 Reviewed-by: Edward Welbourne Reviewed-by: Thiago Macieira --- src/network/socket/qnativesocketengine_win.cpp | 5 ++++- tests/auto/network/socket/qudpsocket/BLACKLIST | 1 - 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/network/socket/qnativesocketengine_win.cpp b/src/network/socket/qnativesocketengine_win.cpp index a09d611e89..eb633eb1d2 100644 --- a/src/network/socket/qnativesocketengine_win.cpp +++ b/src/network/socket/qnativesocketengine_win.cpp @@ -1090,11 +1090,14 @@ qint64 QNativeSocketEnginePrivate::nativeBytesAvailable() const WSABUF buf; buf.buf = &c; buf.len = sizeof(c); + DWORD bytesReceived; DWORD flags = MSG_PEEK; - if (::WSARecvFrom(socketDescriptor, &buf, 1, 0, &flags, 0,0,0,0) == SOCKET_ERROR) { + if (::WSARecvFrom(socketDescriptor, &buf, 1, &bytesReceived, &flags, 0,0,0,0) == SOCKET_ERROR) { int err = WSAGetLastError(); if (err != WSAECONNRESET && err != WSAENETRESET) return 0; + } else { + return bytesReceived; } } return nbytes; diff --git a/tests/auto/network/socket/qudpsocket/BLACKLIST b/tests/auto/network/socket/qudpsocket/BLACKLIST index cf25c96fd8..5adb05d3f2 100644 --- a/tests/auto/network/socket/qudpsocket/BLACKLIST +++ b/tests/auto/network/socket/qudpsocket/BLACKLIST @@ -6,7 +6,6 @@ osx windows osx [asyncReadDatagram] -windows osx [multicastLeaveAfterClose] osx