summaryrefslogtreecommitdiffstats
path: root/src/network/socket/qnativesocketengine_win.cpp
diff options
context:
space:
mode:
authorMarkus Goetz <Markus.Goetz@nokia.com>2009-11-18 14:54:48 (GMT)
committerMarkus Goetz <Markus.Goetz@nokia.com>2009-11-19 10:11:49 (GMT)
commite4392c36352c0d78bd374b616527482f50e6ed72 (patch)
treea531fbc2c1429b128331d13076ba602fe8faed88 /src/network/socket/qnativesocketengine_win.cpp
parentae68511de0cfa23486c4871cc45e39c05f331046 (diff)
downloadQt-e4392c36352c0d78bd374b616527482f50e6ed72.zip
Qt-e4392c36352c0d78bd374b616527482f50e6ed72.tar.gz
Qt-e4392c36352c0d78bd374b616527482f50e6ed72.tar.bz2
QTcpSocket: Fix waitForConnected on Windows
The select() system call was used in the wrong way. We need to select for exceptions too. Task-number: QTBUG-5799 Reviewed-by: Aleksandar Sasha Babic <aleksandar.babic@nokia.com> Reviewed-by: Peter Hartmann
Diffstat (limited to 'src/network/socket/qnativesocketengine_win.cpp')
-rw-r--r--src/network/socket/qnativesocketengine_win.cpp34
1 files changed, 28 insertions, 6 deletions
diff --git a/src/network/socket/qnativesocketengine_win.cpp b/src/network/socket/qnativesocketengine_win.cpp
index 63fe78e..91f930a 100644
--- a/src/network/socket/qnativesocketengine_win.cpp
+++ b/src/network/socket/qnativesocketengine_win.cpp
@@ -1107,10 +1107,22 @@ int QNativeSocketEnginePrivate::nativeSelect(int timeout, bool selectForRead) co
tv.tv_sec = timeout / 1000;
tv.tv_usec = (timeout % 1000) * 1000;
- if (selectForRead)
+ if (selectForRead) {
ret = select(0, &fds, 0, 0, timeout < 0 ? 0 : &tv);
- else
- ret = select(0, 0, &fds, 0, timeout < 0 ? 0 : &tv);
+ } else {
+ // select for write
+
+ // Windows needs this to report errors when connecting a socket ...
+ fd_set fdexception;
+ FD_ZERO(&fdexception);
+ FD_SET(socketDescriptor, &fdexception);
+
+ ret = select(0, 0, &fds, &fdexception, timeout < 0 ? 0 : &tv);
+
+ // ... but if it is actually set, pretend it did not happen
+ if (ret > 0 && FD_ISSET(socketDescriptor, &fdexception))
+ ret--;
+ }
if (readEnabled)
readNotifier->setEnabled(true);
@@ -1125,9 +1137,10 @@ int QNativeSocketEnginePrivate::nativeSelect(int timeout,
bool readEnabled = checkRead && readNotifier && readNotifier->isEnabled();
if (readEnabled)
readNotifier->setEnabled(false);
-
+
fd_set fdread;
fd_set fdwrite;
+ fd_set fdexception;
int ret = 0;
@@ -1137,9 +1150,13 @@ int QNativeSocketEnginePrivate::nativeSelect(int timeout,
fdread.fd_array[0] = socketDescriptor;
}
memset(&fdwrite, 0, sizeof(fd_set));
+ FD_ZERO(&fdexception);
if (checkWrite) {
fdwrite.fd_count = 1;
fdwrite.fd_array[0] = socketDescriptor;
+
+ // Windows needs this to report errors when connecting a socket
+ FD_SET(socketDescriptor, &fdexception);
}
struct timeval tv;
@@ -1147,10 +1164,15 @@ int QNativeSocketEnginePrivate::nativeSelect(int timeout,
tv.tv_usec = (timeout % 1000) * 1000;
#if !defined(Q_OS_WINCE)
- ret = select(socketDescriptor + 1, &fdread, &fdwrite, 0, timeout < 0 ? 0 : &tv);
+ ret = select(socketDescriptor + 1, &fdread, &fdwrite, &fdexception, timeout < 0 ? 0 : &tv);
#else
- ret = select(1, &fdread, &fdwrite, 0, timeout < 0 ? 0 : &tv);
+ ret = select(1, &fdread, &fdwrite, &fdexception, timeout < 0 ? 0 : &tv);
#endif
+
+ //... but if it is actually set, pretend it did not happen
+ if (ret > 0 && FD_ISSET(socketDescriptor, &fdexception))
+ ret--;
+
if (readEnabled)
readNotifier->setEnabled(true);