diff --git a/src/corelib/io/qprocess_p.h b/src/corelib/io/qprocess_p.h index 74ab6ab409..4b38f191d5 100644 --- a/src/corelib/io/qprocess_p.h +++ b/src/corelib/io/qprocess_p.h @@ -287,6 +287,7 @@ public: #ifdef Q_OS_WIN qint64 pipeWriterBytesToWrite() const; void _q_bytesWritten(qint64 bytes); + void _q_writeFailed(); #else bool _q_canWrite(); bool writeToStdin(); diff --git a/src/corelib/io/qprocess_win.cpp b/src/corelib/io/qprocess_win.cpp index f935e4f491..b2e8beaa53 100644 --- a/src/corelib/io/qprocess_win.cpp +++ b/src/corelib/io/qprocess_win.cpp @@ -841,6 +841,8 @@ qint64 QProcess::writeData(const char *data, qint64 len) d->stdinChannel.writer = new QWindowsPipeWriter(d->stdinChannel.pipe[1], this); QObjectPrivate::connect(d->stdinChannel.writer, &QWindowsPipeWriter::bytesWritten, d, &QProcessPrivate::_q_bytesWritten); + QObjectPrivate::connect(d->stdinChannel.writer, &QWindowsPipeWriter::writeFailed, + d, &QProcessPrivate::_q_writeFailed); } if (d->isWriteChunkCached(data, len)) @@ -872,6 +874,12 @@ void QProcessPrivate::_q_bytesWritten(qint64 bytes) closeWriteChannel(); } +void QProcessPrivate::_q_writeFailed() +{ + closeWriteChannel(); + setErrorAndEmit(QProcess::WriteError); +} + // Use ShellExecuteEx() to trigger an UAC prompt when CreateProcess()fails // with ERROR_ELEVATION_REQUIRED. static bool startDetachedUacPrompt(const QString &programIn, const QStringList &arguments, diff --git a/src/corelib/io/qwindowspipewriter.cpp b/src/corelib/io/qwindowspipewriter.cpp index 843ff6a00b..3024742d34 100644 --- a/src/corelib/io/qwindowspipewriter.cpp +++ b/src/corelib/io/qwindowspipewriter.cpp @@ -341,6 +341,7 @@ bool QWindowsPipeWriter::consumePendingAndEmit(bool allowWinActPosting) if (alive) { writeBuffer.clear(); completionState = WriteDisabled; + emit writeFailed(); } } else if (emitBytesWritten) { emit bytesWritten(numberOfBytesWritten); diff --git a/src/corelib/io/qwindowspipewriter_p.h b/src/corelib/io/qwindowspipewriter_p.h index 81a586dc3d..71e47c9787 100644 --- a/src/corelib/io/qwindowspipewriter_p.h +++ b/src/corelib/io/qwindowspipewriter_p.h @@ -78,6 +78,7 @@ public: Q_SIGNALS: void bytesWritten(qint64 bytes); + void writeFailed(); protected: bool event(QEvent *e) override; diff --git a/src/network/socket/qlocalsocket_p.h b/src/network/socket/qlocalsocket_p.h index 036ce48885..bb1a808911 100644 --- a/src/network/socket/qlocalsocket_p.h +++ b/src/network/socket/qlocalsocket_p.h @@ -137,6 +137,7 @@ public: void _q_bytesWritten(qint64 bytes); void _q_pipeClosed(); void _q_winError(ulong windowsError, const QString &function); + void _q_writeFailed(); HANDLE handle; QWindowsPipeWriter *pipeWriter; QWindowsPipeReader *pipeReader; diff --git a/src/network/socket/qlocalsocket_win.cpp b/src/network/socket/qlocalsocket_win.cpp index c4da59c278..019829cc9c 100644 --- a/src/network/socket/qlocalsocket_win.cpp +++ b/src/network/socket/qlocalsocket_win.cpp @@ -310,6 +310,8 @@ qint64 QLocalSocket::writeData(const char *data, qint64 len) d->pipeWriter = new QWindowsPipeWriter(d->handle, this); QObjectPrivate::connect(d->pipeWriter, &QWindowsPipeWriter::bytesWritten, d, &QLocalSocketPrivate::_q_bytesWritten); + QObjectPrivate::connect(d->pipeWriter, &QWindowsPipeWriter::writeFailed, + d, &QLocalSocketPrivate::_q_writeFailed); } if (d->isWriteChunkCached(data, len)) @@ -455,6 +457,16 @@ void QLocalSocketPrivate::_q_bytesWritten(qint64 bytes) q->disconnectFromServer(); } +void QLocalSocketPrivate::_q_writeFailed() +{ + Q_Q(QLocalSocket); + error = QLocalSocket::PeerClosedError; + errorString = QLocalSocket::tr("Remote closed"); + emit q->errorOccurred(error); + + _q_pipeClosed(); +} + qintptr QLocalSocket::socketDescriptor() const { Q_D(const QLocalSocket); diff --git a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp index 519a7bfacb..b2f426d01c 100644 --- a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp +++ b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp @@ -1531,6 +1531,7 @@ void tst_QLocalSocket::writeToDisconnected() QVERIFY(server.listen("writeToDisconnected")); QLocalSocket client; + QSignalSpy spyError(&client, SIGNAL(errorOccurred(QLocalSocket::LocalSocketError))); client.connectToServer("writeToDisconnected"); QVERIFY(client.waitForConnected(3000)); QVERIFY(server.waitForNewConnection(3000)); @@ -1548,6 +1549,7 @@ void tst_QLocalSocket::writeToDisconnected() QCOMPARE(client.bytesToWrite(), qint64(1)); QVERIFY(!client.waitForBytesWritten()); + QCOMPARE(spyError.count(), 1); QCOMPARE(client.state(), QLocalSocket::UnconnectedState); }