QLocalSocket/Tcp: open device before making a connection

According to QLocalSocket's documentation, connectToServer() must
initiate a connection attempt after opening the device. Otherwise, if
a connection succeeds immediately, connected() signal will be emitted
on closed device. So, this patch ensures that TCP-based implementation
behaves correctly.

Change-Id: I4cc9474815e091a1491a429a6dc17f9cf0154f58
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Alex Trotsenko 2016-07-28 17:28:27 +03:00
parent 457d91bb07
commit 595c6abf9d
2 changed files with 2 additions and 1 deletions

View File

@ -239,8 +239,8 @@ void QLocalSocket::connectToServer(OpenMode openMode)
QLatin1String("QLocalSocket::connectToServer"));
return;
}
d->tcpSocket->connectToHost(QHostAddress::LocalHost, port, openMode);
QIODevice::open(openMode);
d->tcpSocket->connectToHost(QHostAddress::LocalHost, port, openMode);
}
bool QLocalSocket::setSocketDescriptor(qintptr socketDescriptor,

View File

@ -190,6 +190,7 @@ private slots:
void slotConnected()
{
QCOMPARE(state(), QLocalSocket::ConnectedState);
QVERIFY(isOpen());
}
void slotDisconnected()
{