summaryrefslogtreecommitdiffstats
path: root/src/network/socket/qnativesocketengine_win.cpp
diff options
context:
space:
mode:
authorAlex Trotsenko <alex1973tr@gmail.com>2017-06-15 20:16:21 +0300
committerSimon Hausmann <simon.hausmann@qt.io>2017-07-30 13:02:30 +0000
commit6adff20fe6afe8d17db2d8183506abd2792789bd (patch)
treefd9516f305cbbbfc4155896bfb55cb6d0cb31a8c /src/network/socket/qnativesocketengine_win.cpp
parent7c2850cd8f1029b74d960fad5754320b61176f46 (diff)
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 <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/network/socket/qnativesocketengine_win.cpp')
-rw-r--r--src/network/socket/qnativesocketengine_win.cpp5
1 files changed, 4 insertions, 1 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;