From 9fb68a90af79df3b8dc3225a3a97e2c6387afeec Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 23 Dec 2014 13:37:01 -0200 Subject: 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 --- src/network/ssl/qsslsocket.cpp | 23 +++++++++++++++++++++++ src/network/ssl/qsslsocket_p.h | 1 + 2 files changed, 24 insertions(+) (limited to 'src/network/ssl') diff --git a/src/network/ssl/qsslsocket.cpp b/src/network/ssl/qsslsocket.cpp index 508d300d42..b1076ebd68 100644 --- a/src/network/ssl/qsslsocket.cpp +++ b/src/network/ssl/qsslsocket.cpp @@ -2404,6 +2404,29 @@ bool QSslSocketPrivate::isPaused() const return paused; } +bool QSslSocketPrivate::bind(const QHostAddress &address, quint16 port, QAbstractSocket::BindMode mode) +{ + // this function is called from QAbstractSocket::bind + if (!initialized) + init(); + initialized = false; + +#ifdef QSSLSOCKET_DEBUG + qCDebug(lcSsl) << "QSslSocket::bind(" << address << ',' << port << ',' << mode << ')'; +#endif + if (!plainSocket) { +#ifdef QSSLSOCKET_DEBUG + qCDebug(lcSsl) << "\tcreating internal plain socket"; +#endif + createPlainSocket(QIODevice::ReadWrite); + } + bool ret = plainSocket->bind(address, port, mode); + localPort = plainSocket->localPort(); + localAddress = plainSocket->localAddress(); + cachedSocketDescriptor = plainSocket->socketDescriptor(); + return ret; +} + /*! \internal */ diff --git a/src/network/ssl/qsslsocket_p.h b/src/network/ssl/qsslsocket_p.h index b110d65f9a..5f726f2371 100644 --- a/src/network/ssl/qsslsocket_p.h +++ b/src/network/ssl/qsslsocket_p.h @@ -172,6 +172,7 @@ public: static void checkSettingSslContext(QSslSocket*, QSharedPointer); static QSharedPointer sslContext(QSslSocket *socket); bool isPaused() const; + bool bind(const QHostAddress &address, quint16, QAbstractSocket::BindMode) Q_DECL_OVERRIDE; void _q_connectedSlot(); void _q_hostFoundSlot(); void _q_disconnectedSlot(); -- cgit v1.2.3