QAbstractSocket: fix handling of successful connectToHostByName()

In case connectToHostByName() returns 'true', we should fetch the
connection parameters and emit connected() signal.

Change-Id: Id36b6d71005b8cec070a1b12e7bb0caf8bf0bcb9
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
Alex Trotsenko 2016-11-09 18:40:43 +02:00
parent 3c59065d5c
commit f03cd9a7bc

View File

@ -962,13 +962,17 @@ void QAbstractSocketPrivate::startConnectingByName(const QString &host)
emit q->stateChanged(state);
if (cachedSocketDescriptor != -1 || initSocketLayer(QAbstractSocket::UnknownNetworkLayerProtocol)) {
if (socketEngine->connectToHostByName(host, port) ||
socketEngine->state() == QAbstractSocket::ConnectingState) {
cachedSocketDescriptor = socketEngine->socketDescriptor();
// Try to connect to the host. If it succeeds immediately
// (e.g. QSocks5SocketEngine in UDPASSOCIATE mode), emit
// connected() and return.
if (socketEngine->connectToHostByName(host, port)) {
fetchConnectionParameters();
return;
}
if (socketEngine->state() == QAbstractSocket::ConnectingState)
return;
// failed to connect
setError(socketEngine->error(), socketEngine->errorString());
}