Changeset 769 for trunk/src/network/socket
- Timestamp:
- Aug 2, 2010, 9:27:30 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.6.3 (added) merged: 768 /branches/vendor/nokia/qt/current merged: 767 /branches/vendor/nokia/qt/4.6.2 removed
- Property svn:mergeinfo changed
-
trunk/src/network/socket/qabstractsocket.cpp
r651 r769 156 156 examples for an overview of both approaches. 157 157 158 \note We discourage the use of the blocking functions together 159 with signals. One of the two possibilities should be used. 160 158 161 QAbstractSocket can be used with QTextStream and QDataStream's 159 162 stream operators (operator<<() and operator>>()). There is one … … 170 173 the host lookup has succeeded. 171 174 175 \note Since Qt 4.6.3 QAbstractSocket may emit hostFound() 176 directly from the connectToHost() call since a DNS result could have been 177 cached. 178 172 179 \sa connected() 173 180 */ … … 178 185 This signal is emitted after connectToHost() has been called and 179 186 a connection has been successfully established. 187 188 \note On some operating systems the connected() signal may 189 be directly emitted from the connectToHost() call for connections 190 to the localhost. 180 191 181 192 \sa connectToHost(), disconnected() … … 352 363 #include "qabstractsocket_p.h" 353 364 365 #include "private/qhostinfo_p.h" 366 354 367 #include <qabstracteventdispatcher.h> 355 368 #include <qdatetime.h> … … 1367 1380 #endif 1368 1381 } else { 1369 if (d->threadData->eventDispatcher) 1370 d->hostLookupId = QHostInfo::lookupHost(hostName, this, SLOT(_q_startConnecting(QHostInfo))); 1382 if (d->threadData->eventDispatcher) { 1383 // this internal API for QHostInfo either immediatly gives us the desired 1384 // QHostInfo from cache or later calls the _q_startConnecting slot. 1385 bool immediateResultValid = false; 1386 QHostInfo hostInfo = qt_qhostinfo_lookup(hostName, 1387 this, 1388 SLOT(_q_startConnecting(QHostInfo)), 1389 &immediateResultValid, 1390 &d->hostLookupId); 1391 if (immediateResultValid) { 1392 d->hostLookupId = -1; 1393 d->_q_startConnecting(hostInfo); 1394 } 1395 } 1371 1396 } 1372 1397 … … 1683 1708 If msecs is -1, this function will not time out. 1684 1709 1685 Note:This function may wait slightly longer than \a msecs,1710 \note This function may wait slightly longer than \a msecs, 1686 1711 depending on the time it takes to complete the host lookup. 1712 1713 \note Multiple calls to this functions do not accumulate the time. 1714 If the function times out, the connecting process will be aborted. 1687 1715 1688 1716 \sa connectToHost(), connected() … … 1723 1751 } 1724 1752 if (state() == UnconnectedState) 1725 return false; 1753 return false; // connect not im progress anymore! 1726 1754 1727 1755 bool timedOut = true; … … 2355 2383 qDebug("QAbstractSocket::disconnectFromHost() aborting immediately"); 2356 2384 #endif 2385 if (d->state == HostLookupState) { 2386 QHostInfo::abortHostLookup(d->hostLookupId); 2387 d->hostLookupId = -1; 2388 } 2357 2389 } else { 2358 2390 // Perhaps emit closing() -
trunk/src/network/socket/qlocalserver.cpp
r755 r769 123 123 d->pendingConnections.clear(); 124 124 d->closeServer(); 125 d->serverName = QString();126 d->fullServerName = QString();127 d->errorString = QString();125 d->serverName.clear(); 126 d->fullServerName.clear(); 127 d->errorString.clear(); 128 128 d->error = QAbstractSocket::UnknownSocketError; 129 129 } … … 229 229 230 230 if (!d->listen(name)) { 231 d->serverName = QString();232 d->fullServerName = QString();231 d->serverName.clear(); 232 d->fullServerName.clear(); 233 233 return false; 234 234 } -
trunk/src/network/socket/qlocalserver_win.cpp
r651 r769 168 168 } else { 169 169 if (GetLastError() != ERROR_IO_INCOMPLETE) { 170 q->close(); 170 171 setError(QLatin1String("QLocalServerPrivate::_q_onNewConnection")); 171 closeServer();172 172 return; 173 173 } -
trunk/src/network/socket/qlocalsocket_p.h
r651 r769 129 129 void _q_error(QAbstractSocket::SocketError newError); 130 130 #elif defined(Q_OS_WIN) 131 ~QLocalSocketPrivate() { 132 CloseHandle(overlapped.hEvent); 133 } 134 131 ~QLocalSocketPrivate(); 132 void destroyPipeHandles(); 135 133 void setErrorString(const QString &function); 136 134 void _q_notified(); -
trunk/src/network/socket/qlocalsocket_tcp.cpp
r651 r769 103 103 case QAbstractSocket::UnconnectedState: 104 104 state = QLocalSocket::UnconnectedState; 105 serverName = QString();106 fullServerName = QString();105 serverName.clear(); 106 fullServerName.clear(); 107 107 break; 108 108 case QAbstractSocket::ConnectingState: … … 219 219 return; 220 220 221 d->errorString = QString();221 d->errorString.clear(); 222 222 d->state = ConnectingState; 223 223 emit stateChanged(d->state); … … 334 334 Q_D(QLocalSocket); 335 335 d->tcpSocket->close(); 336 d->serverName = QString();337 d->fullServerName = QString();336 d->serverName.clear(); 337 d->fullServerName.clear(); 338 338 QIODevice::close(); 339 339 } -
trunk/src/network/socket/qlocalsocket_unix.cpp
r651 r769 110 110 case QAbstractSocket::UnconnectedState: 111 111 state = QLocalSocket::UnconnectedState; 112 serverName = QString();113 fullServerName = QString();112 serverName.clear(); 113 fullServerName.clear(); 114 114 break; 115 115 case QAbstractSocket::ConnectingState: … … 226 226 return; 227 227 228 d->errorString = QString();228 d->errorString.clear(); 229 229 d->unixSocket.setSocketState(QAbstractSocket::ConnectingState); 230 230 d->state = ConnectingState; … … 342 342 } 343 343 connectingSocket = -1; 344 connectingName = QString();344 connectingName.clear(); 345 345 connectingOpenMode = 0; 346 346 } … … 439 439 ::close(d->connectingSocket); 440 440 d->connectingSocket = -1; 441 d->connectingName = QString();441 d->connectingName.clear(); 442 442 d->connectingOpenMode = 0; 443 d->serverName = QString();444 d->fullServerName = QString();443 d->serverName.clear(); 444 d->fullServerName.clear(); 445 445 QIODevice::close(); 446 446 } -
trunk/src/network/socket/qlocalsocket_win.cpp
r651 r769 40 40 ****************************************************************************/ 41 41 42 #include "qlocalsocket.h"43 42 #include "qlocalsocket_p.h" 44 43 … … 109 108 state(QLocalSocket::UnconnectedState) 110 109 { 110 } 111 112 QLocalSocketPrivate::~QLocalSocketPrivate() 113 { 114 destroyPipeHandles(); 115 CloseHandle(overlapped.hEvent); 116 } 117 118 void QLocalSocketPrivate::destroyPipeHandles() 119 { 120 if (handle != INVALID_HANDLE_VALUE) { 121 DisconnectNamedPipe(handle); 122 CloseHandle(handle); 123 } 111 124 } 112 125 … … 389 402 d->pendingReadyRead = false; 390 403 d->pipeClosed = false; 391 DisconnectNamedPipe(d->handle); 392 CloseHandle(d->handle); 404 d->destroyPipeHandles(); 393 405 d->handle = INVALID_HANDLE_VALUE; 394 406 ResetEvent(d->overlapped.hEvent); … … 413 425 { 414 426 Q_D(QLocalSocket); 427 428 // Are we still connected? 429 if (!isValid()) { 430 // If we have unwritten data, the pipeWriter is still present. 431 // It must be destroyed before close() to prevent an infinite loop. 432 delete d->pipeWriter; 433 d->pipeWriter = 0; 434 } 435 415 436 flush(); 416 437 if (d->pipeWriter && d->pipeWriter->bytesToWrite() != 0) { … … 525 546 { 526 547 Q_D(const QLocalSocket); 527 return (d->handle != INVALID_HANDLE_VALUE); 548 if (d->handle == INVALID_HANDLE_VALUE) 549 return false; 550 551 return PeekNamedPipe(d->handle, NULL, 0, NULL, NULL, NULL); 528 552 } 529 553 -
trunk/src/network/socket/qnativesocketengine.cpp
r651 r769 780 780 return -1; 781 781 } else if (readBytes == -1) { 782 d->setError(QAbstractSocket::NetworkError, 783 QNativeSocketEnginePrivate::ReadErrorString); 782 if (!d->hasSetSocketError) { 783 d->hasSetSocketError = true; 784 d->socketError = QAbstractSocket::NetworkError; 785 d->socketErrorString = qt_error_string(); 786 } 784 787 close(); 785 788 return -1; -
trunk/src/network/socket/qnativesocketengine_unix.cpp
r651 r769 602 602 // well be 0, so we can't check recvfrom's return value. 603 603 ssize_t readBytes; 604 #ifdef Q_OS_SYMBIAN 605 char c; 606 readBytes = ::recvfrom(socketDescriptor, &c, 1, MSG_PEEK, &storage.a, &storageSize); 607 #else 604 608 do { 605 609 char c; 606 610 readBytes = ::recvfrom(socketDescriptor, &c, 1, MSG_PEEK, &storage.a, &storageSize); 607 611 } while (readBytes == -1 && errno == EINTR); 612 #endif 608 613 609 614 // If there's no error, or if our buffer was too small, there must be a … … 662 667 663 668 ssize_t recvFromResult = 0; 669 #ifdef Q_OS_SYMBIAN 670 char c; 671 recvFromResult = ::recvfrom(socketDescriptor, maxSize ? data : &c, maxSize ? maxSize : 1, 672 0, &aa.a, &sz); 673 #else 664 674 do { 665 675 char c; … … 667 677 0, &aa.a, &sz); 668 678 } while (recvFromResult == -1 && errno == EINTR); 679 #endif 669 680 670 681 if (recvFromResult == -1) { … … 833 844 qt_ignore_sigpipe(); 834 845 835 // loop while ::write() returns -1 and errno == EINTR, in case836 // of an interrupting signal.837 846 ssize_t writtenBytes; 838 do { 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? 845 } while (writtenBytes < 0 && errno == EINTR); 847 #ifdef Q_OS_SYMBIAN 848 // Symbian does not support signals natively and Open C returns EINTR when moving to offline 849 writtenBytes = ::write(socketDescriptor, data, len); 850 #else 851 writtenBytes = qt_safe_write(socketDescriptor, data, len); 852 #endif 846 853 847 854 if (writtenBytes < 0) { … … 883 890 884 891 ssize_t r = 0; 885 do { 886 #ifdef Q_OS_SYMBIAN 887 r = ::read(socketDescriptor, data, maxSize); 888 #else 889 r = qt_safe_read(socketDescriptor, data, maxSize); 890 #endif 891 } while (r == -1 && errno == EINTR); 892 #ifdef Q_OS_SYMBIAN 893 r = ::read(socketDescriptor, data, maxSize); 894 #else 895 r = qt_safe_read(socketDescriptor, data, maxSize); 896 #endif 892 897 893 898 if (r < 0) { … … 904 909 case EINVAL: 905 910 case EIO: 906 setError(QAbstractSocket::NetworkError, ReadErrorString);911 //error string is now set in read(), not here in nativeRead() 907 912 break; 908 913 #ifdef Q_OS_SYMBIAN -
trunk/src/network/socket/qnativesocketengine_win.cpp
r651 r769 1069 1069 case WSAEBADF: 1070 1070 case WSAEINVAL: 1071 setError(QAbstractSocket::NetworkError, ReadErrorString);1071 //error string is now set in read(), not here in nativeRead() 1072 1072 break; 1073 1073 case WSAECONNRESET: -
trunk/src/network/socket/qtcpserver.cpp
r651 r769 79 79 use waitForNewConnection(), which blocks until either a 80 80 connection is available or a timeout expires. 81 82 \section1 Symbian Platform Security Requirements 83 84 On Symbian, processes which use this class must have the 85 \c NetworkServices platform security capability. If the client 86 process lacks this capability, it will lead to a panic. 87 88 Platform security capabilities are added via the 89 \l{qmake-variable-reference.html#target-capability}{TARGET.CAPABILITY} 90 qmake variable. 81 91 82 92 \sa QTcpSocket, {Fortune Server Example}, {Threaded Fortune Server Example}, … … 514 524 connections. 515 525 526 \note The returned QTcpSocket object cannot be used from another 527 thread. If you want to use an incoming connection from another thread, 528 you need to override incomingConnection(). 529 516 530 \sa hasPendingConnections() 517 531 */ … … 543 557 may not be usable with native socket functions, and should only be 544 558 used with QTcpSocket::setSocketDescriptor(). 559 560 \note If you want to handle an incoming connection as a new QTcpSocket 561 object in another thread you have to pass the socketDescriptor 562 to the other thread and create the QTcpSocket object there and 563 use its setSocketDescriptor() method. 545 564 546 565 \sa newConnection(), nextPendingConnection() -
trunk/src/network/socket/qtcpsocket.cpp
r651 r769 61 61 \bold{Note:} TCP sockets cannot be opened in QIODevice::Unbuffered mode. 62 62 63 \section1 Symbian Platform Security Requirements 64 65 On Symbian, processes which use this class must have the 66 \c NetworkServices platform security capability. If the client 67 process lacks this capability, it will result in a panic. 68 69 Platform security capabilities are added via the 70 \l{qmake-variable-reference.html#target-capability}{TARGET.CAPABILITY} 71 qmake variable. 72 63 73 \sa QTcpServer, QUdpSocket, QFtp, QNetworkAccessManager, 64 74 {Fortune Server Example}, {Fortune Client Example}, -
trunk/src/network/socket/qudpsocket.cpp
r651 r769 86 86 \l{network/broadcastreceiver}{Broadcast Receiver} examples 87 87 illustrate how to use QUdpSocket in applications. 88 89 \section1 Symbian Platform Security Requirements 90 91 On Symbian, processes which use this class must have the 92 \c NetworkServices platform security capability. If the client 93 process lacks this capability, operations will result in a panic. 94 95 Platform security capabilities are added via the 96 \l{qmake-variable-reference.html#target-capability}{TARGET.CAPABILITY} 97 qmake variable. 88 98 89 99 \sa QTcpSocket
Note:
See TracChangeset
for help on using the changeset viewer.