src/network/socket/qnativesocketengine_win.cpp
changeset 18 2f34d5167611
parent 3 41300fa6a67c
child 37 758a864f9613
--- a/src/network/socket/qnativesocketengine_win.cpp	Tue Feb 02 00:43:10 2010 +0200
+++ b/src/network/socket/qnativesocketengine_win.cpp	Fri Apr 16 15:50:13 2010 +0300
@@ -1,6 +1,6 @@
 /****************************************************************************
 **
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
 **
@@ -994,9 +994,9 @@
 {
     Q_Q(QNativeSocketEngine);
     qint64 ret = 0;
-    // don't send more than 49152 per call to WSASendTo to avoid getting a WSAENOBUFS
+    qint64 bytesToSend = len;
+
     for (;;) {
-        qint64 bytesToSend = qMin<qint64>(49152, len - ret);
         WSABUF buf;
         buf.buf = (char*)data + ret;
         buf.len = bytesToSend;
@@ -1007,15 +1007,21 @@
 
         ret += qint64(bytesWritten);
 
+        int err;
         if (socketRet != SOCKET_ERROR) {
             if (ret == len)
                 break;
             else
                 continue;
-        } else if (WSAGetLastError() == WSAEWOULDBLOCK) {
+        } else if ((err = WSAGetLastError()) == WSAEWOULDBLOCK) {
             break;
+        } else if (err == WSAENOBUFS) {
+            // this function used to not send more than 49152 per call to WSASendTo
+            // to avoid getting a WSAENOBUFS. However this is a performance regression
+            // and we think it only appears with old windows versions. We now handle the
+            // WSAENOBUFS and hope it never appears anyway.
+            // just go on, the next loop run we will try a smaller number
         } else {
-            int err = WSAGetLastError();
             WS_ERROR_DEBUG(err);
             switch (err) {
             case WSAECONNRESET:
@@ -1029,6 +1035,9 @@
             }
             break;
         }
+
+        // for next send:
+        bytesToSend = qMin<qint64>(49152, len - ret);
     }
 
 #if defined (QNATIVESOCKETENGINE_DEBUG)
@@ -1059,7 +1068,7 @@
             break;
         case WSAEBADF:
         case WSAEINVAL:
-            setError(QAbstractSocket::NetworkError, ReadErrorString);
+            //error string is now set in read(), not here in nativeRead()
             break;
         case WSAECONNRESET:
         case WSAECONNABORTED:
@@ -1190,8 +1199,10 @@
 #if defined (QTCPSOCKETENGINE_DEBUG)
     qDebug("QNativeSocketEnginePrivate::nativeClose()");
 #endif
-    linger l = {1, 0};
-    ::setsockopt(socketDescriptor, SOL_SOCKET, SO_DONTLINGER, (char*)&l, sizeof(l));
+    // We were doing a setsockopt here before with SO_DONTLINGER. (However with kind of wrong
+    // usage of parameters, it wants a BOOL but we used a struct and pretended it to be bool).
+    // We don't think setting this option should be done here, if a user wants it she/he can
+     // do it manually with socketDescriptor()/setSocketDescriptor();
     ::closesocket(socketDescriptor);
 }