QLocalSocket/Win: do not flush the pipe in disconnectFromServer()
In the case where we have pending data to write, calling flush() here may cause the device to close immediately, if the pipe writer already got a result of the last operation from the thread pool. In this scenario, the device does not enter the 'Closing' state, which leads the following code to unexpectedly fail on Windows socket.write(...); socket.disconnectFromServer(); QVERIFY(socket.waitForDisconnected()); Removing the call to flush() makes the behavior consistent with the implementation on Unix. Change-Id: Ic31fbc999be979c1e5befa8f132d9fb367f472ca Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
This commit is contained in:
parent
594948a07b
commit
6481733d45
@ -403,7 +403,6 @@ void QLocalSocket::disconnectFromServer()
|
||||
{
|
||||
Q_D(QLocalSocket);
|
||||
|
||||
flush();
|
||||
if (bytesToWrite() != 0) {
|
||||
d->state = QLocalSocket::ClosingState;
|
||||
emit stateChanged(d->state);
|
||||
|
@ -120,6 +120,7 @@ private slots:
|
||||
void waitForDisconnect();
|
||||
void waitForDisconnectByServer();
|
||||
void waitForReadyReadOnDisconnected();
|
||||
void delayedDisconnect();
|
||||
|
||||
void removeServer();
|
||||
|
||||
@ -1352,6 +1353,24 @@ void tst_QLocalSocket::waitForReadyReadOnDisconnected()
|
||||
QVERIFY(timer.elapsed() < 2000);
|
||||
}
|
||||
|
||||
void tst_QLocalSocket::delayedDisconnect()
|
||||
{
|
||||
QString name = "tst_localsocket";
|
||||
LocalServer server;
|
||||
QVERIFY(server.listen(name));
|
||||
LocalSocket socket;
|
||||
socket.connectToServer(name);
|
||||
QVERIFY(socket.waitForConnected(3000));
|
||||
QVERIFY(server.waitForNewConnection(3000));
|
||||
QLocalSocket *serverSocket = server.nextPendingConnection();
|
||||
QVERIFY(serverSocket);
|
||||
QVERIFY(socket.putChar(0));
|
||||
socket.disconnectFromServer();
|
||||
QCOMPARE(socket.state(), QLocalSocket::ClosingState);
|
||||
QVERIFY(socket.waitForDisconnected(3000));
|
||||
QCOMPARE(socket.state(), QLocalSocket::UnconnectedState);
|
||||
}
|
||||
|
||||
void tst_QLocalSocket::removeServer()
|
||||
{
|
||||
// this is a hostile takeover, but recovering from a crash results in the same
|
||||
|
Loading…
x
Reference in New Issue
Block a user