diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2014-12-23 13:37:01 -0200 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2015-03-04 23:58:03 +0000 |
commit | 9fb68a90af79df3b8dc3225a3a97e2c6387afeec (patch) | |
tree | b51f4ca6effbcf2da792595837a92198a2181f01 /src/network/socket/qnativesocketengine.cpp | |
parent | 29051bce39d24a6e33155feeec2833b79b55ff16 (diff) |
Fix bind+connect in both TCP and UDP
This has been known to be broken for a while. Now it works: you can bind
and you'll retain the port (and the file descriptor) for the connect
call. Incidentally, in fixing the binding for more than one IP for the
hostname (with event loop), this commit fixes the setSocketDescriptor
XFAIL.
[ChangeLog][QtNetwork] Fixed a bug that caused both QTcpSocket and
QUdpSocket to close the socket and lose any bound ports before
connecting. Now bind()/setSocketDescriptor() followed by connect() will
retain the original file descriptor.
Task-number: QTBUG-26538
Change-Id: I691caed7e8fd16a9cf687b5995afbf3006bf453a
Reviewed-by: Richard J. Moore <rich@kde.org>
Diffstat (limited to 'src/network/socket/qnativesocketengine.cpp')
-rw-r--r-- | src/network/socket/qnativesocketengine.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/network/socket/qnativesocketengine.cpp b/src/network/socket/qnativesocketengine.cpp index db6c7c487a..fcfef87e3c 100644 --- a/src/network/socket/qnativesocketengine.cpp +++ b/src/network/socket/qnativesocketengine.cpp @@ -136,6 +136,12 @@ QT_BEGIN_NAMESPACE " not in "#state1" or "#state2); \ return (returnValue); \ } } while (0) +#define Q_CHECK_STATES3(function, state1, state2, state3, returnValue) do { \ + if (d->socketState != (state1) && d->socketState != (state2) && d->socketState != (state3)) { \ + qWarning(""#function" was called" \ + " not in "#state1" or "#state2); \ + return (returnValue); \ + } } while (0) #define Q_CHECK_TYPE(function, type, returnValue) do { \ if (d->socketType != (type)) { \ qWarning(#function" was called by a" \ @@ -495,7 +501,7 @@ bool QNativeSocketEngine::connectToHost(const QHostAddress &address, quint16 por if (!d->checkProxy(address)) return false; - Q_CHECK_STATES(QNativeSocketEngine::connectToHost(), + Q_CHECK_STATES3(QNativeSocketEngine::connectToHost(), QAbstractSocket::BoundState, QAbstractSocket::UnconnectedState, QAbstractSocket::ConnectingState, false); d->peerAddress = address; @@ -961,7 +967,7 @@ bool QNativeSocketEngine::waitForWrite(int msecs, bool *timedOut) QNativeSocketEnginePrivate::TimeOutErrorString); d->hasSetSocketError = false; // A timeout error is temporary in waitFor functions return false; - } else if (state() == QAbstractSocket::ConnectingState) { + } else if (state() == QAbstractSocket::ConnectingState || (state() == QAbstractSocket::BoundState && d->socketDescriptor != -1)) { connectToHost(d->peerAddress, d->peerPort); } |