Changeset 561 for trunk/src/network/socket
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 34 edited
- 1 copied
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/qabstractsocket.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 ** … … 49 49 50 50 \reentrant 51 \ingroup io51 \ingroup network 52 52 \inmodule QtNetwork 53 53 … … 100 100 write buffer size. You can monitor its size by listening to this 101 101 signal. 102 102 103 103 The readyRead() signal is emitted every time a new chunk of data 104 104 has arrived. bytesAvailable() then returns the number of bytes … … 161 161 is available before attempting to read it using operator>>(). 162 162 163 \sa QFtp, Q Http, QTcpServer163 \sa QFtp, QNetworkAccessManager, QTcpServer 164 164 */ 165 165 … … 200 200 201 201 QAbstractSocket::SocketError is not a registered metatype, so for queued 202 connections, you will have to register it with Q_REGISTER_METATYPE. 203 204 \sa error(), errorString() 202 connections, you will have to register it with Q_DECLARE_METATYPE() and 203 qRegisterMetaType(). 204 205 \sa error(), errorString(), {Creating Custom Qt Types} 205 206 */ 206 207 … … 212 213 213 214 QAbstractSocket::SocketState is not a registered metatype, so for queued 214 connections, you will have to register it with Q_REGISTER_METATYPE. 215 216 \sa state() 215 connections, you will have to register it with Q_REGISTER_METATYPE() and 216 qRegisterMetaType(). 217 218 \sa state(), {Creating Custom Qt Types} 217 219 */ 218 220 … … 331 333 */ 332 334 335 /*! 336 \enum QAbstractSocket::SocketOption 337 \since 4.6 338 339 This enum represents the options that can be set on a socket. 340 If desired, they can be set after having received the connected() signal from 341 the socket or after having received a new socket from a QTcpServer. 342 343 \value LowDelayOption Try to optimize the socket for low latency. For a QTcpSocket 344 this would set the TCP_NODELAY option and disable Nagle's algorithm. Set this to 1 345 to enable. 346 \value KeepAliveOption Set this to 1 to enable the SO_KEEPALIVE socket option 347 348 \sa QAbstractSocket::setSocketOption(), QAbstractSocket::socketOption() 349 */ 350 333 351 #include "qabstractsocket.h" 334 352 #include "qabstractsocket_p.h" … … 436 454 socketEngine(0), 437 455 cachedSocketDescriptor(-1), 456 #ifdef Q_OS_LINUX 457 addToBytesAvailable(0), 458 #endif 438 459 readBufferMaxSize(0), 439 460 readBuffer(QABSTRACTSOCKET_BUFFERSIZE), … … 442 463 blockingTimeout(30000), 443 464 connectTimer(0), 465 disconnectTimer(0), 444 466 connectTimeElapsed(0), 445 467 hostLookupId(-1), 468 socketType(QAbstractSocket::UnknownSocketType), 446 469 state(QAbstractSocket::UnconnectedState), 447 470 socketError(QAbstractSocket::UnknownSocketError) … … 476 499 cachedSocketDescriptor = -1; 477 500 } 478 if (connectTimer) {501 if (connectTimer) 479 502 connectTimer->stop(); 480 } 503 if (disconnectTimer) 504 disconnectTimer->stop(); 481 505 } 482 506 … … 648 672 if (socketEngine) { 649 673 #if defined (Q_OS_WIN) 650 651 674 if (!writeBuffer.isEmpty()) 675 socketEngine->setWriteNotificationEnabled(true); 652 676 #else 653 if (writeBuffer.isEmpty())654 677 if (writeBuffer.isEmpty() && socketEngine->bytesToWrite() == 0) 678 socketEngine->setWriteNotificationEnabled(false); 655 679 #endif 656 680 } … … 689 713 { 690 714 Q_Q(QAbstractSocket); 691 if (!socketEngine || !socketEngine->isValid() || writeBuffer.isEmpty()) { 715 if (!socketEngine || !socketEngine->isValid() || (writeBuffer.isEmpty() 716 && socketEngine->bytesToWrite() == 0)) { 692 717 #if defined (QABSTRACTSOCKET_DEBUG) 693 718 qDebug("QAbstractSocketPrivate::flush() nothing to do: valid ? %s, writeBuffer.isEmpty() ? %s", 694 719 socketEngine->isValid() ? "yes" : "no", writeBuffer.isEmpty() ? "yes" : "no"); 695 720 #endif 721 722 // this covers the case when the buffer was empty, but we had to wait for the socket engine to finish 723 if (state == QAbstractSocket::ClosingState) 724 q->disconnectFromHost(); 725 696 726 return false; 697 727 } … … 730 760 } 731 761 732 if (writeBuffer.isEmpty() && socketEngine && socketEngine->isWriteNotificationEnabled()) 762 if (writeBuffer.isEmpty() && socketEngine && socketEngine->isWriteNotificationEnabled() 763 && !socketEngine->bytesToWrite()) 733 764 socketEngine->setWriteNotificationEnabled(false); 734 765 if (state == QAbstractSocket::ClosingState) … … 851 882 s += addresses.at(i).toString(); 852 883 } 853 s += "}";884 s += '}'; 854 885 qDebug("QAbstractSocketPrivate::_q_startConnecting(hostInfo == %s)", s.toLatin1().constData()); 855 886 #endif … … 1052 1083 if (socketEngine) 1053 1084 socketEngine->setWriteNotificationEnabled(false); 1085 1054 1086 connectTimer->stop(); 1055 1087 … … 1062 1094 } else { 1063 1095 _q_connectToNextAddress(); 1096 } 1097 } 1098 1099 void QAbstractSocketPrivate::_q_forceDisconnect() 1100 { 1101 Q_Q(QAbstractSocket); 1102 if (socketEngine && socketEngine->isValid() && state == QAbstractSocket::ClosingState) { 1103 socketEngine->close(); 1104 q->disconnectFromHost(); 1064 1105 } 1065 1106 } … … 1128 1169 /*! \internal 1129 1170 1130 Sets up the theinternal state after the connection has succeeded.1171 Sets up the internal state after the connection has succeeded. 1131 1172 */ 1132 1173 void QAbstractSocketPrivate::fetchConnectionParameters() … … 1232 1273 \a hostName may be an IP address in string form (e.g., 1233 1274 "43.195.83.32"), or it may be a host name (e.g., 1234 " qtsoftware.com"). QAbstractSocket will do a lookup only if1275 "example.com"). QAbstractSocket will do a lookup only if 1235 1276 required. \a port is in native byte order. 1236 1277 … … 1264 1305 #endif 1265 1306 1266 if (d->state == ConnectedState || d->state == ConnectingState) { 1267 qWarning("QAbstractSocket::connectToHost() called when already connecting/connected to \"%s\"", qPrintable(hostName)); 1307 if (d->state == ConnectedState || d->state == ConnectingState 1308 || d->state == ClosingState || d->state == HostLookupState) { 1309 qWarning("QAbstractSocket::connectToHost() called when already looking up or connecting/connected to \"%s\"", qPrintable(hostName)); 1268 1310 return; 1269 1311 } … … 1547 1589 } 1548 1590 1591 /*! 1592 \since 4.6 1593 Sets the given \a option to the value described by \a value. 1594 1595 \sa socketOption() 1596 */ 1597 void QAbstractSocket::setSocketOption(QAbstractSocket::SocketOption option, const QVariant &value) 1598 { 1599 #ifndef QT_NO_OPENSSL 1600 if (QSslSocket *sslSocket = qobject_cast<QSslSocket*>(this)) { 1601 sslSocket->setSocketOption(option, value); 1602 return; 1603 } 1604 #endif 1605 1606 if (!d_func()->socketEngine) 1607 return; 1608 1609 switch (option) { 1610 case LowDelayOption: 1611 d_func()->socketEngine->setOption(QAbstractSocketEngine::LowDelayOption, value.toInt()); 1612 break; 1613 1614 case KeepAliveOption: 1615 d_func()->socketEngine->setOption(QAbstractSocketEngine::KeepAliveOption, value.toInt()); 1616 break; 1617 } 1618 } 1619 1620 /*! 1621 \since 4.6 1622 Returns the value of the \a option option. 1623 1624 \sa setSocketOption() 1625 */ 1626 QVariant QAbstractSocket::socketOption(QAbstractSocket::SocketOption option) 1627 { 1628 #ifndef QT_NO_OPENSSL 1629 if (QSslSocket *sslSocket = qobject_cast<QSslSocket*>(this)) { 1630 return sslSocket->socketOption(option); 1631 } 1632 #endif 1633 1634 if (!d_func()->socketEngine) 1635 return QVariant(); 1636 1637 int ret = -1; 1638 switch (option) { 1639 case LowDelayOption: 1640 ret = d_func()->socketEngine->option(QAbstractSocketEngine::LowDelayOption); 1641 break; 1642 1643 case KeepAliveOption: 1644 ret = d_func()->socketEngine->option(QAbstractSocketEngine::KeepAliveOption); 1645 break; 1646 } 1647 if (ret == -1) 1648 return QVariant(); 1649 else 1650 return QVariant(ret); 1651 } 1652 1653 1549 1654 /* 1550 1655 Returns the difference between msecs and elapsed. If msecs is -1, … … 1657 1762 1658 1763 /*! 1659 This function blocks until data is available for reading and the1764 This function blocks until new data is available for reading and the 1660 1765 \l{QIODevice::}{readyRead()} signal has been emitted. The function 1661 1766 will timeout after \a msecs milliseconds; the default timeout is … … 1663 1768 1664 1769 The function returns true if the readyRead() signal is emitted and 1665 there is data available for reading; otherwise it returns false1770 there is new data available for reading; otherwise it returns false 1666 1771 (if an error occurred or the operation timed out). 1667 1772 … … 1865 1970 1866 1971 /*! 1867 Aborts the current connection and resets the socket. Unlike 1868 disconnectFromHost(), this function immediately closes the socket, discarding1869 any pending data in thewrite buffer.1972 Aborts the current connection and resets the socket. Unlike disconnectFromHost(), 1973 this function immediately closes the socket, discarding any pending data in the 1974 write buffer. 1870 1975 1871 1976 \sa disconnectFromHost(), close() … … 2164 2269 2165 2270 /*! 2166 Disconnects the socket's connection with the host. 2271 Closes the I/O device for the socket, disconnects the socket's connection with the 2272 host, closes the socket, and resets the name, address, port number and underlying 2273 socket descriptor. 2274 2275 See QIODevice::close() for a description of the actions that occur when an I/O 2276 device is closed. 2167 2277 2168 2278 \sa abort() … … 2256 2366 2257 2367 // Wait for pending data to be written. 2258 if (d->socketEngine && d->socketEngine->isValid() && d->writeBuffer.size() > 0) { 2368 if (d->socketEngine && d->socketEngine->isValid() && (d->writeBuffer.size() > 0 2369 || d->socketEngine->bytesToWrite() > 0)) { 2370 // hack: when we are waiting for the socket engine to write bytes (only 2371 // possible when using Socks5 or HTTP socket engine), then close 2372 // anyway after 2 seconds. This is to prevent a timeout on Mac, where we 2373 // sometimes just did not get the write notifier from the underlying 2374 // CFSocket and no progress was made. 2375 if (d->writeBuffer.size() == 0 && d->socketEngine->bytesToWrite() > 0) { 2376 if (!d->disconnectTimer) { 2377 d->disconnectTimer = new QTimer(this); 2378 connect(d->disconnectTimer, SIGNAL(timeout()), this, 2379 SLOT(_q_forceDisconnect()), Qt::DirectConnection); 2380 } 2381 if (!d->disconnectTimer->isActive()) 2382 d->disconnectTimer->start(2000); 2383 } 2259 2384 d->socketEngine->setWriteNotificationEnabled(true); 2260 2385 … … 2457 2582 2458 2583 #ifdef QT3_SUPPORT 2459 /*! \enum QAbstractSocket::Error 2584 /*! 2585 \enum QAbstractSocket::Error 2460 2586 \compat 2461 2587 … … 2589 2715 break; 2590 2716 default: 2591 debug << "QAbstractSocket::SocketError(" << int(error) << ")";2717 debug << "QAbstractSocket::SocketError(" << int(error) << ')'; 2592 2718 break; 2593 2719 } … … 2620 2746 break; 2621 2747 default: 2622 debug << "QAbstractSocket::SocketState(" << int(state) << ")";2748 debug << "QAbstractSocket::SocketState(" << int(state) << ')'; 2623 2749 break; 2624 2750 } -
trunk/src/network/socket/qabstractsocket.h
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 ** … … 117 117 #endif 118 118 }; 119 enum SocketOption { 120 LowDelayOption, // TCP_NODELAY 121 KeepAliveOption // SO_KEEPALIVE 122 }; 119 123 120 124 QAbstractSocket(SocketType socketType, QObject *parent); … … 149 153 bool setSocketDescriptor(int socketDescriptor, SocketState state = ConnectedState, 150 154 OpenMode openMode = ReadWrite); 155 156 // ### Qt 5: Make virtual? 157 void setSocketOption(QAbstractSocket::SocketOption option, const QVariant &value); 158 QVariant socketOption(QAbstractSocket::SocketOption option); 151 159 152 160 SocketType socketType() const; … … 209 217 Q_PRIVATE_SLOT(d_func(), void _q_abortConnectionAttempt()) 210 218 Q_PRIVATE_SLOT(d_func(), void _q_testConnection()) 219 Q_PRIVATE_SLOT(d_func(), void _q_forceDisconnect()) 211 220 212 221 #ifdef QT3_SUPPORT -
trunk/src/network/socket/qabstractsocket_p.h
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 // This file is not part of the Qt API. It exists for the convenience 50 // of the Q Libraryclass. This header file may change from50 // of the QAbstractSocket class. This header file may change from 51 51 // version to version without notice, or even be removed. 52 52 // … … 94 94 void _q_testConnection(); 95 95 void _q_abortConnectionAttempt(); 96 void _q_forceDisconnect(); 96 97 97 98 bool readSocketNotifierCalled; … … 149 150 150 151 QTimer *connectTimer; 152 QTimer *disconnectTimer; 151 153 int connectTimeElapsed; 152 154 -
trunk/src/network/socket/qabstractsocketengine.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 ** -
trunk/src/network/socket/qabstractsocketengine_p.h
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 ** … … 93 93 AddressReusable, 94 94 BindExclusively, 95 ReceiveOutOfBandData 95 ReceiveOutOfBandData, 96 LowDelayOption, 97 KeepAliveOption 96 98 }; 97 99 … … 124 126 virtual qint64 pendingDatagramSize() const = 0; 125 127 #endif 128 129 virtual qint64 bytesToWrite() const = 0; 126 130 127 131 virtual int option(SocketOption option) const = 0; -
trunk/src/network/socket/qhttpsocketengine.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 ** … … 277 277 #endif // QT_NO_UDPSOCKET 278 278 279 int QHttpSocketEngine::option(SocketOption) const 280 { 279 qint64 QHttpSocketEngine::bytesToWrite() const 280 { 281 Q_D(const QHttpSocketEngine); 282 if (d->socket) { 283 return d->socket->bytesToWrite(); 284 } else { 285 return 0; 286 } 287 } 288 289 int QHttpSocketEngine::option(SocketOption option) const 290 { 291 Q_D(const QHttpSocketEngine); 292 if (d->socket) { 293 // convert the enum and call the real socket 294 if (option == QAbstractSocketEngine::LowDelayOption) 295 return d->socket->socketOption(QAbstractSocket::LowDelayOption).toInt(); 296 if (option == QAbstractSocketEngine::KeepAliveOption) 297 return d->socket->socketOption(QAbstractSocket::KeepAliveOption).toInt(); 298 } 281 299 return -1; 282 300 } 283 301 284 bool QHttpSocketEngine::setOption(SocketOption, int) 285 { 302 bool QHttpSocketEngine::setOption(SocketOption option, int value) 303 { 304 Q_D(QHttpSocketEngine); 305 if (d->socket) { 306 // convert the enum and call the real socket 307 if (option == QAbstractSocketEngine::LowDelayOption) 308 d->socket->setSocketOption(QAbstractSocket::LowDelayOption, value); 309 if (option == QAbstractSocketEngine::KeepAliveOption) 310 d->socket->setSocketOption(QAbstractSocket::KeepAliveOption, value); 311 return true; 312 } 286 313 return false; 287 314 } … … 455 482 data += " HTTP/1.1\r\n"; 456 483 data += "Proxy-Connection: keep-alive\r\n" 484 "User-Agent: Mozilla/5.0\r\n" 457 485 "Host: " + peerAddress + "\r\n"; 458 486 QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(d->authenticator); … … 735 763 , writeNotificationPending(false) 736 764 , connectionNotificationPending(false) 765 , pendingResponseData(0) 737 766 { 738 767 socket = 0; … … 769 798 } 770 799 800 QT_END_NAMESPACE 801 771 802 #endif 772 773 QT_END_NAMESPACE -
trunk/src/network/socket/qhttpsocketengine_p.h
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 ** … … 110 110 qint64 pendingDatagramSize() const; 111 111 #endif // QT_NO_UDPSOCKET 112 113 qint64 bytesToWrite() const; 112 114 113 115 int option(SocketOption option) const; -
trunk/src/network/socket/qlocalserver.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 ** … … 78 78 to use it without one. In that case, you must use waitForNewConnection(), 79 79 which blocks until either a connection is available or a timeout expires. 80 81 Note that this feature is not supported on Windows 9x.82 80 83 81 \sa QLocalSocket, QTcpServer … … 277 275 return 0; 278 276 QLocalSocket *nextSocket = d->pendingConnections.dequeue(); 277 #ifdef Q_OS_SYMBIAN 278 if(!d->socketNotifier) 279 return nextSocket; 280 #endif 281 #ifndef QT_LOCALSOCKET_TCP 282 if (d->pendingConnections.size() <= d->maxPendingConnections) 279 283 #ifndef Q_OS_WIN 280 d->socketNotifier->setEnabled(d->pendingConnections.size() 281 <= d->maxPendingConnections); 284 d->socketNotifier->setEnabled(true); 285 #else 286 d->connectionEventNotifier->setEnabled(true); 287 #endif 282 288 #endif 283 289 return nextSocket; -
trunk/src/network/socket/qlocalserver.h
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 ** … … 87 87 private: 88 88 Q_DISABLE_COPY(QLocalServer) 89 #if defined(QT_LOCALSOCKET_TCP)90 89 Q_PRIVATE_SLOT(d_func(), void _q_onNewConnection()) 91 #elif defined(Q_OS_WIN)92 Q_PRIVATE_SLOT(d_func(), void _q_openSocket(HANDLE handle))93 Q_PRIVATE_SLOT(d_func(), void _q_stoppedListening())94 Q_PRIVATE_SLOT(d_func(), void _q_setError(QAbstractSocket::SocketError error, const QString &errorString))95 #else96 Q_PRIVATE_SLOT(d_func(), void _q_socketActivated())97 #endif98 90 }; 99 91 -
trunk/src/network/socket/qlocalserver_p.h
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 ** … … 64 64 #elif defined(Q_OS_WIN) 65 65 # include <qt_windows.h> 66 # include < qthread.h>66 # include <private/qwineventnotifier_p.h> 67 67 #else 68 68 # include <private/qnativesocketengine_p.h> … … 72 72 QT_BEGIN_NAMESPACE 73 73 74 #if defined(Q_OS_WIN) && !defined(QT_LOCALSOCKET_TCP)75 76 /*!77 \internal78 QLocalServerThread exists because Windows does not have a79 way to provide notifications when there is a new connections to80 the server.81 */82 class QLocalServerThread : public QThread83 {84 Q_OBJECT85 86 Q_SIGNALS:87 void connected(HANDLE newSocket);88 void error(QAbstractSocket::SocketError error, const QString &errorString);89 90 public:91 QLocalServerThread(QObject *parent = 0);92 ~QLocalServerThread();93 void closeServer();94 95 public:96 QString setName(const QString &name);97 void run();98 void stop();99 bool makeHandle();100 101 HANDLE gotConnectionEvent;102 QQueue<HANDLE> pendingHandles;103 int maxPendingConnections;104 private:105 HANDLE stopEvent;106 QString fullServerName;107 };108 109 #endif110 111 74 class QLocalServerPrivate : public QObjectPrivate 112 75 { … … 115 78 public: 116 79 QLocalServerPrivate() : 117 #if defined(Q_OS_WIN) && !defined(QT_LOCALSOCKET_TCP) 118 inWaitingFunction(false), 119 #elif !defined(QT_LOCALSOCKET_TCP) 80 #if !defined(QT_LOCALSOCKET_TCP) && !defined(Q_OS_WIN) 120 81 listenSocket(-1), socketNotifier(0), 121 82 #endif … … 129 90 void closeServer(); 130 91 void waitForNewConnection(int msec, bool *timedOut); 92 void _q_onNewConnection(); 131 93 132 94 #if defined(QT_LOCALSOCKET_TCP) 133 void _q_onNewConnection();134 95 135 96 QTcpServer tcpServer; 136 97 QMap<quintptr, QTcpSocket*> socketMap; 137 98 #elif defined(Q_OS_WIN) 138 void _q_openSocket(HANDLE socket); 139 void _q_stoppedListening(); 140 void _q_setError(QAbstractSocket::SocketError error, const QString &errorString); 99 struct Listener { 100 HANDLE handle; 101 OVERLAPPED overlapped; 102 }; 141 103 142 QLocalServerThread waitForConnection; 143 bool inWaitingFunction; 104 void setError(const QString &function); 105 bool addListener(); 106 107 QList<Listener> listeners; 108 HANDLE eventHandle; 109 QWinEventNotifier *connectionEventNotifier; 144 110 #else 145 111 void setError(const QString &function); 146 void _q_socketActivated();147 112 148 113 int listenSocket; -
trunk/src/network/socket/qlocalserver_tcp.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 ** … … 93 93 if (pendingConnections.isEmpty()) 94 94 tcpServer.waitForNewConnection(msec, timedOut); 95 else 95 else if (timedOut) 96 96 *timedOut = false; 97 97 } -
trunk/src/network/socket/qlocalserver_unix.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 ** … … 44 44 #include "qlocalsocket.h" 45 45 #include "qlocalsocket_p.h" 46 #include "qnet_unix_p.h" 46 47 47 48 #ifndef QT_NO_LOCALSERVER … … 53 54 #include <qdir.h> 54 55 #include <qdatetime.h> 56 57 #ifdef Q_OS_VXWORKS 58 # include <selectLib.h> 59 #endif 55 60 56 61 QT_BEGIN_NAMESPACE … … 89 94 90 95 // create the unix socket 91 listenSocket = q Socket(PF_UNIX, SOCK_STREAM, 0);96 listenSocket = qt_safe_socket(PF_UNIX, SOCK_STREAM, 0); 92 97 if (-1 == listenSocket) { 93 98 setError(QLatin1String("QLocalServer::listen")); … … 107 112 fullServerName.toLatin1().size() + 1); 108 113 114 #ifdef Q_OS_SYMBIAN 115 // In SYMBIAN OS it can currently happen that accept is called twice, 116 // once from waitForNewConnection and once via QSocketNotfier activity 117 // 118 // As an workaround, we set the socket to non blocking so possible 119 // subsequent call to accept will not block in any case 120 // 121 // This change can be removed once more generic fix to select thread 122 // syncronization problem is implemented. 123 int flags = fcntl(listenSocket, F_GETFL, 0); 124 if (-1 == flags 125 || -1 == (fcntl(listenSocket, F_SETFL, flags | O_NONBLOCK))) { 126 setError(QLatin1String("QLocalServer::listen")); 127 closeServer(); 128 return false; 129 } 130 #endif 131 109 132 // bind 110 if(-1 == qBind(listenSocket, (sockaddr *)&addr, sizeof(sockaddr_un))) {133 if(-1 == QT_SOCKET_BIND(listenSocket, (sockaddr *)&addr, sizeof(sockaddr_un))) { 111 134 setError(QLatin1String("QLocalServer::listen")); 112 135 // if address is in use already, just close the socket, but do not delete the file … … 121 144 122 145 // listen for connections 123 if (-1 == q Listen(listenSocket, 50)) {146 if (-1 == qt_safe_listen(listenSocket, 50)) { 124 147 setError(QLatin1String("QLocalServer::listen")); 125 148 closeServer(); … … 133 156 QSocketNotifier::Read, q); 134 157 q->connect(socketNotifier, SIGNAL(activated(int)), 135 q, SLOT(_q_ socketActivated()));158 q, SLOT(_q_onNewConnection())); 136 159 socketNotifier->setEnabled(maxPendingConnections > 0); 137 160 return true; … … 149 172 listenSocket = -1; 150 173 151 if (socketNotifier) 174 if (socketNotifier) { 175 socketNotifier->setEnabled(false); // Otherwise, closed socket is checked before deleter runs 152 176 socketNotifier->deleteLater(); 153 socketNotifier = 0; 177 socketNotifier = 0; 178 } 154 179 155 180 if (!fullServerName.isEmpty()) … … 163 188 Accept the new socket. 164 189 */ 165 void QLocalServerPrivate::_q_ socketActivated()190 void QLocalServerPrivate::_q_onNewConnection() 166 191 { 167 192 Q_Q(QLocalServer); … … 171 196 ::sockaddr_un addr; 172 197 QT_SOCKLEN_T length = sizeof(sockaddr_un); 173 int connectedSocket = q Accept(listenSocket, (sockaddr *)&addr, &length);198 int connectedSocket = qt_safe_accept(listenSocket, (sockaddr *)&addr, &length); 174 199 if(-1 == connectedSocket) { 175 200 setError(QLatin1String("QLocalSocket::activated")); … … 192 217 timeout.tv_usec = (msec % 1000) * 1000; 193 218 194 // timeout can not be 0 or else select will return an error.195 if (0 == msec)196 timeout.tv_usec = 1000;197 198 219 int result = -1; 199 // on Linux timeout will be updated by select, but _not_ on other systems. 200 QTime timer; 201 timer.start(); 202 while (pendingConnections.isEmpty() && (-1 == msec || timer.elapsed() < msec)) { 203 result = ::select(listenSocket + 1, &readfds, 0, 0, &timeout); 204 if (-1 == result && errno != EINTR) { 205 setError(QLatin1String("QLocalServer::waitForNewConnection")); 206 closeServer(); 207 break; 208 } 209 if (result > 0) 210 _q_socketActivated(); 211 } 220 result = qt_safe_select(listenSocket + 1, &readfds, 0, 0, (msec == -1) ? 0 : &timeout); 221 if (-1 == result) { 222 setError(QLatin1String("QLocalServer::waitForNewConnection")); 223 closeServer(); 224 } 225 if (result > 0) 226 _q_onNewConnection(); 212 227 if (timedOut) 213 228 *timedOut = (result == 0); -
trunk/src/network/socket/qlocalserver_win.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 ** … … 45 45 46 46 #include <qdebug.h> 47 #include <qdatetime.h>48 #include <qcoreapplication.h>49 #include <QMetaType>50 47 51 48 // The buffer size need to be 0 otherwise data could be … … 54 51 #define BUFSIZE 0 55 52 53 // ###: This should be a property. Should replace the insane 50 on unix as well. 54 #define SYSTEM_MAX_PENDING_SOCKETS 8 55 56 56 QT_BEGIN_NAMESPACE 57 57 58 QLocalServerThread::QLocalServerThread(QObject *parent) : QThread(parent), 59 maxPendingConnections(1) 60 { 61 stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); 62 gotConnectionEvent = CreateEvent(NULL, TRUE, FALSE, NULL); 63 } 64 65 QLocalServerThread::~QLocalServerThread() 66 { 67 stop(); 68 closeServer(); 69 CloseHandle(stopEvent); 70 CloseHandle(gotConnectionEvent); 71 } 72 73 void QLocalServerThread::stop() 74 { 75 if (isRunning()) { 76 SetEvent(stopEvent); 77 wait(); 78 ResetEvent(stopEvent); 79 } 80 } 81 82 void QLocalServerThread::closeServer() 83 { 84 while (!pendingHandles.isEmpty()) 85 CloseHandle(pendingHandles.dequeue()); 86 } 87 88 QString QLocalServerThread::setName(const QString &name) 89 { 90 QString pipePath = QLatin1String("\\\\.\\pipe\\"); 91 if (name.startsWith(pipePath)) 92 fullServerName = name; 93 else 94 fullServerName = pipePath + name; 95 for (int i = pendingHandles.count(); i < maxPendingConnections; ++i) 96 if (!makeHandle()) 97 break; 98 return fullServerName; 99 } 100 101 bool QLocalServerThread::makeHandle() 102 { 103 if (pendingHandles.count() >= maxPendingConnections) 104 return false; 105 106 HANDLE handle = INVALID_HANDLE_VALUE; 107 QT_WA({ 108 handle = CreateNamedPipeW( 109 (TCHAR*)fullServerName.utf16(), // pipe name 58 bool QLocalServerPrivate::addListener() 59 { 60 // The object must not change its address once the 61 // contained OVERLAPPED struct is passed to Windows. 62 listeners << Listener(); 63 Listener &listener = listeners.last(); 64 65 listener.handle = CreateNamedPipe( 66 (const wchar_t *)fullServerName.utf16(), // pipe name 110 67 PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, // read/write access 111 68 PIPE_TYPE_MESSAGE | // message type pipe … … 117 74 3000, // client time-out 118 75 NULL); 119 }, { 120 handle = CreateNamedPipeA( 121 fullServerName.toLocal8Bit().constData(), // pipe name 122 PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, // read/write access 123 PIPE_TYPE_MESSAGE | // message type pipe 124 PIPE_READMODE_MESSAGE | // message-read mode 125 PIPE_WAIT, // blocking mode 126 PIPE_UNLIMITED_INSTANCES, // max. instances 127 BUFSIZE, // output buffer size 128 BUFSIZE, // input buffer size 129 3000, // client time-out 130 NULL); 131 }); 132 133 if (INVALID_HANDLE_VALUE == handle) { 76 77 if (listener.handle == INVALID_HANDLE_VALUE) { 78 setError(QLatin1String("QLocalServerPrivate::addListener")); 79 listeners.removeLast(); 134 80 return false; 135 81 } 136 pendingHandles.enqueue(handle); 82 83 memset(&listener.overlapped, 0, sizeof(listener.overlapped)); 84 listener.overlapped.hEvent = eventHandle; 85 if (!ConnectNamedPipe(listener.handle, &listener.overlapped)) { 86 switch (GetLastError()) { 87 case ERROR_IO_PENDING: 88 break; 89 case ERROR_PIPE_CONNECTED: 90 SetEvent(eventHandle); 91 break; 92 default: 93 CloseHandle(listener.handle); 94 setError(QLatin1String("QLocalServerPrivate::addListener")); 95 listeners.removeLast(); 96 return false; 97 } 98 } else { 99 Q_ASSERT_X(false, "QLocalServerPrivate::addListener", "The impossible happened"); 100 SetEvent(eventHandle); 101 } 137 102 return true; 138 103 } 139 104 140 void QLocalServerThread::run() 141 { 142 OVERLAPPED op; 143 HANDLE handleArray[2]; 144 memset(&op, 0, sizeof(op)); 145 handleArray[0] = op.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); 146 handleArray[1] = stopEvent; 147 HANDLE handle = INVALID_HANDLE_VALUE; 148 149 forever { 150 if (INVALID_HANDLE_VALUE == handle) { 151 makeHandle(); 152 if (!pendingHandles.isEmpty()) 153 handle = pendingHandles.dequeue(); 154 } 155 if (INVALID_HANDLE_VALUE == handle) { 156 int windowsError = GetLastError(); 157 QString function = QLatin1String("QLocalServer::run"); 158 QString errorString = QLocalServer::tr("%1: Unknown error %2").arg(function).arg(windowsError); 159 emit error(QAbstractSocket::UnknownSocketError, errorString); 160 CloseHandle(handleArray[0]); 161 SetEvent(gotConnectionEvent); 162 return; 163 } 164 165 BOOL isConnected = ConnectNamedPipe(handle, &op) ? TRUE : (GetLastError() == ERROR_PIPE_CONNECTED); 166 if (!isConnected) { 167 switch (WaitForMultipleObjects(2, handleArray, FALSE, INFINITE)) 168 { 169 case WAIT_OBJECT_0 + 1: 170 CloseHandle(handle); 171 CloseHandle(handleArray[0]); 105 void QLocalServerPrivate::setError(const QString &function) 106 { 107 int windowsError = GetLastError(); 108 errorString = QString::fromLatin1("%1: %2").arg(function).arg(qt_error_string(windowsError)); 109 error = QAbstractSocket::UnknownSocketError; 110 } 111 112 void QLocalServerPrivate::init() 113 { 114 } 115 116 bool QLocalServerPrivate::removeServer(const QString &name) 117 { 118 Q_UNUSED(name); 119 return true; 120 } 121 122 bool QLocalServerPrivate::listen(const QString &name) 123 { 124 Q_Q(QLocalServer); 125 126 QString pipePath = QLatin1String("\\\\.\\pipe\\"); 127 if (name.startsWith(pipePath)) 128 fullServerName = name; 129 else 130 fullServerName = pipePath + name; 131 132 // Use only one event for all listeners of one socket. 133 // The idea is that listener events are rare, so polling all listeners once in a while is 134 // cheap compared to waiting for N additional events in each iteration of the main loop. 135 eventHandle = CreateEvent(NULL, TRUE, FALSE, NULL); 136 connectionEventNotifier = new QWinEventNotifier(eventHandle , q); 137 q->connect(connectionEventNotifier, SIGNAL(activated(HANDLE)), q, SLOT(_q_onNewConnection())); 138 139 for (int i = 0; i < SYSTEM_MAX_PENDING_SOCKETS; ++i) 140 if (!addListener()) 141 return false; 142 return true; 143 } 144 145 void QLocalServerPrivate::_q_onNewConnection() 146 { 147 Q_Q(QLocalServer); 148 DWORD dummy; 149 150 // Reset first, otherwise we could reset an event which was asserted 151 // immediately after we checked the conn status. 152 ResetEvent(eventHandle); 153 154 // Testing shows that there is indeed absolutely no guarantee which listener gets 155 // a client connection first, so there is no way around polling all of them. 156 for (int i = 0; i < listeners.size(); ) { 157 HANDLE handle = listeners[i].handle; 158 if (GetOverlappedResult(handle, &listeners[i].overlapped, &dummy, FALSE)) { 159 listeners.removeAt(i); 160 161 addListener(); 162 163 if (pendingConnections.size() > maxPendingConnections) 164 connectionEventNotifier->setEnabled(false); 165 166 // Make this the last thing so connected slots can wreak the least havoc 167 q->incomingConnection((quintptr)handle); 168 } else { 169 if (GetLastError() != ERROR_IO_INCOMPLETE) { 170 setError(QLatin1String("QLocalServerPrivate::_q_onNewConnection")); 171 closeServer(); 172 172 return; 173 173 } 174 175 ++i; 174 176 } 175 emit connected(handle); 176 handle = INVALID_HANDLE_VALUE; 177 ResetEvent(handleArray[0]); 178 SetEvent(gotConnectionEvent); 179 } 180 } 181 182 void QLocalServerPrivate::init() 183 { 184 Q_Q(QLocalServer); 185 qRegisterMetaType<HANDLE>("HANDLE"); 186 q->connect(&waitForConnection, SIGNAL(connected(HANDLE)), 187 q, SLOT(_q_openSocket(HANDLE)), Qt::QueuedConnection); 188 q->connect(&waitForConnection, SIGNAL(finished()), 189 q, SLOT(_q_stoppedListening()), Qt::QueuedConnection); 190 q->connect(&waitForConnection, SIGNAL(terminated()), 191 q, SLOT(_q_stoppedListening()), Qt::QueuedConnection); 192 q->connect(&waitForConnection, SIGNAL(error(QAbstractSocket::SocketError, const QString &)), 193 q, SLOT(_q_setError(QAbstractSocket::SocketError, const QString &))); 194 } 195 196 bool QLocalServerPrivate::removeServer(const QString &name) 197 { 198 Q_UNUSED(name); 199 return true; 200 } 201 202 bool QLocalServerPrivate::listen(const QString &name) 203 { 204 fullServerName = waitForConnection.setName(name); 205 serverName = name; 206 waitForConnection.start(); 207 return true; 208 } 209 210 void QLocalServerPrivate::_q_setError(QAbstractSocket::SocketError e, const QString &eString) 211 { 212 error = e; 213 errorString = eString; 214 } 215 216 void QLocalServerPrivate::_q_stoppedListening() 217 { 218 Q_Q(QLocalServer); 219 if (!inWaitingFunction) 220 q->close(); 221 } 222 223 void QLocalServerPrivate::_q_openSocket(HANDLE handle) 224 { 225 Q_Q(QLocalServer); 226 q->incomingConnection((int)handle); 177 } 227 178 } 228 179 229 180 void QLocalServerPrivate::closeServer() 230 181 { 231 waitForConnection.stop(); 232 waitForConnection.closeServer(); 182 connectionEventNotifier->setEnabled(false); // Otherwise, closed handle is checked before deleter runs 183 connectionEventNotifier->deleteLater(); 184 connectionEventNotifier = 0; 185 CloseHandle(eventHandle); 186 for (int i = 0; i < listeners.size(); ++i) 187 CloseHandle(listeners[i].handle); 188 listeners.clear(); 233 189 } 234 190 … … 239 195 return; 240 196 241 DWORD result = WaitForSingleObject(waitForConnection.gotConnectionEvent, 242 (msecs == -1) ? INFINITE : msecs); 197 DWORD result = WaitForSingleObject(eventHandle, (msecs == -1) ? INFINITE : msecs); 243 198 if (result == WAIT_TIMEOUT) { 244 199 if (timedOut) 245 200 *timedOut = true; 246 201 } else { 247 ResetEvent(waitForConnection.gotConnectionEvent); 248 QCoreApplication::instance()->processEvents(); 202 _q_onNewConnection(); 249 203 } 250 204 } -
trunk/src/network/socket/qlocalsocket.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 ** … … 64 64 which blocks until the operation is complete or the timeout expires. 65 65 66 Note that this feature is not supported on Window 9x. 66 Note that this feature is not supported on versions of Windows earlier than 67 Windows XP. 67 68 68 69 \sa QLocalServer … … 103 104 specified by \a socketState. 104 105 105 Note:It is not possible to initialize two local sockets with the same106 \note It is not possible to initialize two local sockets with the same 106 107 native socket descriptor. 107 108 … … 208 209 returns false. 209 210 210 Note:The socket's state must be ConnectedState before reading211 \note The socket's state must be ConnectedState before reading 211 212 and writing can occur. 212 213 213 \sa state() 214 \sa state(), connectToServer() 214 215 */ 215 216 … … 244 245 245 246 /*! 246 \fn bool QLocalSocket::waitForConnected(int msec )247 248 Waits until the socket is connected, up to \a msec milliseconds. If the247 \fn bool QLocalSocket::waitForConnected(int msecs) 248 249 Waits until the socket is connected, up to \a msecs milliseconds. If the 249 250 connection has been established, this function returns true; otherwise 250 251 it returns false. In the case where it returns false, you can call … … 256 257 \snippet doc/src/snippets/code/src_network_socket_qlocalsocket_unix.cpp 0 257 258 258 If msecs is -1, this function will not time out.259 If \a msecs is -1, this function will not time out. 259 260 260 261 \sa connectToServer(), connected() … … 275 276 \snippet doc/src/snippets/code/src_network_socket_qlocalsocket_unix.cpp 1 276 277 277 If msecs is -1, this function will not time out.278 If \a msecs is -1, this function will not time out. 278 279 279 280 \sa disconnectFromServer(), close() … … 310 311 311 312 QLocalSocket::LocalSocketError is not a registered metatype, so for queued 312 connections, you will have to register it with Q_DECLARE_METATYPE. 313 314 \sa error(), errorString() 313 connections, you will have to register it with Q_DECLARE_METATYPE() and 314 qRegisterMetaType(). 315 316 \sa error(), errorString(), {Creating Custom Qt Types} 315 317 */ 316 318 … … 322 324 323 325 QLocalSocket::SocketState is not a registered metatype, so for queued 324 connections, you will have to register it with Q_DECLARE_METATYPE. 325 326 \sa state() 326 connections, you will have to register it with Q_DECLARE_METATYPE() and 327 qRegisterMetaType(). 328 329 \sa state(), {Creating Custom Qt Types} 327 330 */ 328 331 … … 366 369 Returns the server path that the socket is connected to. 367 370 368 Note: This is platform specific371 \note The return value of this function is platform specific. 369 372 370 373 \sa connectToServer(), serverName() … … 469 472 break; 470 473 default: 471 debug << "QLocalSocket::SocketError(" << int(error) << ")";474 debug << "QLocalSocket::SocketError(" << int(error) << ')'; 472 475 break; 473 476 } … … 491 494 break; 492 495 default: 493 debug << "QLocalSocket::SocketState(" << int(state) << ")";496 debug << "QLocalSocket::SocketState(" << int(state) << ')'; 494 497 break; 495 498 } -
trunk/src/network/socket/qlocalsocket.h
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 ** … … 135 135 Q_PRIVATE_SLOT(d_func(), void _q_canWrite()) 136 136 Q_PRIVATE_SLOT(d_func(), void _q_pipeClosed()) 137 Q_PRIVATE_SLOT(d_func(), void _q_emitReadyRead()) 137 138 #else 138 139 Q_PRIVATE_SLOT(d_func(), void _q_stateChanged(QAbstractSocket::SocketState)) -
trunk/src/network/socket/qlocalsocket_p.h
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 ** … … 66 66 # include "private/qwindowspipewriter_p.h" 67 67 # include "private/qringbuffer_p.h" 68 # include <private/qwineventnotifier_p.h> 68 69 #else 69 70 # include "private/qnativesocketengine_p.h" … … 74 75 75 76 QT_BEGIN_NAMESPACE 76 77 #if !defined(Q_OS_WIN) && !defined(QT_LOCALSOCKET_TCP)78 static inline int qSocket(int af, int socketype, int proto)79 {80 int ret;81 while((ret = qt_socket_socket(af, socketype, proto)) == -1 && errno == EINTR){}82 return ret;83 }84 85 static inline int qBind(int fd, const sockaddr *sa, int len)86 {87 int ret;88 while((ret = QT_SOCKET_BIND(fd, (sockaddr*)sa, len)) == -1 && errno == EINTR){}89 return ret;90 }91 92 static inline int qConnect(int fd, const sockaddr *sa, int len)93 {94 int ret;95 while((ret = QT_SOCKET_CONNECT(fd, (sockaddr*)sa, len)) == -1 && errno == EINTR){}96 return ret;97 }98 99 static inline int qListen(int fd, int backlog)100 {101 int ret;102 while((ret = qt_socket_listen(fd, backlog)) == -1 && errno == EINTR){}103 return ret;104 }105 106 static inline int qAccept(int fd, struct sockaddr *addr, QT_SOCKLEN_T *addrlen)107 {108 int ret;109 while((ret = qt_socket_accept(fd, addr, addrlen)) == -1 && errno == EINTR){}110 return ret;111 }112 #endif //#if !defined(Q_OS_WIN) && !defined(QT_LOCALSOCKET_TCP)113 77 114 78 #if !defined(Q_OS_WIN) || defined(QT_LOCALSOCKET_TCP) … … 173 137 void _q_canWrite(); 174 138 void _q_pipeClosed(); 175 qint64 readData(char *data, qint64 maxSize); 176 qint64 bytesAvailable(); 177 bool readFromSocket(); 139 void _q_emitReadyRead(); 140 DWORD bytesAvailable(); 141 void startAsyncRead(); 142 bool completeAsyncRead(); 143 void checkReadyRead(); 178 144 HANDLE handle; 179 145 OVERLAPPED overlapped; … … 181 147 qint64 readBufferMaxSize; 182 148 QRingBuffer readBuffer; 183 QTimer dataNotifier; 149 int actualReadBufferSize; 150 QWinEventNotifier *dataReadNotifier; 184 151 QLocalSocket::LocalSocketError error; 185 bool readyReadEmitted; 152 bool readSequenceStarted; 153 bool pendingReadyRead; 186 154 bool pipeClosed; 155 static const qint64 initialReadBufferSize = 4096; 187 156 #else 188 157 QLocalUnixSocket unixSocket; … … 193 162 void _q_connectToSocket(); 194 163 void _q_abortConnectionAttempt(); 164 void cancelDelayedConnect(); 195 165 QSocketNotifier *delayConnect; 196 166 QTimer *connectTimer; -
trunk/src/network/socket/qlocalsocket_tcp.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 ** -
trunk/src/network/socket/qlocalsocket_unix.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 ** … … 42 42 #include "qlocalsocket.h" 43 43 #include "qlocalsocket_p.h" 44 #include "qnet_unix_p.h" 44 45 45 46 #ifndef QT_NO_LOCALSOCKET … … 55 56 #include <qdir.h> 56 57 #include <qdebug.h> 58 59 #ifdef Q_OS_VXWORKS 60 # include <selectLib.h> 61 #endif 57 62 58 63 #define QT_CONNECT_TIMEOUT 30000 … … 233 238 234 239 // create the socket 235 if (-1 == (d->connectingSocket = q Socket(PF_UNIX, SOCK_STREAM, 0))) {240 if (-1 == (d->connectingSocket = qt_safe_socket(PF_UNIX, SOCK_STREAM, 0))) { 236 241 d->errorOccurred(UnsupportedSocketOperationError, 237 242 QLatin1String("QLocalSocket::connectToServer")); 238 243 return; 239 244 } 240 245 #ifndef Q_OS_SYMBIAN 241 246 // set non blocking so we can try to connect and it wont wait 242 247 int flags = fcntl(d->connectingSocket, F_GETFL, 0); … … 247 252 return; 248 253 } 254 #endif 249 255 250 256 // _q_connectToSocket does the actual connecting … … 283 289 ::memcpy(name.sun_path, connectingPathName.toLatin1().data(), 284 290 connectingPathName.toLatin1().size() + 1); 285 if (-1 == q Connect(connectingSocket, (struct sockaddr *)&name, sizeof(name))) {291 if (-1 == qt_safe_connect(connectingSocket, (struct sockaddr *)&name, sizeof(name))) { 286 292 QString function = QLatin1String("QLocalSocket::connectToServer"); 287 293 switch (errno) … … 304 310 // Try again later, all of the sockets listening are full 305 311 if (!delayConnect) { 306 delayConnect = new QSocketNotifier(connectingSocket, QSocketNotifier::Write );312 delayConnect = new QSocketNotifier(connectingSocket, QSocketNotifier::Write, q); 307 313 q->connect(delayConnect, SIGNAL(activated(int)), q, SLOT(_q_connectToSocket())); 308 314 } … … 323 329 324 330 // connected! 325 if (delayConnect) { 326 delayConnect->setEnabled(false); 327 delete delayConnect; 328 delayConnect = 0; 329 } 331 cancelDelayedConnect(); 332 330 333 serverName = connectingName; 331 334 fullServerName = connectingPathName; … … 374 377 } 375 378 379 void QLocalSocketPrivate::cancelDelayedConnect() 380 { 381 if (delayConnect) { 382 delayConnect->setEnabled(false); 383 delete delayConnect; 384 delayConnect = 0; 385 connectTimer->stop(); 386 delete connectTimer; 387 connectTimer = 0; 388 } 389 } 390 376 391 quintptr QLocalSocket::socketDescriptor() const 377 392 { … … 420 435 Q_D(QLocalSocket); 421 436 d->unixSocket.close(); 422 if (d->delayConnect) { 423 d->delayConnect->setEnabled(false); 424 delete d->delayConnect; 425 d->delayConnect = 0; 426 d->connectTimer->stop(); 427 delete d->connectTimer; 428 d->connectTimer = 0; 429 } 437 d->cancelDelayedConnect(); 430 438 if (d->connectingSocket != -1) 431 439 ::close(d->connectingSocket); … … 513 521 return (state() == ConnectedState); 514 522 515 fd_set readfds;516 FD_ZERO(& readfds);517 FD_SET(d->connectingSocket, & readfds);523 fd_set fds; 524 FD_ZERO(&fds); 525 FD_SET(d->connectingSocket, &fds); 518 526 519 527 timeval timeout; … … 531 539 while (state() == ConnectingState 532 540 && (-1 == msec || timer.elapsed() < msec)) { 533 result = ::select(d->connectingSocket + 1, &readfds, 0, 0, &timeout); 541 #ifdef Q_OS_SYMBIAN 542 // On Symbian, ready-to-write is signaled when non-blocking socket 543 // connect is finised. Is ready-to-read really used on other 544 // UNIX paltforms when using non-blocking AF_UNIX socket? 545 result = ::select(d->connectingSocket + 1, 0, &fds, 0, &timeout); 546 #else 547 result = ::select(d->connectingSocket + 1, &fds, 0, 0, &timeout); 548 #endif 534 549 if (-1 == result && errno != EINTR) { 535 550 d->errorOccurred( QLocalSocket::UnknownSocketError, -
trunk/src/network/socket/qlocalsocket_win.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 ** … … 49 49 QT_BEGIN_NAMESPACE 50 50 51 #define NOTIFYTIMEOUT 10052 53 51 void QLocalSocketPrivate::init() 54 52 { 55 53 Q_Q(QLocalSocket); 56 QObject::connect(&dataNotifier, SIGNAL(timeout()), q, SLOT(_q_notified()));54 memset(&overlapped, 0, sizeof(overlapped)); 57 55 overlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); 56 dataReadNotifier = new QWinEventNotifier(overlapped.hEvent, q); 57 q->connect(dataReadNotifier, SIGNAL(activated(HANDLE)), q, SLOT(_q_notified())); 58 58 } 59 59 … … 102 102 pipeWriter(0), 103 103 readBufferMaxSize(0), 104 actualReadBufferSize(0), 104 105 error(QLocalSocket::UnknownSocketError), 105 readyReadEmitted(false), 106 readSequenceStarted(false), 107 pendingReadyRead(false), 106 108 pipeClosed(false), 107 109 state(QLocalSocket::UnconnectedState) … … 138 140 DWORD permissions = (openMode & QIODevice::ReadOnly) ? GENERIC_READ : 0; 139 141 permissions |= (openMode & QIODevice::WriteOnly) ? GENERIC_WRITE : 0; 140 QT_WA({ 141 localSocket = CreateFileW( 142 (TCHAR*)d->fullServerName.utf16(), // pipe name 143 permissions, 144 0, // no sharing 145 NULL, // default security attributes 146 OPEN_EXISTING, // opens existing pipe 147 0, // default attributes 148 NULL); // no template file 149 }, { 150 localSocket = CreateFileA( 151 d->fullServerName.toLocal8Bit().constData(), // pipe name 152 permissions, 153 0, // no sharing 154 NULL, // default security attributes 155 OPEN_EXISTING, // opens existing pipe 156 0, // default attributes 157 NULL); // no template file 158 }); 142 localSocket = CreateFile((const wchar_t *)d->fullServerName.utf16(), // pipe name 143 permissions, 144 0, // no sharing 145 NULL, // default security attributes 146 OPEN_EXISTING, // opens existing pipe 147 FILE_FLAG_OVERLAPPED, 148 NULL); // no template file 149 159 150 if (localSocket != INVALID_HANDLE_VALUE) 160 151 break; … … 166 157 167 158 // All pipe instances are busy, so wait until connected or up to 5 seconds. 168 QT_WA({ 169 if (!WaitNamedPipeW((TCHAR*)d->fullServerName.utf16(), 5000)) 170 break; 171 }, { 172 if (!WaitNamedPipeA(d->fullServerName.toLocal8Bit().constData(), 5000)) 173 break; 174 }); 159 if (!WaitNamedPipe((const wchar_t *)d->fullServerName.utf16(), 5000)) 160 break; 175 161 } 176 162 … … 183 169 // we have a valid handle 184 170 d->serverName = name; 185 if (setSocketDescriptor((quintptr)localSocket ), openMode) {171 if (setSocketDescriptor((quintptr)localSocket, ConnectedState, openMode)) { 186 172 d->handle = localSocket; 187 173 emit connected(); … … 193 179 { 194 180 Q_D(QLocalSocket); 195 if (d->readBuffer.isEmpty()) { 196 if (!d->readFromSocket()) { 197 if (d->pipeClosed) 198 return -1; 199 return 0; 200 } 201 } 202 203 if (!d->dataNotifier.isActive() && d->threadData->eventDispatcher) 204 d->dataNotifier.start(NOTIFYTIMEOUT); 205 206 if (d->readBuffer.isEmpty()) 207 return qint64(0); 208 209 // If readFromSocket() read data, copy it to its destination. 210 if (maxSize == 1) { 181 182 qint64 readSoFar; 183 // If startAsyncRead() read data, copy it to its destination. 184 if (maxSize == 1 && d->actualReadBufferSize > 0) { 211 185 *data = d->readBuffer.getChar(); 212 return 1; 213 } 214 215 qint64 bytesToRead = qMin(qint64(d->readBuffer.size()), maxSize); 216 qint64 readSoFar = 0; 217 while (readSoFar < bytesToRead) { 218 const char *ptr = d->readBuffer.readPointer(); 219 int bytesToReadFromThisBlock = qMin(int(bytesToRead - readSoFar), 220 d->readBuffer.nextDataBlockSize()); 221 memcpy(data + readSoFar, ptr, bytesToReadFromThisBlock); 222 readSoFar += bytesToReadFromThisBlock; 223 d->readBuffer.free(bytesToReadFromThisBlock); 224 } 186 d->actualReadBufferSize--; 187 readSoFar = 1; 188 } else { 189 qint64 bytesToRead = qMin(qint64(d->actualReadBufferSize), maxSize); 190 readSoFar = 0; 191 while (readSoFar < bytesToRead) { 192 const char *ptr = d->readBuffer.readPointer(); 193 int bytesToReadFromThisBlock = qMin(bytesToRead - readSoFar, 194 qint64(d->readBuffer.nextDataBlockSize())); 195 memcpy(data + readSoFar, ptr, bytesToReadFromThisBlock); 196 readSoFar += bytesToReadFromThisBlock; 197 d->readBuffer.free(bytesToReadFromThisBlock); 198 d->actualReadBufferSize -= bytesToReadFromThisBlock; 199 } 200 } 201 202 if (d->pipeClosed) { 203 if (readSoFar == 0) { 204 QTimer::singleShot(0, this, SLOT(_q_pipeClosed())); 205 return -1; // signal EOF 206 } 207 } else { 208 if (!d->readSequenceStarted) 209 d->startAsyncRead(); 210 d->checkReadyRead(); 211 } 212 225 213 return readSoFar; 226 214 } … … 228 216 /*! 229 217 \internal 230 read from the socket218 Schedules or cancels a readyRead() emission depending on actual data availability 231 219 */ 232 qint64 QLocalSocketPrivate::readData(char *data, qint64 maxSize) 233 { 234 DWORD bytesRead = 0; 235 overlapped.Offset = 0; 236 overlapped.OffsetHigh = 0; 237 bool success = ReadFile(handle, data, maxSize, &bytesRead, &overlapped); 238 if (!success && GetLastError() == ERROR_IO_PENDING) 239 if (GetOverlappedResult(handle, &overlapped, &bytesRead, TRUE)) 240 success = true; 241 if (!success) { 242 setErrorString(QLatin1String("QLocalSocket::readData")); 243 return 0; 244 } 245 return bytesRead; 220 void QLocalSocketPrivate::checkReadyRead() 221 { 222 if (actualReadBufferSize > 0) { 223 if (!pendingReadyRead) { 224 Q_Q(QLocalSocket); 225 QTimer::singleShot(0, q, SLOT(_q_emitReadyRead())); 226 pendingReadyRead = true; 227 } 228 } else { 229 pendingReadyRead = false; 230 } 246 231 } 247 232 … … 250 235 Reads data from the socket into the readbuffer 251 236 */ 252 bool QLocalSocketPrivate::readFromSocket() 253 { 254 qint64 bytesToRead = bytesAvailable(); 255 if (bytesToRead == 0) 237 void QLocalSocketPrivate::startAsyncRead() 238 { 239 do { 240 DWORD bytesToRead = bytesAvailable(); 241 if (bytesToRead == 0) { 242 // There are no bytes in the pipe but we need to 243 // start the overlapped read with some buffer size. 244 bytesToRead = initialReadBufferSize; 245 } 246 247 if (readBufferMaxSize && bytesToRead > (readBufferMaxSize - readBuffer.size())) { 248 bytesToRead = readBufferMaxSize - readBuffer.size(); 249 if (bytesToRead == 0) { 250 // Buffer is full. User must read data from the buffer 251 // before we can read more from the pipe. 252 return; 253 } 254 } 255 256 char *ptr = readBuffer.reserve(bytesToRead); 257 258 readSequenceStarted = true; 259 if (ReadFile(handle, ptr, bytesToRead, NULL, &overlapped)) { 260 completeAsyncRead(); 261 } else { 262 switch (GetLastError()) { 263 case ERROR_IO_PENDING: 264 // This is not an error. We're getting notified, when data arrives. 265 return; 266 case ERROR_PIPE_NOT_CONNECTED: 267 { 268 // It may happen, that the other side closes the connection directly 269 // after writing data. Then we must set the appropriate socket state. 270 pipeClosed = true; 271 Q_Q(QLocalSocket); 272 emit q->readChannelFinished(); 273 return; 274 } 275 default: 276 setErrorString(QLatin1String("QLocalSocketPrivate::startAsyncRead")); 277 return; 278 } 279 } 280 } while (!readSequenceStarted); 281 } 282 283 /*! 284 \internal 285 Sets the correct size of the read buffer after a read operation. 286 Returns false, if an error occured or the connection dropped. 287 */ 288 bool QLocalSocketPrivate::completeAsyncRead() 289 { 290 ResetEvent(overlapped.hEvent); 291 readSequenceStarted = false; 292 293 DWORD bytesRead; 294 if (!GetOverlappedResult(handle, &overlapped, &bytesRead, TRUE)) { 295 if (GetLastError() != ERROR_PIPE_NOT_CONNECTED) 296 setErrorString(QLatin1String("QLocalSocketPrivate::completeAsyncRead")); 256 297 return false; 257 258 if (readBufferMaxSize && bytesToRead 259 > (readBufferMaxSize - readBuffer.size())) 260 bytesToRead = readBufferMaxSize - readBuffer.size(); 261 262 char *ptr = readBuffer.reserve(bytesToRead); 263 qint64 readBytes = readData(ptr, bytesToRead); 264 if (readBytes == 0) { 265 readBuffer.chop(bytesToRead); 266 return false; 267 } 268 readyReadEmitted = false; 269 readBuffer.chop(int(bytesToRead - (readBytes < 0 ? qint64(0) : readBytes))); 298 } 299 300 actualReadBufferSize += bytesRead; 301 readBuffer.truncate(actualReadBufferSize); 270 302 return true; 271 303 } … … 276 308 if (!d->pipeWriter) { 277 309 d->pipeWriter = new QWindowsPipeWriter(d->handle, this); 310 connect(d->pipeWriter, SIGNAL(canWrite()), this, SLOT(_q_canWrite())); 311 connect(d->pipeWriter, SIGNAL(bytesWritten(qint64)), this, SIGNAL(bytesWritten(qint64))); 278 312 d->pipeWriter->start(); 279 connect(d->pipeWriter, SIGNAL(canWrite()), this, SLOT(_q_canWrite()));280 313 } 281 314 return d->pipeWriter->write(data, maxSize); … … 290 323 The number of bytes available from the pipe 291 324 */ 292 qint64QLocalSocketPrivate::bytesAvailable()325 DWORD QLocalSocketPrivate::bytesAvailable() 293 326 { 294 327 Q_Q(QLocalSocket); 295 if (q->state() != QLocalSocket::ConnectedState)296 return 0;297 328 DWORD bytes; 298 329 if (PeekNamedPipe(handle, NULL, 0, NULL, &bytes, NULL)) { 299 330 return bytes; 300 331 } else { 301 if ( ERROR_BROKEN_PIPE == GetLastError() &&!pipeClosed) {332 if (!pipeClosed) { 302 333 pipeClosed = true; 334 emit q->readChannelFinished(); 303 335 QTimer::singleShot(0, q, SLOT(_q_pipeClosed())); 304 336 } … … 317 349 Q_D(const QLocalSocket); 318 350 qint64 available = QIODevice::bytesAvailable(); 319 available += (qint64) d-> readBuffer.size();351 available += (qint64) d->actualReadBufferSize; 320 352 return available; 321 353 } … … 332 364 if (state() != ConnectedState) 333 365 return false; 334 return (d->readBuffer.indexOf('\n') != -1 || QIODevice::canReadLine()); 366 return (QIODevice::canReadLine() 367 || d->readBuffer.indexOf('\n', d->actualReadBufferSize) != -1); 335 368 } 336 369 … … 344 377 d->state = ClosingState; 345 378 emit stateChanged(d->state); 346 d->readyReadEmitted = false;347 emit readChannelFinished();379 if (!d->pipeClosed) 380 emit readChannelFinished(); 348 381 d->serverName = QString(); 349 382 d->fullServerName = QString(); … … 353 386 return; 354 387 } 388 d->readSequenceStarted = false; 389 d->pendingReadyRead = false; 355 390 d->pipeClosed = false; 356 391 DisconnectNamedPipe(d->handle); 357 392 CloseHandle(d->handle); 358 393 d->handle = INVALID_HANDLE_VALUE; 394 ResetEvent(d->overlapped.hEvent); 359 395 d->state = UnconnectedState; 360 396 emit stateChanged(d->state); … … 364 400 d->pipeWriter = 0; 365 401 } 366 d->dataNotifier.stop();367 402 } 368 403 … … 398 433 Q_D(QLocalSocket); 399 434 d->readBuffer.clear(); 435 d->actualReadBufferSize = 0; 400 436 QIODevice::open(openMode); 401 437 d->handle = (int*)socketDescriptor; 402 438 d->state = socketState; 403 439 emit stateChanged(d->state); 404 if (d->threadData->eventDispatcher) 405 d->dataNotifier.start(NOTIFYTIMEOUT); 440 if (d->state == ConnectedState && openMode.testFlag(QIODevice::ReadOnly)) { 441 d->startAsyncRead(); 442 d->checkReadyRead(); 443 } 406 444 return true; 407 445 } … … 417 455 { 418 456 Q_Q(QLocalSocket); 419 if (0 != bytesAvailable()) { 420 if (readBufferMaxSize == 0 || readBuffer.size() < readBufferMaxSize) { 421 if (!readFromSocket()) { 422 return; 423 } 424 // wait until buffer is cleared before starting again 425 if (readBufferMaxSize && readBuffer.size() == readBufferMaxSize) { 426 dataNotifier.stop(); 427 } 428 } 429 if (!readyReadEmitted) { 430 readyReadEmitted = true; 431 q->emit readyRead(); 432 } 457 if (!completeAsyncRead()) { 458 pipeClosed = true; 459 emit q->readChannelFinished(); 460 return; 461 } 462 startAsyncRead(); 463 pendingReadyRead = false; 464 emit q->readyRead(); 465 } 466 467 void QLocalSocketPrivate::_q_emitReadyRead() 468 { 469 if (pendingReadyRead) { 470 Q_Q(QLocalSocket); 471 pendingReadyRead = false; 472 emit q->readyRead(); 433 473 } 434 474 } … … 463 503 if (state() == UnconnectedState) 464 504 return false; 505 if (!openMode().testFlag(QIODevice::ReadOnly)) { 506 qWarning("QLocalSocket::waitForDisconnected isn't supported for write only pipes."); 507 return false; 508 } 465 509 QIncrementalSleepTimer timer(msecs); 466 510 forever { 467 d-> _q_notified();468 469 511 d->bytesAvailable(); // to check if PeekNamedPipe fails 512 if (d->pipeClosed) 513 close(); 470 514 if (state() == UnconnectedState) 471 515 return true; … … 487 531 { 488 532 Q_D(QLocalSocket); 489 QIncrementalSleepTimer timer(msecs); 490 forever { 491 d->_q_notified(); 492 if (bytesAvailable() > 0) { 493 if (!d->readyReadEmitted) { 494 d->readyReadEmitted = true; 495 emit readyRead(); 496 } 533 534 if (bytesAvailable() > 0) 535 return true; 536 537 if (d->state != QLocalSocket::ConnectedState) 538 return false; 539 540 Q_ASSERT(d->readSequenceStarted); 541 DWORD result = WaitForSingleObject(d->overlapped.hEvent, msecs == -1 ? INFINITE : msecs); 542 switch (result) { 543 case WAIT_OBJECT_0: 544 d->_q_notified(); 497 545 return true; 498 } 499 500 Sleep(timer.nextSleepTime()); 501 if (timer.hasTimedOut()) 502 break; 503 } 504 546 case WAIT_TIMEOUT: 547 return false; 548 } 549 550 qWarning("QLocalSocket::waitForReadyRead WaitForSingleObject failed with error code %d.", int(GetLastError())); 505 551 return false; 506 552 } … … 512 558 return false; 513 559 514 QIncrementalSleepTimer timer(msecs); 515 forever { 516 if (d->pipeWriter->hadWritten()) 517 return true; 518 519 if (d->pipeWriter->bytesToWrite() == 0) 520 return false; 521 522 // Wait for the pipe writer to acknowledge that it has 523 // written. This will succeed if either the pipe writer has 524 // already written the data, or if it manages to write data 525 // within the given timeout. 526 if (d->pipeWriter->waitForWrite(0)) 527 return true; 528 529 Sleep(timer.nextSleepTime()); 530 if (timer.hasTimedOut()) 531 break; 532 } 533 534 return false; 560 // Wait for the pipe writer to acknowledge that it has 561 // written. This will succeed if either the pipe writer has 562 // already written the data, or if it manages to write data 563 // within the given timeout. 564 return d->pipeWriter->waitForWrite(msecs); 535 565 } 536 566 -
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 } -
trunk/src/network/socket/qnativesocketengine_p.h
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 ** … … 53 53 // We mean it. 54 54 // 55 56 55 #include "QtNetwork/qhostaddress.h" 57 56 #include "private/qabstractsocketengine_p.h" 58 57 #ifndef Q_OS_WIN 59 #include "qplatformdefs.h" 58 # include "qplatformdefs.h" 59 #else 60 # include <winsock2.h> 61 #endif 62 63 #ifdef Q_OS_SYMBIAN 64 #include <private/qeventdispatcher_symbian_p.h> 65 #include <unistd.h> 60 66 #endif 61 67 62 68 QT_BEGIN_NAMESPACE 63 69 64 #ifndef Q_OS_WIN 65 // Almost always the same. If not, specify in qplatformdefs.h. 66 #if !defined(QT_SOCKOPTLEN_T) 67 # define QT_SOCKOPTLEN_T QT_SOCKLEN_T 68 #endif 69 70 // Tru64 redefines accept -> _accept with _XOPEN_SOURCE_EXTENDED 71 static inline int qt_socket_accept(int s, struct sockaddr *addr, QT_SOCKLEN_T *addrlen) 72 { return ::accept(s, addr, static_cast<QT_SOCKLEN_T *>(addrlen)); } 73 #if defined(accept) 74 # undef accept 75 #endif 76 77 // UnixWare 7 redefines listen -> _listen 78 static inline int qt_socket_listen(int s, int backlog) 79 { return ::listen(s, backlog); } 80 #if defined(listen) 81 # undef listen 82 #endif 83 84 // UnixWare 7 redefines socket -> _socket 85 static inline int qt_socket_socket(int domain, int type, int protocol) 86 { return ::socket(domain, type, protocol); } 87 #if defined(socket) 88 # undef socket 89 #endif 90 91 #endif 70 // Use our own defines and structs which we know are correct 71 # define QT_SS_MAXSIZE 128 72 # define QT_SS_ALIGNSIZE (sizeof(qint64)) 73 # define QT_SS_PAD1SIZE (QT_SS_ALIGNSIZE - sizeof (short)) 74 # define QT_SS_PAD2SIZE (QT_SS_MAXSIZE - (sizeof (short) + QT_SS_PAD1SIZE + QT_SS_ALIGNSIZE)) 75 struct qt_sockaddr_storage { 76 short ss_family; 77 char __ss_pad1[QT_SS_PAD1SIZE]; 78 qint64 __ss_align; 79 char __ss_pad2[QT_SS_PAD2SIZE]; 80 }; 81 82 // sockaddr_in6 size changed between old and new SDK 83 // Only the new version is the correct one, so always 84 // use this structure. 85 struct qt_in6_addr { 86 quint8 qt_s6_addr[16]; 87 }; 88 struct qt_sockaddr_in6 { 89 short sin6_family; /* AF_INET6 */ 90 quint16 sin6_port; /* Transport level port number */ 91 quint32 sin6_flowinfo; /* IPv6 flow information */ 92 struct qt_in6_addr sin6_addr; /* IPv6 address */ 93 quint32 sin6_scope_id; /* set of interfaces for a scope */ 94 }; 95 96 union qt_sockaddr { 97 sockaddr a; 98 sockaddr_in a4; 99 qt_sockaddr_in6 a6; 100 qt_sockaddr_storage storage; 101 }; 92 102 93 103 class QNativeSocketEnginePrivate; … … 125 135 bool hasPendingDatagrams() const; 126 136 qint64 pendingDatagramSize() const; 137 138 qint64 bytesToWrite() const; 127 139 128 140 qint64 receiveBufferSize() const; -
trunk/src/network/socket/qnativesocketengine_unix.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 ** … … 41 41 42 42 //#define QNATIVESOCKETENGINE_DEBUG 43 44 43 #include "qnativesocketengine_p.h" 44 #include "private/qnet_unix_p.h" 45 45 #include "qiodevice.h" 46 46 #include "qhostaddress.h" … … 63 63 #include <qstring.h> 64 64 #include <ctype.h> 65 #endif 66 67 #ifdef Q_OS_SYMBIAN // ### TODO: Are these headers right? 68 #include <sys/socket.h> 69 #include <netinet/in.h> 70 #else 71 #include <netinet/tcp.h> 65 72 #endif 66 73 … … 101 108 static void qt_ignore_sigpipe() 102 109 { 110 #ifndef Q_NO_POSIX_SIGNALS 103 111 // Set to ignore SIGPIPE once only. 104 112 static QBasicAtomicInt atom = Q_BASIC_ATOMIC_INITIALIZER(0); … … 109 117 ::sigaction(SIGPIPE, &noaction, 0); 110 118 } 119 #else 120 // Posix signals are not supported by the underlying platform 121 // so we don't need to ignore sigpipe signal explicitly 122 #endif 111 123 } 112 124 … … 115 127 \a port and \a addr if they are non-null. 116 128 */ 117 static inline void qt_socket_getPortAndAddress( struct sockaddr *sa, quint16 *port, QHostAddress *addr)129 static inline void qt_socket_getPortAndAddress(const qt_sockaddr *s, quint16 *port, QHostAddress *addr) 118 130 { 119 131 #if !defined(QT_NO_IPV6) 120 if (sa->sa_family == AF_INET6) { 121 struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)sa; 132 if (s->a.sa_family == AF_INET6) { 122 133 Q_IPV6ADDR tmp; 123 memcpy(&tmp, &s a6->sin6_addr.s6_addr, sizeof(tmp));134 memcpy(&tmp, &s->a6.sin6_addr, sizeof(tmp)); 124 135 if (addr) { 125 136 QHostAddress tmpAddress; … … 128 139 #ifndef QT_NO_IPV6IFNAME 129 140 char scopeid[IFNAMSIZ]; 130 if (::if_indextoname(s a6->sin6_scope_id, scopeid) > 0) {141 if (::if_indextoname(s->a6.sin6_scope_id, scopeid)) { 131 142 addr->setScopeId(QLatin1String(scopeid)); 132 143 } else 133 144 #endif 134 addr->setScopeId(QString::number(s a6->sin6_scope_id));145 addr->setScopeId(QString::number(s->a6.sin6_scope_id)); 135 146 } 136 147 if (port) 137 *port = ntohs(s a6->sin6_port);148 *port = ntohs(s->a6.sin6_port); 138 149 return; 139 150 } 140 151 #endif 141 struct sockaddr_in *sa4 = (struct sockaddr_in *)sa;142 152 if (port) 143 *port = ntohs(s a4->sin_port);153 *port = ntohs(s->a4.sin_port); 144 154 if (addr) { 145 155 QHostAddress tmpAddress; 146 tmpAddress.setAddress(ntohl(s a4->sin_addr.s_addr));156 tmpAddress.setAddress(ntohl(s->a4.sin_addr.s_addr)); 147 157 *addr = tmpAddress; 148 158 } … … 164 174 #endif 165 175 int type = (socketType == QAbstractSocket::UdpSocket) ? SOCK_DGRAM : SOCK_STREAM; 166 int socket = qt_socket_socket(protocol, type, 0); 176 #ifdef Q_OS_SYMBIAN 177 int socket = ::socket(protocol, type, 0); 178 #else 179 int socket = qt_safe_socket(protocol, type, 0); 180 #endif 167 181 168 182 if (socket <= 0) { … … 191 205 // Ensure that the socket is closed on exec*(). 192 206 ::fcntl(socket, F_SETFD, FD_CLOEXEC); 207 193 208 socketDescriptor = socket; 194 209 return true; … … 205 220 206 221 int n = -1; 222 int level = SOL_SOCKET; // default 223 207 224 switch (opt) { 208 225 case QNativeSocketEngine::ReceiveBufferSocketOption: … … 224 241 n = SO_OOBINLINE; 225 242 break; 243 case QNativeSocketEngine::LowDelayOption: 244 level = IPPROTO_TCP; 245 n = TCP_NODELAY; 246 break; 247 case QNativeSocketEngine::KeepAliveOption: 248 n = SO_KEEPALIVE; 249 break; 226 250 } 227 251 228 252 int v = -1; 229 253 QT_SOCKOPTLEN_T len = sizeof(v); 230 if ( getsockopt(socketDescriptor, SOL_SOCKET, n, (char *) &v, &len) != -1)254 if (::getsockopt(socketDescriptor, level, n, (char *) &v, &len) != -1) 231 255 return v; 256 232 257 return -1; 233 258 } … … 244 269 245 270 int n = 0; 271 int level = SOL_SOCKET; // default 272 246 273 switch (opt) { 247 274 case QNativeSocketEngine::ReceiveBufferSocketOption: … … 256 283 case QNativeSocketEngine::NonBlockingSocketOption: { 257 284 // Make the socket nonblocking. 285 #if !defined(Q_OS_VXWORKS) 258 286 int flags = ::fcntl(socketDescriptor, F_GETFL, 0); 259 287 if (flags == -1) { … … 269 297 return false; 270 298 } 271 299 #else // Q_OS_VXWORKS 300 int onoff = 1; 301 #ifdef Q_OS_SYMBIAN 302 if (::ioctl(socketDescriptor, FIONBIO, &onoff) < 0) { 303 #else 304 if (qt_safe_ioctl(socketDescriptor, FIONBIO, &onoff) < 0) { 305 #endif 306 #ifdef QNATIVESOCKETENGINE_DEBUG 307 perror("QNativeSocketEnginePrivate::setOption(): ioctl(FIONBIO, 1) failed"); 308 #endif 309 return false; 310 } 311 #endif // Q_OS_VXWORKS 272 312 return true; 273 313 } 274 314 case QNativeSocketEngine::AddressReusable: 275 #if def SO_REUSEPORT315 #if defined(SO_REUSEPORT) && !defined(Q_OS_SYMBIAN) 276 316 n = SO_REUSEPORT; 277 317 #else … … 284 324 n = SO_OOBINLINE; 285 325 break; 286 } 287 288 return ::setsockopt(socketDescriptor, SOL_SOCKET, n, (char *) &v, sizeof(v)) == 0; 326 case QNativeSocketEngine::LowDelayOption: 327 level = IPPROTO_TCP; 328 n = TCP_NODELAY; 329 break; 330 case QNativeSocketEngine::KeepAliveOption: 331 n = SO_KEEPALIVE; 332 break; 333 } 334 335 return ::setsockopt(socketDescriptor, level, n, (char *) &v, sizeof(v)) == 0; 289 336 } 290 337 291 338 bool QNativeSocketEnginePrivate::nativeConnect(const QHostAddress &addr, quint16 port) 292 339 { 340 #ifdef QNATIVESOCKETENGINE_DEBUG 341 qDebug("QNativeSocketEnginePrivate::nativeConnect() : %d ", socketDescriptor); 342 #endif 343 293 344 struct sockaddr_in sockAddrIPv4; 294 345 struct sockaddr *sockAddrPtr = 0; … … 328 379 // unreachable 329 380 } 330 331 int connectResult = QT_SOCKET_CONNECT(socketDescriptor, sockAddrPtr, sockAddrSize); 381 #ifdef Q_OS_SYMBIAN 382 int connectResult = ::connect(socketDescriptor, sockAddrPtr, sockAddrSize); 383 #else 384 int connectResult = qt_safe_connect(socketDescriptor, sockAddrPtr, sockAddrSize); 385 #endif 332 386 if (connectResult == -1) { 333 387 switch (errno) { … … 433 487 434 488 int bindResult = QT_SOCKET_BIND(socketDescriptor, sockAddrPtr, sockAddrSize); 489 435 490 if (bindResult < 0) { 436 491 switch(errno) { … … 469 524 bool QNativeSocketEnginePrivate::nativeListen(int backlog) 470 525 { 471 if (qt_socket_listen(socketDescriptor, backlog) < 0) { 526 #ifdef Q_OS_SYMBIAN 527 if (::listen(socketDescriptor, backlog) < 0) { 528 #else 529 if (qt_safe_listen(socketDescriptor, backlog) < 0) { 530 #endif 472 531 switch (errno) { 473 532 case EADDRINUSE: … … 496 555 int QNativeSocketEnginePrivate::nativeAccept() 497 556 { 498 int acceptedDescriptor = qt_socket_accept(socketDescriptor, 0, 0); 499 #if defined (QNATIVESOCKETENGINE_DEBUG) 500 qDebug("QNativeSocketEnginePrivate::nativeAccept() == %i", acceptedDescriptor); 501 #endif 502 // Ensure that the socket is closed on exec*() 503 ::fcntl(acceptedDescriptor, F_SETFD, FD_CLOEXEC); 557 #ifdef Q_OS_SYMBIAN 558 int acceptedDescriptor = ::accept(socketDescriptor, 0, 0); 559 #else 560 int acceptedDescriptor = qt_safe_accept(socketDescriptor, 0, 0); 561 #endif 562 //check if we have vaild descriptor at all 563 if(acceptedDescriptor > 0) { 564 // Ensure that the socket is closed on exec*() 565 ::fcntl(acceptedDescriptor, F_SETFD, FD_CLOEXEC); 566 } 567 #ifdef Q_OS_SYMBIAN 568 else { 569 qWarning("QNativeSocketEnginePrivate::nativeAccept() - acceptedDescriptor <= 0"); 570 } 571 #endif 572 504 573 return acceptedDescriptor; 505 574 } … … 507 576 qint64 QNativeSocketEnginePrivate::nativeBytesAvailable() const 508 577 { 509 /* 510 Apparently, there is not consistency among different operating 511 systems on how to use FIONREAD. 512 513 FreeBSD, Linux and Solaris all expect the 3rd argument to 514 ioctl() to be an int, which is normally 32-bit even on 64-bit 515 machines. 516 517 IRIX, on the other hand, expects a size_t, which is 64-bit on 518 64-bit machines. 519 520 So, the solution is to use size_t initialized to zero to make 521 sure all bits are set to zero, preventing underflow with the 522 FreeBSD/Linux/Solaris ioctls. 523 */ 524 size_t nbytes = 0; 578 int nbytes = 0; 525 579 // gives shorter than true amounts on Unix domain sockets. 526 580 qint64 available = 0; 527 if (::ioctl(socketDescriptor, FIONREAD, (char *) &nbytes) >= 0) 528 available = (qint64) *((int *) &nbytes); 581 #ifdef Q_OS_SYMBIAN 582 if (::ioctl(socketDescriptor, FIONREAD, (char *) &nbytes) >= 0) 583 #else 584 if (qt_safe_ioctl(socketDescriptor, FIONREAD, (char *) &nbytes) >= 0) 585 #endif 586 available = (qint64) nbytes; 529 587 530 588 #if defined (QNATIVESOCKETENGINE_DEBUG) … … 537 595 { 538 596 // Create a sockaddr struct and reset its port number. 539 #if !defined(QT_NO_IPV6) 540 struct sockaddr_storage storage; 541 sockaddr_in6 *storagePtrIPv6 = reinterpret_cast<sockaddr_in6 *>(&storage); 542 storagePtrIPv6->sin6_port = 0; 543 #else 544 struct sockaddr storage; 545 #endif 546 sockaddr *storagePtr = reinterpret_cast<sockaddr *>(&storage); 547 storagePtr->sa_family = 0; 548 549 sockaddr_in *storagePtrIPv4 = reinterpret_cast<sockaddr_in *>(&storage); 550 storagePtrIPv4->sin_port = 0; 597 qt_sockaddr storage; 551 598 QT_SOCKLEN_T storageSize = sizeof(storage); 599 memset(&storage, 0, storageSize); 552 600 553 601 // Peek 0 bytes into the next message. The size of the message may … … 556 604 do { 557 605 char c; 558 readBytes = ::recvfrom(socketDescriptor, &c, 1, MSG_PEEK, storagePtr, &storageSize);606 readBytes = ::recvfrom(socketDescriptor, &c, 1, MSG_PEEK, &storage.a, &storageSize); 559 607 } while (readBytes == -1 && errno == EINTR); 560 608 … … 570 618 } 571 619 620 #ifdef Q_OS_SYMBIAN 621 qint64 QNativeSocketEnginePrivate::nativePendingDatagramSize() const 622 { 623 size_t nbytes = 0; 624 ::ioctl(socketDescriptor, E32IONREAD, (char *) &nbytes); 625 return qint64(nbytes-28); 626 } 627 #else 572 628 qint64 QNativeSocketEnginePrivate::nativePendingDatagramSize() const 573 629 { 574 630 QVarLengthArray<char, 8192> udpMessagePeekBuffer(8192); 575 631 ssize_t recvResult = -1; 632 576 633 for (;;) { 577 634 // the data written to udpMessagePeekBuffer is discarded, so … … 579 636 // so. 580 637 recvResult = ::recv(socketDescriptor, udpMessagePeekBuffer.data(), 581 638 udpMessagePeekBuffer.size(), MSG_PEEK); 582 639 if (recvResult == -1 && errno == EINTR) 583 640 continue; … … 595 652 return qint64(recvResult); 596 653 } 597 654 #endif 598 655 qint64 QNativeSocketEnginePrivate::nativeReceiveDatagram(char *data, qint64 maxSize, 599 656 QHostAddress *address, quint16 *port) 600 657 { 601 #if !defined(QT_NO_IPV6) 602 struct sockaddr_storage aa; 603 #else 604 struct sockaddr_in aa; 605 #endif 658 qt_sockaddr aa; 606 659 memset(&aa, 0, sizeof(aa)); 607 660 QT_SOCKLEN_T sz; … … 612 665 char c; 613 666 recvFromResult = ::recvfrom(socketDescriptor, maxSize ? data : &c, maxSize ? maxSize : 1, 614 0, (struct sockaddr *)&aa, &sz);667 0, &aa.a, &sz); 615 668 } while (recvFromResult == -1 && errno == EINTR); 616 669 … … 618 671 setError(QAbstractSocket::NetworkError, ReceiveDatagramErrorString); 619 672 } else if (port || address) { 620 qt_socket_getPortAndAddress( (struct sockaddr *)&aa, port, address);673 qt_socket_getPortAndAddress(&aa, port, address); 621 674 } 622 675 … … 641 694 struct sockaddr_in6 sockAddrIPv6; 642 695 if (host.protocol() == QAbstractSocket::IPv6Protocol) { 643 644 645 646 647 648 649 650 696 memset(&sockAddrIPv6, 0, sizeof(sockAddrIPv6)); 697 sockAddrIPv6.sin6_family = AF_INET6; 698 sockAddrIPv6.sin6_port = htons(port); 699 700 Q_IPV6ADDR tmp = host.toIPv6Address(); 701 memcpy(&sockAddrIPv6.sin6_addr.s6_addr, &tmp, sizeof(tmp)); 702 sockAddrSize = sizeof(sockAddrIPv6); 703 sockAddrPtr = (struct sockaddr *)&sockAddrIPv6; 651 704 } else 652 705 #endif 653 706 if (host.protocol() == QAbstractSocket::IPv4Protocol) { 654 655 656 657 658 659 707 memset(&sockAddrIPv4, 0, sizeof(sockAddrIPv4)); 708 sockAddrIPv4.sin_family = AF_INET; 709 sockAddrIPv4.sin_port = htons(port); 710 sockAddrIPv4.sin_addr.s_addr = htonl(host.toIPv4Address()); 711 sockAddrSize = sizeof(sockAddrIPv4); 712 sockAddrPtr = (struct sockaddr *)&sockAddrIPv4; 660 713 } 661 714 662 715 // ignore the SIGPIPE signal 663 716 qt_ignore_sigpipe(); 664 665 ssize_t sentBytes; 666 do { 667 sentBytes = ::sendto(socketDescriptor, data, len, 668 0, sockAddrPtr, sockAddrSize); 669 } while (sentBytes == -1 && errno == EINTR); 717 #ifdef Q_OS_SYMBIAN 718 ssize_t sentBytes = ::sendto(socketDescriptor, data, len, 719 0, sockAddrPtr, sockAddrSize); 720 #else 721 ssize_t sentBytes = qt_safe_sendto(socketDescriptor, data, len, 722 0, sockAddrPtr, sockAddrSize); 723 #endif 670 724 671 725 if (sentBytes < 0) { … … 698 752 return false; 699 753 700 #if !defined(QT_NO_IPV6) 701 struct sockaddr_storage sa; 702 #else 703 struct sockaddr_in sa; 704 #endif 705 struct sockaddr *sockAddrPtr = (struct sockaddr *) &sa; 754 qt_sockaddr sa; 706 755 QT_SOCKLEN_T sockAddrSize = sizeof(sa); 707 756 708 757 // Determine local address 709 758 memset(&sa, 0, sizeof(sa)); 710 if (::getsockname(socketDescriptor, sockAddrPtr, &sockAddrSize) == 0) {711 qt_socket_getPortAndAddress( sockAddrPtr, &localPort, &localAddress);759 if (::getsockname(socketDescriptor, &sa.a, &sockAddrSize) == 0) { 760 qt_socket_getPortAndAddress(&sa, &localPort, &localAddress); 712 761 713 762 // Determine protocol family 714 switch (s ockAddrPtr->sa_family) {763 switch (sa.a.sa_family) { 715 764 case AF_INET: 716 765 socketProtocol = QAbstractSocket::IPv4Protocol; … … 732 781 733 782 // Determine the remote address 734 if (!::getpeername(socketDescriptor, sockAddrPtr, &sockAddrSize))735 qt_socket_getPortAndAddress( sockAddrPtr, &peerPort, &peerAddress);783 if (!::getpeername(socketDescriptor, &sa.a, &sockAddrSize)) 784 qt_socket_getPortAndAddress(&sa, &peerPort, &peerAddress); 736 785 737 786 // Determine the socket type (UDP/TCP) … … 769 818 qDebug("QNativeSocketEngine::nativeClose()"); 770 819 #endif 820 821 #ifdef Q_OS_SYMBIAN 771 822 ::close(socketDescriptor); 823 #else 824 qt_safe_close(socketDescriptor); 825 #endif 772 826 } 773 827 … … 783 837 ssize_t writtenBytes; 784 838 do { 785 writtenBytes = ::write(socketDescriptor, data, len); 839 #ifdef Q_OS_SYMBIAN 840 writtenBytes = ::write(socketDescriptor, data, len); 841 #else 842 writtenBytes = qt_safe_write(socketDescriptor, data, len); 843 #endif 844 // writtenBytes = QT_WRITE(socketDescriptor, data, len); ### TODO S60: Should this line be removed or the one above it? 786 845 } while (writtenBytes < 0 && errno == EINTR); 787 846 … … 825 884 ssize_t r = 0; 826 885 do { 886 #ifdef Q_OS_SYMBIAN 827 887 r = ::read(socketDescriptor, data, maxSize); 888 #else 889 r = qt_safe_read(socketDescriptor, data, maxSize); 890 #endif 828 891 } while (r == -1 && errno == EINTR); 829 892 … … 843 906 setError(QAbstractSocket::NetworkError, ReadErrorString); 844 907 break; 908 #ifdef Q_OS_SYMBIAN 909 case EPIPE: 910 #endif 845 911 case ECONNRESET: 912 #if defined(Q_OS_VXWORKS) 913 case ESHUTDOWN: 914 #endif 846 915 r = 0; 847 916 break; … … 870 939 tv.tv_usec = (timeout % 1000) * 1000; 871 940 872 QTime timer; 873 timer.start(); 941 #ifdef Q_OS_SYMBIAN 942 fd_set fdexception; 943 FD_ZERO(&fdexception); 944 FD_SET(socketDescriptor, &fdexception); 945 #endif 874 946 875 947 int retval; 876 do { 877 if (selectForRead) 878 retval = select(socketDescriptor + 1, &fds, 0, 0, timeout < 0 ? 0 : &tv); 879 else 880 retval = select(socketDescriptor + 1, 0, &fds, 0, timeout < 0 ? 0 : &tv); 881 882 if (retval != -1 || errno != EINTR) 883 break; 884 885 if (timeout > 0) { 886 // recalculate the timeout 887 int t = timeout - timer.elapsed(); 888 if (t < 0) { 889 // oops, timeout turned negative? 890 retval = -1; 891 break; 948 if (selectForRead) 949 #ifdef Q_OS_SYMBIAN 950 retval = ::select(socketDescriptor + 1, &fds, 0, &fdexception, timeout < 0 ? 0 : &tv); 951 #else 952 retval = qt_safe_select(socketDescriptor + 1, &fds, 0, 0, timeout < 0 ? 0 : &tv); 953 #endif 954 else 955 #ifdef Q_OS_SYMBIAN 956 retval = ::select(socketDescriptor + 1, 0, &fds, &fdexception, timeout < 0 ? 0 : &tv); 957 #else 958 retval = qt_safe_select(socketDescriptor + 1, 0, &fds, 0, timeout < 0 ? 0 : &tv); 959 #endif 960 961 962 #ifdef Q_OS_SYMBIAN 963 bool selectForExec = false; 964 if(retval != 0) { 965 if(retval < 0) { 966 qWarning("nativeSelect(....) returned < 0 for socket %d", socketDescriptor); 892 967 } 893 894 tv.tv_sec = t / 1000; 895 tv.tv_usec = (t % 1000) * 1000; 896 } 897 } while (true); 968 selectForExec = FD_ISSET(socketDescriptor, &fdexception); 969 } 970 if(selectForExec) { 971 qWarning("nativeSelect (selectForRead %d, retVal %d, errno %d) Unexpected exception for fd %d", 972 selectForRead, retval, errno, socketDescriptor); 973 } 974 #endif 898 975 899 976 return retval; … … 901 978 902 979 int QNativeSocketEnginePrivate::nativeSelect(int timeout, bool checkRead, bool checkWrite, 903 980 bool *selectForRead, bool *selectForWrite) const 904 981 { 905 982 fd_set fdread; … … 913 990 FD_SET(socketDescriptor, &fdwrite); 914 991 992 #ifdef Q_OS_SYMBIAN 993 fd_set fdexception; 994 FD_ZERO(&fdexception); 995 FD_SET(socketDescriptor, &fdexception); 996 #endif 997 915 998 struct timeval tv; 916 999 tv.tv_sec = timeout / 1000; 917 1000 tv.tv_usec = (timeout % 1000) * 1000; 918 1001 1002 int ret; 1003 #ifndef Q_OS_SYMBIAN 1004 ret = qt_safe_select(socketDescriptor + 1, &fdread, &fdwrite, 0, timeout < 0 ? 0 : &tv); 1005 #else 919 1006 QTime timer; 920 1007 timer.start(); 921 1008 922 int ret;923 1009 do { 924 ret = select(socketDescriptor + 1, &fdread, &fdwrite, 0, timeout < 0 ? 0 : &tv); 925 if (ret != -1 || errno != EINTR) 926 break; 1010 ret = ::select(socketDescriptor + 1, &fdread, &fdwrite, &fdexception, timeout < 0 ? 0 : &tv); 1011 bool selectForExec = false; 1012 if(ret != 0) { 1013 if(ret < 0) { 1014 qWarning("nativeSelect(....) returned < 0 for socket %d", socketDescriptor); 1015 } 1016 selectForExec = FD_ISSET(socketDescriptor, &fdexception); 1017 } 1018 if(selectForExec) { 1019 qWarning("nativeSelect (checkRead %d, checkWrite %d, ret %d, errno %d): Unexpected expectfds ready in fd %d", 1020 checkRead, checkWrite, ret, errno, socketDescriptor); 1021 if (checkWrite){ 1022 FD_CLR(socketDescriptor, &fdread); 1023 FD_SET(socketDescriptor, &fdwrite); 1024 } else if (checkRead) 1025 FD_SET(socketDescriptor, &fdread); 1026 1027 1028 if ((ret == -1) && ( errno == ECONNREFUSED || errno == EPIPE )) 1029 ret = 1; 1030 1031 } 1032 1033 if (ret != -1 || errno != EINTR) { 1034 break; 1035 } 927 1036 928 1037 if (timeout > 0) { … … 939 1048 } 940 1049 } while (true); 1050 #endif 1051 941 1052 if (ret <= 0) 942 1053 return ret; 943 944 1054 *selectForRead = FD_ISSET(socketDescriptor, &fdread); 945 1055 *selectForWrite = FD_ISSET(socketDescriptor, &fdwrite); 1056 946 1057 return ret; 947 1058 } -
trunk/src/network/socket/qnativesocketengine_win.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 ** … … 150 150 #endif 151 151 152 #if !defined (QT_NO_IPV6)153 154 // Use our own defines and structs which we know are correct155 # define QT_SS_MAXSIZE 128156 # define QT_SS_ALIGNSIZE (sizeof(__int64))157 # define QT_SS_PAD1SIZE (QT_SS_ALIGNSIZE - sizeof (short))158 # define QT_SS_PAD2SIZE (QT_SS_MAXSIZE - (sizeof (short) + QT_SS_PAD1SIZE + QT_SS_ALIGNSIZE))159 struct qt_sockaddr_storage {160 short ss_family;161 char __ss_pad1[QT_SS_PAD1SIZE];162 __int64 __ss_align;163 char __ss_pad2[QT_SS_PAD2SIZE];164 };165 166 // sockaddr_in6 size changed between old and new SDK167 // Only the new version is the correct one, so always168 // use this structure.169 struct qt_in6_addr {170 u_char qt_s6_addr[16];171 };172 typedef struct {173 short sin6_family; /* AF_INET6 */174 u_short sin6_port; /* Transport level port number */175 u_long sin6_flowinfo; /* IPv6 flow information */176 struct qt_in6_addr sin6_addr; /* IPv6 address */177 u_long sin6_scope_id; /* set of interfaces for a scope */178 } qt_sockaddr_in6;179 180 #else181 182 typedef void * qt_sockaddr_in6 ;183 184 185 #endif186 187 152 #ifndef AF_INET6 188 153 #define AF_INET6 23 /* Internetwork Version 6 */ … … 202 167 \a port and \a addr if they are non-null. 203 168 */ 204 static inline void qt_socket_getPortAndAddress(SOCKET socketDescriptor, structsockaddr *sa, quint16 *port, QHostAddress *address)169 static inline void qt_socket_getPortAndAddress(SOCKET socketDescriptor, const qt_sockaddr *sa, quint16 *port, QHostAddress *address) 205 170 { 206 171 #if !defined (QT_NO_IPV6) 207 if (sa-> sa_family == AF_INET6) {208 qt_sockaddr_in6 *sa6 = (qt_sockaddr_in6 *)sa;172 if (sa->a.sa_family == AF_INET6) { 173 const qt_sockaddr_in6 *sa6 = &sa->a6; 209 174 Q_IPV6ADDR tmp; 210 175 for (int i = 0; i < 16; ++i) … … 218 183 } else 219 184 #endif 220 if (sa-> sa_family == AF_INET) {221 struct sockaddr_in *sa4 = (struct sockaddr_in *)sa;185 if (sa->a.sa_family == AF_INET) { 186 const sockaddr_in *sa4 = &sa->a4; 222 187 unsigned long addr; 223 188 WSANtohl(socketDescriptor, sa4->sin_addr.s_addr, &addr); … … 398 363 399 364 int n = -1; 365 int level = SOL_SOCKET; // default 366 400 367 switch (opt) { 401 368 case QNativeSocketEngine::ReceiveBufferSocketOption: … … 425 392 n = SO_OOBINLINE; 426 393 break; 394 case QNativeSocketEngine::LowDelayOption: 395 level = IPPROTO_TCP; 396 n = TCP_NODELAY; 397 break; 398 case QNativeSocketEngine::KeepAliveOption: 399 n = SO_KEEPALIVE; 400 break; 427 401 } 428 402 429 403 int v = -1; 430 404 QT_SOCKOPTLEN_T len = sizeof(v); 431 if (getsockopt(socketDescriptor, SOL_SOCKET, n, (char *) &v, &len) != -1)405 if (getsockopt(socketDescriptor, level, n, (char *) &v, &len) != -1) 432 406 return v; 433 407 return -1; … … 445 419 446 420 int n = 0; 421 int level = SOL_SOCKET; // default 422 447 423 switch (opt) { 448 424 case QNativeSocketEngine::ReceiveBufferSocketOption: … … 476 452 n = SO_OOBINLINE; 477 453 break; 478 } 479 480 if (::setsockopt(socketDescriptor, SOL_SOCKET, n, (char*)&v, sizeof(v)) != 0) { 454 case QNativeSocketEngine::LowDelayOption: 455 level = IPPROTO_TCP; 456 n = TCP_NODELAY; 457 break; 458 case QNativeSocketEngine::KeepAliveOption: 459 n = SO_KEEPALIVE; 460 break; 461 } 462 463 if (::setsockopt(socketDescriptor, level, n, (char*)&v, sizeof(v)) != 0) { 481 464 WS_ERROR_DEBUG(WSAGetLastError()); 482 465 return false; … … 499 482 return false; 500 483 501 #if !defined (QT_NO_IPV6) 502 struct qt_sockaddr_storage sa; 503 #else 504 struct sockaddr_in sa; 505 #endif 506 struct sockaddr *pSa = (struct sockaddr *) &sa; 507 508 QT_SOCKLEN_T sz = sizeof(sa); 509 484 qt_sockaddr sa; 485 QT_SOCKLEN_T sockAddrSize = sizeof(sa); 486 487 // Determine local address 510 488 memset(&sa, 0, sizeof(sa)); 511 if (::getsockname(socketDescriptor, pSa, &sz) == 0) {512 qt_socket_getPortAndAddress(socketDescriptor, pSa, &localPort, &localAddress);489 if (::getsockname(socketDescriptor, &sa.a, &sockAddrSize) == 0) { 490 qt_socket_getPortAndAddress(socketDescriptor, &sa, &localPort, &localAddress); 513 491 // Determine protocol family 514 switch ( pSa->sa_family) {492 switch (sa.a.sa_family) { 515 493 case AF_INET: 516 494 socketProtocol = QAbstractSocket::IPv4Protocol; … … 536 514 537 515 memset(&sa, 0, sizeof(sa)); 538 if (::getpeername(socketDescriptor, pSa, &sz) == 0) {539 qt_socket_getPortAndAddress(socketDescriptor, pSa, &peerPort, &peerAddress);516 if (::getpeername(socketDescriptor, &sa.a, &sockAddrSize) == 0) { 517 qt_socket_getPortAndAddress(socketDescriptor, &sa, &peerPort, &peerAddress); 540 518 } else { 541 519 WS_ERROR_DEBUG(WSAGetLastError()); … … 569 547 struct sockaddr_in sockAddrIPv4; 570 548 qt_sockaddr_in6 sockAddrIPv6; 571 struct sockaddr *sockAddrPtr ;572 QT_SOCKLEN_T sockAddrSize ;549 struct sockaddr *sockAddrPtr = 0; 550 QT_SOCKLEN_T sockAddrSize = 0; 573 551 574 552 qt_socket_setPortAndAddress(socketDescriptor, &sockAddrIPv4, &sockAddrIPv6, port, address, &sockAddrPtr, &sockAddrSize); … … 606 584 break; 607 585 } 586 if (value == WSAEHOSTUNREACH) { 587 setError(QAbstractSocket::NetworkError, HostUnreachableErrorString); 588 socketState = QAbstractSocket::UnconnectedState; 589 break; 590 } 608 591 } 609 592 // fall through … … 669 652 struct sockaddr_in sockAddrIPv4; 670 653 qt_sockaddr_in6 sockAddrIPv6; 671 struct sockaddr *sockAddrPtr ;672 QT_SOCKLEN_T sockAddrSize ;654 struct sockaddr *sockAddrPtr = 0; 655 QT_SOCKLEN_T sockAddrSize = 0; 673 656 674 657 qt_socket_setPortAndAddress(socketDescriptor, &sockAddrIPv4, &sockAddrIPv6, port, address, &sockAddrPtr, &sockAddrSize); … … 797 780 #if !defined(Q_OS_WINCE) 798 781 // Create a sockaddr struct and reset its port number. 799 #if !defined(QT_NO_IPV6) 800 qt_sockaddr_in6 storage; 801 qt_sockaddr_in6 *storagePtrIPv6 = reinterpret_cast<qt_sockaddr_in6 *>(&storage); 802 storagePtrIPv6->sin6_port = 0; 803 #else 804 struct sockaddr storage; 805 #endif 806 sockaddr *storagePtr = reinterpret_cast<sockaddr *>(&storage); 807 storagePtr->sa_family = 0; 808 809 sockaddr_in *storagePtrIPv4 = reinterpret_cast<sockaddr_in *>(&storage); 810 storagePtrIPv4->sin_port = 0; 782 qt_sockaddr storage; 811 783 QT_SOCKLEN_T storageSize = sizeof(storage); 812 784 memset(&storage, 0, storageSize); 813 785 814 786 bool result = false; … … 822 794 DWORD available = 0; 823 795 DWORD flags = MSG_PEEK; 824 int ret = ::WSARecvFrom(socketDescriptor, &buf, 1, &available, &flags, storagePtr, &storageSize,0,0);796 int ret = ::WSARecvFrom(socketDescriptor, &buf, 1, &available, &flags, &storage.a, &storageSize,0,0); 825 797 int err = WSAGetLastError(); 826 798 if (ret == SOCKET_ERROR && err != WSAEMSGSIZE) { … … 832 804 flags = 0; 833 805 ::WSARecvFrom(socketDescriptor, &buf, 1, &available, &flags, 834 storagePtr, &storageSize, 0, 0);806 &storage.a, &storageSize, 0, 0); 835 807 } 836 808 } else { … … 924 896 qint64 ret = 0; 925 897 926 #if !defined(QT_NO_IPV6) 927 qt_sockaddr_storage aa; 928 #else 929 struct sockaddr_in aa; 930 #endif 898 qt_sockaddr aa; 931 899 memset(&aa, 0, sizeof(aa)); 932 900 QT_SOCKLEN_T sz; 933 901 sz = sizeof(aa); 902 934 903 WSABUF buf; 935 904 buf.buf = data; … … 946 915 DWORD flags = 0; 947 916 DWORD bytesRead = 0; 948 int wsaRet = ::WSARecvFrom(socketDescriptor, &buf, 1, &bytesRead, &flags, (struct sockaddr *) &aa, &sz,0,0);917 int wsaRet = ::WSARecvFrom(socketDescriptor, &buf, 1, &bytesRead, &flags, &aa.a, &sz,0,0); 949 918 if (wsaRet == SOCKET_ERROR) { 950 919 int err = WSAGetLastError(); 951 920 if (err == WSAEMSGSIZE) { 952 921 // it is ok the buffer was to small if bytesRead is larger than 953 // maxLength (win 9x)then assume bytes read is really maxLenth922 // maxLength then assume bytes read is really maxLenth 954 923 ret = qint64(bytesRead) > maxLength ? maxLength : qint64(bytesRead); 955 924 } else { … … 962 931 } 963 932 964 qt_socket_getPortAndAddress(socketDescriptor, (struct sockaddr *)&aa, port, address);933 qt_socket_getPortAndAddress(socketDescriptor, &aa, port, address); 965 934 966 935 #if defined (QNATIVESOCKETENGINE_DEBUG) … … 981 950 struct sockaddr_in sockAddrIPv4; 982 951 qt_sockaddr_in6 sockAddrIPv6; 983 struct sockaddr *sockAddrPtr ;984 QT_SOCKLEN_T sockAddrSize ;952 struct sockaddr *sockAddrPtr = 0; 953 QT_SOCKLEN_T sockAddrSize = 0; 985 954 986 955 qt_socket_setPortAndAddress(socketDescriptor, &sockAddrIPv4, &sockAddrIPv6, port, address, &sockAddrPtr, &sockAddrSize); 987 956 988 if (QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based && len > qint64(qt_socket_getMaxMsgSize(socketDescriptor))) { 989 // WSAEMSGSIZE is not reliable enough (win 9x) so we check max size our self. 990 setError(QAbstractSocket::DatagramTooLargeError, DatagramTooLargeErrorString); 957 WSABUF buf; 958 #if !defined(Q_OS_WINCE) 959 buf.buf = len ? (char*)data : 0; 960 #else 961 char tmp; 962 buf.buf = len ? (char*)data : &tmp; 963 #endif 964 buf.len = len; 965 DWORD flags = 0; 966 DWORD bytesSent = 0; 967 if (::WSASendTo(socketDescriptor, &buf, 1, &bytesSent, flags, sockAddrPtr, sockAddrSize, 0,0) == SOCKET_ERROR) { 968 int err = WSAGetLastError(); 969 WS_ERROR_DEBUG(err); 970 switch (err) { 971 case WSAEMSGSIZE: 972 setError(QAbstractSocket::DatagramTooLargeError, DatagramTooLargeErrorString); 973 break; 974 default: 975 setError(QAbstractSocket::NetworkError, SendDatagramErrorString); 976 break; 977 } 978 ret = -1; 991 979 } else { 992 WSABUF buf; 993 #if !defined(Q_OS_WINCE) 994 buf.buf = len ? (char*)data : 0; 995 #else 996 char tmp; 997 buf.buf = len ? (char*)data : &tmp; 998 #endif 999 buf.len = len; 1000 DWORD flags = 0; 1001 DWORD bytesSent = 0; 1002 if (::WSASendTo(socketDescriptor, &buf, 1, &bytesSent, flags, sockAddrPtr, sockAddrSize, 0,0) == SOCKET_ERROR) { 1003 int err = WSAGetLastError(); 1004 WS_ERROR_DEBUG(err); 1005 switch (err) { 1006 case WSAEMSGSIZE: 1007 setError(QAbstractSocket::DatagramTooLargeError, DatagramTooLargeErrorString); 1008 break; 1009 default: 1010 setError(QAbstractSocket::NetworkError, SendDatagramErrorString); 1011 break; 1012 } 1013 ret = -1; 1014 } else { 1015 ret = qint64(bytesSent); 1016 } 1017 } 980 ret = qint64(bytesSent); 981 } 982 1018 983 #if defined (QNATIVESOCKETENGINE_DEBUG) 1019 984 qDebug("QNativeSocketEnginePrivate::nativeSendDatagram(%p \"%s\", %li, \"%s\", %i) == %li", data, … … 1143 1108 tv.tv_usec = (timeout % 1000) * 1000; 1144 1109 1145 if (selectForRead) 1110 if (selectForRead) { 1146 1111 ret = select(0, &fds, 0, 0, timeout < 0 ? 0 : &tv); 1147 else 1148 ret = select(0, 0, &fds, 0, timeout < 0 ? 0 : &tv); 1112 } else { 1113 // select for write 1114 1115 // Windows needs this to report errors when connecting a socket ... 1116 fd_set fdexception; 1117 FD_ZERO(&fdexception); 1118 FD_SET(socketDescriptor, &fdexception); 1119 1120 ret = select(0, 0, &fds, &fdexception, timeout < 0 ? 0 : &tv); 1121 1122 // ... but if it is actually set, pretend it did not happen 1123 if (ret > 0 && FD_ISSET(socketDescriptor, &fdexception)) 1124 ret--; 1125 } 1149 1126 1150 1127 if (readEnabled) … … 1161 1138 if (readEnabled) 1162 1139 readNotifier->setEnabled(false); 1163 1140 1164 1141 fd_set fdread; 1165 1142 fd_set fdwrite; 1143 fd_set fdexception; 1166 1144 1167 1145 int ret = 0; … … 1173 1151 } 1174 1152 memset(&fdwrite, 0, sizeof(fd_set)); 1153 FD_ZERO(&fdexception); 1175 1154 if (checkWrite) { 1176 1155 fdwrite.fd_count = 1; 1177 1156 fdwrite.fd_array[0] = socketDescriptor; 1157 1158 // Windows needs this to report errors when connecting a socket 1159 FD_SET(socketDescriptor, &fdexception); 1178 1160 } 1179 1161 … … 1183 1165 1184 1166 #if !defined(Q_OS_WINCE) 1185 ret = select(socketDescriptor + 1, &fdread, &fdwrite, 0, timeout < 0 ? 0 : &tv);1167 ret = select(socketDescriptor + 1, &fdread, &fdwrite, &fdexception, timeout < 0 ? 0 : &tv); 1186 1168 #else 1187 ret = select(1, &fdread, &fdwrite, 0, timeout < 0 ? 0 : &tv); 1188 #endif 1169 ret = select(1, &fdread, &fdwrite, &fdexception, timeout < 0 ? 0 : &tv); 1170 #endif 1171 1172 //... but if it is actually set, pretend it did not happen 1173 if (ret > 0 && FD_ISSET(socketDescriptor, &fdexception)) 1174 ret--; 1175 1189 1176 if (readEnabled) 1190 1177 readNotifier->setEnabled(true); -
trunk/src/network/socket/qsocks5socketengine.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 ** … … 60 60 QT_BEGIN_NAMESPACE 61 61 62 #ifdef Q_OS_SYMBIAN 63 static const int MaxWriteBufferSize = 4*1024; 64 #else 62 65 static const int MaxWriteBufferSize = 128*1024; 66 #endif 63 67 64 68 //#define QSOCKS5SOCKETLAYER_DEBUG … … 154 158 static bool qt_socks5_set_host_address_and_port(const QHostAddress &address, quint16 port, QByteArray *pBuf) 155 159 { 156 QSOCKS5_DEBUG << "setting [" << address << ":" << port << "]";160 QSOCKS5_DEBUG << "setting [" << address << ':' << port << ']'; 157 161 158 162 union { … … 187 191 static bool qt_socks5_set_host_name_and_port(const QString &hostname, quint16 port, QByteArray *pBuf) 188 192 { 189 QSOCKS5_DEBUG << "setting [" << hostname << ":" << port << "]";193 QSOCKS5_DEBUG << "setting [" << hostname << ':' << port << ']'; 190 194 191 195 QByteArray encodedHostName = QUrl::toAce(hostname); … … 266 270 267 271 if (ret) { 268 QSOCKS5_DEBUG << "got [" << address << ":" << port << "]";272 QSOCKS5_DEBUG << "got [" << address << ':' << port << ']'; 269 273 *pAddress = address; 270 274 *pPort = port; … … 1125 1129 { 1126 1130 Q_D(QSocks5SocketEngine); 1127 QSOCKS5_DEBUG << "connectToHost" << address << ":"<< port;1131 QSOCKS5_DEBUG << "connectToHost" << address << ':' << port; 1128 1132 1129 1133 setPeerAddress(address); … … 1232 1236 connectData->readBuffer.clear(); 1233 1237 emitReadNotification(); 1238 data->controlSocket->close(); 1239 // cause a disconnect in the outer socket 1240 emitWriteNotification(); 1234 1241 } else if (socks5State == Uninitialized 1235 1242 || socks5State == AuthenticationMethodsSent … … 1242 1249 q_func()->setError(data->controlSocket->error(), data->controlSocket->errorString()); 1243 1250 emitReadNotification(); 1251 emitWriteNotification(); 1244 1252 } 1245 1253 } … … 1380 1388 return false; 1381 1389 } 1382 QSOCKS5_DEBUG << "udp actual address and port" << d->localAddress << ":"<< d->localPort;1390 QSOCKS5_DEBUG << "udp actual address and port" << d->localAddress << ':' << d->localPort; 1383 1391 return true; 1384 1392 #endif // QT_NO_UDPSOCKET … … 1479 1487 { 1480 1488 Q_D(QSocks5SocketEngine); 1481 QSOCKS5_Q_DEBUG << "read( , maxlen = " << maxlen << ")";1489 QSOCKS5_Q_DEBUG << "read( , maxlen = " << maxlen << ')'; 1482 1490 if (d->mode == QSocks5SocketEnginePrivate::ConnectMode) { 1483 1491 if (d->connectData->readBuffer.size() == 0) { … … 1620 1628 #endif // QT_NO_UDPSOCKET 1621 1629 1630 qint64 QSocks5SocketEngine::bytesToWrite() const 1631 { 1632 Q_D(const QSocks5SocketEngine); 1633 if (d->data && d->data->controlSocket) { 1634 return d->data->controlSocket->bytesToWrite(); 1635 } else { 1636 return 0; 1637 } 1638 } 1639 1622 1640 int QSocks5SocketEngine::option(SocketOption option) const 1623 1641 { 1624 Q_UNUSED(option); 1642 Q_D(const QSocks5SocketEngine); 1643 if (d->data && d->data->controlSocket) { 1644 // convert the enum and call the real socket 1645 if (option == QAbstractSocketEngine::LowDelayOption) 1646 return d->data->controlSocket->socketOption(QAbstractSocket::LowDelayOption).toInt(); 1647 if (option == QAbstractSocketEngine::KeepAliveOption) 1648 return d->data->controlSocket->socketOption(QAbstractSocket::KeepAliveOption).toInt(); 1649 } 1625 1650 return -1; 1626 1651 } … … 1628 1653 bool QSocks5SocketEngine::setOption(SocketOption option, int value) 1629 1654 { 1630 Q_UNUSED(option); 1631 Q_UNUSED(value); 1655 Q_D(QSocks5SocketEngine); 1656 if (d->data && d->data->controlSocket) { 1657 // convert the enum and call the real socket 1658 if (option == QAbstractSocketEngine::LowDelayOption) 1659 d->data->controlSocket->setSocketOption(QAbstractSocket::LowDelayOption, value); 1660 if (option == QAbstractSocketEngine::KeepAliveOption) 1661 d->data->controlSocket->setSocketOption(QAbstractSocket::KeepAliveOption, value); 1662 return true; 1663 } 1632 1664 return false; 1633 1665 } … … 1767 1799 Q_D(QSocks5SocketEngine); 1768 1800 1769 QSOCKS5_Q_DEBUG << "setReadNotificationEnabled(" << enable << ")";1801 QSOCKS5_Q_DEBUG << "setReadNotificationEnabled(" << enable << ')'; 1770 1802 1771 1803 bool emitSignal = false; … … 1831 1863 return 0; 1832 1864 } 1833 QS ocks5SocketEngine *engine = new QSocks5SocketEngine(parent);1865 QScopedPointer<QSocks5SocketEngine> engine(new QSocks5SocketEngine(parent)); 1834 1866 engine->setProxy(proxy); 1835 return engine ;1867 return engine.take(); 1836 1868 } 1837 1869 -
trunk/src/network/socket/qsocks5socketengine_p.h
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 ** … … 100 100 qint64 pendingDatagramSize() const; 101 101 #endif // QT_NO_UDPSOCKET 102 103 qint64 bytesToWrite() const; 102 104 103 105 int option(SocketOption option) const; -
trunk/src/network/socket/qtcpserver.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 ** … … 47 47 48 48 \reentrant 49 \ingroup io49 \ingroup network 50 50 \inmodule QtNetwork 51 51 … … 355 355 if (d->socketEngine) { 356 356 d->socketEngine->close(); 357 d->socketEngine->deleteLater(); 357 QT_TRY { 358 d->socketEngine->deleteLater(); 359 } QT_CATCH(const std::bad_alloc &) { 360 // in out of memory situations, the socketEngine 361 // will be deleted in ~QTcpServer (it's a child-object of this) 362 } 358 363 d->socketEngine = 0; 359 364 } -
trunk/src/network/socket/qtcpserver.h
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 ** -
trunk/src/network/socket/qtcpsocket.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 … … 61 61 \bold{Note:} TCP sockets cannot be opened in QIODevice::Unbuffered mode. 62 62 63 \sa QTcpServer, QUdpSocket, QFtp, Q Http, {Fortune Server Example},64 {Fortune Client Example}, {Threaded Fortune ServerExample},65 {Blocking Fortune Client Example}, {LoopbackExample},66 63 \sa QTcpServer, QUdpSocket, QFtp, QNetworkAccessManager, 64 {Fortune Server Example}, {Fortune Client Example}, 65 {Threaded Fortune Server Example}, {Blocking Fortune Client Example}, 66 {Loopback Example}, {Torrent Example} 67 67 */ 68 68 -
trunk/src/network/socket/qtcpsocket.h
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 ** … … 44 44 45 45 #include <QtNetwork/qabstractsocket.h> 46 #include <QtCore/qvariant.h> 46 47 47 48 QT_BEGIN_HEADER -
trunk/src/network/socket/qtcpsocket_p.h
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 ** -
trunk/src/network/socket/qudpsocket.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 ** … … 47 47 \brief The QUdpSocket class provides a UDP socket. 48 48 49 \ingroup io49 \ingroup network 50 50 \inmodule QtNetwork 51 51 … … 71 71 datagram, and readDatagram() to read it. 72 72 73 \note An incoming datagram should be read when you receive the readyRead() 74 signal, otherwise this signal will not be emitted for the next datagram. 75 73 76 Example: 74 77 … … 92 95 This enum describes the different flags you can pass to modify the 93 96 behavior of QUdpSocket::bind(). 97 98 \note On Symbian OS bind flags behaviour depends on process capabilties. 99 If process has NetworkControl capability, the bind attempt with 100 ReuseAddressHint will always succeed even if the address and port is already 101 bound by another socket with any flags. If process does not have 102 NetworkControl capability, the bind attempt to address and port already 103 bound by another socket will always fail. 94 104 95 105 \value ShareAddress Allow other services to bind to the same address … … 348 358 destination. 349 359 360 \warning In S60 5.0 and earlier versions, the writeDatagram return 361 value is not reliable for large datagrams. 362 350 363 \warning Calling this function on a connected UDP socket may 351 364 result in an error and no packet being sent. If you are using a … … 366 379 367 380 qint64 sent = d->socketEngine->writeDatagram(data, size, address, port); 381 #ifdef Q_OS_SYMBIAN 382 if( QSysInfo::s60Version() <= QSysInfo::SV_S60_5_0 ) { 383 // This is evil hack, but for some reason native RSocket::SendTo returns 0, 384 // for large datagrams (such as 600 bytes). Based on comments from Open C team 385 // this should happen only in platforms <= S60 5.0. 386 // As an workaround, we just set sent = size 387 if( sent == 0 ) 388 sent = size; 389 } 390 #endif 368 391 d->cachedSocketDescriptor = d->socketEngine->socketDescriptor(); 369 392 … … 378 401 } 379 402 380 /*! 403 /*! 381 404 \fn qint64 QUdpSocket::writeDatagram(const QByteArray &datagram, 382 405 const QHostAddress &host, quint16 port) -
trunk/src/network/socket/qudpsocket.h
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 ** -
trunk/src/network/socket/socket.pri
r157 r561 29 29 socket/qlocalsocket_unix.cpp \ 30 30 socket/qlocalserver_unix.cpp 31 31 unix:HEADERS += \ 32 socket/qnet_unix_p.h 32 33 33 34 win32:SOURCES += socket/qnativesocketengine_win.cpp \ … … 47 48 DEFINES += QT_LOCALSOCKET_TCP 48 49 } 49 50
Note:
See TracChangeset
for help on using the changeset viewer.