Changeset 561 for trunk/src/network/socket/qnativesocketengine.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/network/socket/qnativesocketengine.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtNetwork module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 48 48 49 49 \reentrant 50 \ingroup io50 \ingroup network 51 51 \inmodule QtNetwork 52 52 … … 195 195 switch (errorString) { 196 196 case NonBlockingInitFailedErrorString: 197 socketErrorString = Q Latin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Unable to initialize non-blocking socket"));197 socketErrorString = QNativeSocketEngine::tr("Unable to initialize non-blocking socket"); 198 198 break; 199 199 case BroadcastingInitFailedErrorString: 200 socketErrorString = Q Latin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Unable to initialize broadcast socket"));200 socketErrorString = QNativeSocketEngine::tr("Unable to initialize broadcast socket"); 201 201 break; 202 202 case NoIpV6ErrorString: 203 socketErrorString = Q Latin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Attempt to use IPv6 socket on a platform with no IPv6 support"));203 socketErrorString = QNativeSocketEngine::tr("Attempt to use IPv6 socket on a platform with no IPv6 support"); 204 204 break; 205 205 case RemoteHostClosedErrorString: 206 socketErrorString = Q Latin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "The remote host closed the connection"));206 socketErrorString = QNativeSocketEngine::tr("The remote host closed the connection"); 207 207 break; 208 208 case TimeOutErrorString: 209 socketErrorString = Q Latin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Network operation timed out"));209 socketErrorString = QNativeSocketEngine::tr("Network operation timed out"); 210 210 break; 211 211 case ResourceErrorString: 212 socketErrorString = Q Latin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Out of resources"));212 socketErrorString = QNativeSocketEngine::tr("Out of resources"); 213 213 break; 214 214 case OperationUnsupportedErrorString: 215 socketErrorString = Q Latin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Unsupported socket operation"));215 socketErrorString = QNativeSocketEngine::tr("Unsupported socket operation"); 216 216 break; 217 217 case ProtocolUnsupportedErrorString: 218 socketErrorString = Q Latin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Protocol type not supported"));218 socketErrorString = QNativeSocketEngine::tr("Protocol type not supported"); 219 219 break; 220 220 case InvalidSocketErrorString: 221 socketErrorString = Q Latin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Invalid socket descriptor"));221 socketErrorString = QNativeSocketEngine::tr("Invalid socket descriptor"); 222 222 break; 223 223 case HostUnreachableErrorString: 224 socketErrorString = Q Latin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Host unreachable"));224 socketErrorString = QNativeSocketEngine::tr("Host unreachable"); 225 225 break; 226 226 case NetworkUnreachableErrorString: 227 socketErrorString = Q Latin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Network unreachable"));227 socketErrorString = QNativeSocketEngine::tr("Network unreachable"); 228 228 break; 229 229 case AccessErrorString: 230 socketErrorString = Q Latin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Permission denied"));230 socketErrorString = QNativeSocketEngine::tr("Permission denied"); 231 231 break; 232 232 case ConnectionTimeOutErrorString: 233 socketErrorString = Q Latin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Connection timed out"));233 socketErrorString = QNativeSocketEngine::tr("Connection timed out"); 234 234 break; 235 235 case ConnectionRefusedErrorString: 236 socketErrorString = Q Latin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Connection refused"));236 socketErrorString = QNativeSocketEngine::tr("Connection refused"); 237 237 break; 238 238 case AddressInuseErrorString: 239 socketErrorString = Q Latin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "The bound address is already in use"));239 socketErrorString = QNativeSocketEngine::tr("The bound address is already in use"); 240 240 break; 241 241 case AddressNotAvailableErrorString: 242 socketErrorString = Q Latin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "The address is not available"));242 socketErrorString = QNativeSocketEngine::tr("The address is not available"); 243 243 break; 244 244 case AddressProtectedErrorString: 245 socketErrorString = Q Latin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "The address is protected"));245 socketErrorString = QNativeSocketEngine::tr("The address is protected"); 246 246 break; 247 247 case DatagramTooLargeErrorString: 248 socketErrorString = Q Latin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Datagram was too large to send"));248 socketErrorString = QNativeSocketEngine::tr("Datagram was too large to send"); 249 249 break; 250 250 case SendDatagramErrorString: 251 socketErrorString = Q Latin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Unable to send a message"));251 socketErrorString = QNativeSocketEngine::tr("Unable to send a message"); 252 252 break; 253 253 case ReceiveDatagramErrorString: 254 socketErrorString = Q Latin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Unable to receive a message"));254 socketErrorString = QNativeSocketEngine::tr("Unable to receive a message"); 255 255 break; 256 256 case WriteErrorString: 257 socketErrorString = Q Latin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Unable to write"));257 socketErrorString = QNativeSocketEngine::tr("Unable to write"); 258 258 break; 259 259 case ReadErrorString: 260 socketErrorString = Q Latin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Network error"));260 socketErrorString = QNativeSocketEngine::tr("Network error"); 261 261 break; 262 262 case PortInuseErrorString: 263 socketErrorString = Q Latin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Another socket is already listening on the same port"));263 socketErrorString = QNativeSocketEngine::tr("Another socket is already listening on the same port"); 264 264 break; 265 265 case NotSocketErrorString: 266 socketErrorString = Q Latin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Operation on non-socket"));266 socketErrorString = QNativeSocketEngine::tr("Operation on non-socket"); 267 267 break; 268 268 case InvalidProxyTypeString: 269 socketErrorString = Q Latin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "The proxy type is invalid for this operation"));269 socketErrorString = QNativeSocketEngine::tr("The proxy type is invalid for this operation"); 270 270 break; 271 271 case UnknownSocketErrorString: 272 socketErrorString = Q Latin1String(QT_TRANSLATE_NOOP("QNativeSocketEngine", "Unknown error"));272 socketErrorString = QNativeSocketEngine::tr("Unknown error"); 273 273 break; 274 274 } … … 382 382 } 383 383 384 384 385 // Make sure we receive out-of-band data 386 // On Symbian OS this works only with native IP stack, not with WinSock 385 387 if (socketType == QAbstractSocket::TcpSocket 386 388 && !setOption(ReceiveOutOfBandData, 1)) { … … 388 390 } 389 391 390 // Set the send and receive buffer sizes to a magic size, found 391 // most optimal for our platforms. 392 setReceiveBufferSize(49152); 393 setSendBufferSize(49152); 392 // Before Qt 4.6, we always set the send and receive buffer size to 49152 as 393 // this was found to be an optimal value. However, modern OS 394 // all have some kind of auto tuning for this and we therefore don't set 395 // this explictly anymore. 396 // If it introduces any performance regressions for Qt 4.6.x (x > 0) then 397 // it will be put back in. 398 // 399 // You can use tests/manual/qhttpnetworkconnection to test HTTP download speed 400 // with this. 401 // 402 // pre-4.6: 403 // setReceiveBufferSize(49152); 404 // setSendBufferSize(49152); 394 405 395 406 d->socketType = socketType; … … 744 755 } 745 756 757 758 qint64 QNativeSocketEngine::bytesToWrite() const 759 { 760 return 0; 761 } 762 746 763 /*! 747 764 Reads up to \a maxSize bytes into \a data from the socket. … … 860 877 bool QNativeSocketEngine::waitForWrite(int msecs, bool *timedOut) 861 878 { 862 Q_D( constQNativeSocketEngine);879 Q_D(QNativeSocketEngine); 863 880 Q_CHECK_VALID_SOCKETLAYER(QNativeSocketEngine::waitForWrite(), false); 864 881 Q_CHECK_NOT_STATE(QNativeSocketEngine::waitForWrite(), … … 877 894 d_func()->fetchConnectionParameters(); 878 895 return true; 896 } else { 897 int value = 0; 898 int valueSize = sizeof(value); 899 if (::getsockopt(d->socketDescriptor, SOL_SOCKET, SO_ERROR, (char *) &value, &valueSize) == 0) { 900 if (value == WSAECONNREFUSED) { 901 d->setError(QAbstractSocket::ConnectionRefusedError, QNativeSocketEnginePrivate::ConnectionRefusedErrorString); 902 d->socketState = QAbstractSocket::UnconnectedState; 903 return false; 904 } else if (value == WSAETIMEDOUT) { 905 d->setError(QAbstractSocket::NetworkError, QNativeSocketEnginePrivate::ConnectionTimeOutErrorString); 906 d->socketState = QAbstractSocket::UnconnectedState; 907 return false; 908 } else if (value == WSAEHOSTUNREACH) { 909 d->setError(QAbstractSocket::NetworkError, QNativeSocketEnginePrivate::HostUnreachableErrorString); 910 d->socketState = QAbstractSocket::UnconnectedState; 911 return false; 912 } 913 } 879 914 } 880 915 #endif … … 897 932 int msecs, bool *timedOut) 898 933 { 899 Q_D( constQNativeSocketEngine);934 Q_D(QNativeSocketEngine); 900 935 Q_CHECK_VALID_SOCKETLAYER(QNativeSocketEngine::waitForWrite(), false); 901 936 Q_CHECK_NOT_STATE(QNativeSocketEngine::waitForReadOrWrite(), … … 911 946 d_func()->fetchConnectionParameters(); 912 947 return true; 913 } 914 #endif 948 } else { 949 int value = 0; 950 int valueSize = sizeof(value); 951 if (::getsockopt(d->socketDescriptor, SOL_SOCKET, SO_ERROR, (char *) &value, &valueSize) == 0) { 952 if (value == WSAECONNREFUSED) { 953 d->setError(QAbstractSocket::ConnectionRefusedError, QNativeSocketEnginePrivate::ConnectionRefusedErrorString); 954 d->socketState = QAbstractSocket::UnconnectedState; 955 return false; 956 } else if (value == WSAETIMEDOUT) { 957 d->setError(QAbstractSocket::NetworkError, QNativeSocketEnginePrivate::ConnectionTimeOutErrorString); 958 d->socketState = QAbstractSocket::UnconnectedState; 959 return false; 960 } else if (value == WSAEHOSTUNREACH) { 961 d->setError(QAbstractSocket::NetworkError, QNativeSocketEnginePrivate::HostUnreachableErrorString); 962 d->socketState = QAbstractSocket::UnconnectedState; 963 return false; 964 } 965 } 966 } 967 #endif 915 968 if (ret == 0) { 916 969 if (timedOut) … … 1087 1140 { 1088 1141 if (e->type() == QEvent::SockAct) { 1089 engine->exceptionNotification(); 1142 if (engine->state() == QAbstractSocket::ConnectingState) 1143 engine->connectionNotification(); 1144 else 1145 engine->exceptionNotification(); 1090 1146 return true; 1091 1147 }
Note:
See TracChangeset
for help on using the changeset viewer.