summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/io/qwindowspipewriter.cpp1
-rw-r--r--src/corelib/io/qwindowspipewriter_p.h1
-rw-r--r--src/network/socket/qlocalsocket_win.cpp3
-rw-r--r--tests/auto/qlocalsocket/tst_qlocalsocket.cpp61
4 files changed, 58 insertions, 8 deletions
diff --git a/src/corelib/io/qwindowspipewriter.cpp b/src/corelib/io/qwindowspipewriter.cpp
index f32eb92..0e707f3 100644
--- a/src/corelib/io/qwindowspipewriter.cpp
+++ b/src/corelib/io/qwindowspipewriter.cpp
@@ -160,6 +160,7 @@ void QWindowsPipeWriter::run()
hasWritten = true;
lock.unlock();
}
+ emit bytesWritten(totalWritten);
emit canWrite();
}
CloseHandle(overl.hEvent);
diff --git a/src/corelib/io/qwindowspipewriter_p.h b/src/corelib/io/qwindowspipewriter_p.h
index d651629..8f8c4a0 100644
--- a/src/corelib/io/qwindowspipewriter_p.h
+++ b/src/corelib/io/qwindowspipewriter_p.h
@@ -121,6 +121,7 @@ class Q_CORE_EXPORT QWindowsPipeWriter : public QThread
Q_SIGNALS:
void canWrite();
+ void bytesWritten(qint64 bytes);
public:
QWindowsPipeWriter(HANDLE writePipe, QObject * parent = 0);
diff --git a/src/network/socket/qlocalsocket_win.cpp b/src/network/socket/qlocalsocket_win.cpp
index 96dfa6e..e15ac65 100644
--- a/src/network/socket/qlocalsocket_win.cpp
+++ b/src/network/socket/qlocalsocket_win.cpp
@@ -302,8 +302,9 @@ qint64 QLocalSocket::writeData(const char *data, qint64 maxSize)
Q_D(QLocalSocket);
if (!d->pipeWriter) {
d->pipeWriter = new QWindowsPipeWriter(d->handle, this);
- d->pipeWriter->start();
connect(d->pipeWriter, SIGNAL(canWrite()), this, SLOT(_q_canWrite()));
+ connect(d->pipeWriter, SIGNAL(bytesWritten(qint64)), this, SIGNAL(bytesWritten(qint64)));
+ d->pipeWriter->start();
}
return d->pipeWriter->write(data, maxSize);
}
diff --git a/tests/auto/qlocalsocket/tst_qlocalsocket.cpp b/tests/auto/qlocalsocket/tst_qlocalsocket.cpp
index fdfbd8a..ce4bf6e 100644
--- a/tests/auto/qlocalsocket/tst_qlocalsocket.cpp
+++ b/tests/auto/qlocalsocket/tst_qlocalsocket.cpp
@@ -110,6 +110,7 @@ private slots:
void writeToClientAndDisconnect();
void debug();
+ void bytesWrittenSignal();
#ifdef Q_OS_SYMBIAN
@@ -423,7 +424,7 @@ void tst_QLocalSocket::listenAndConnect()
for (int j = 0; j < spyStateChanged.count(); ++j) {
QLocalSocket::LocalSocketState s;
s = qVariantValue<QLocalSocket::LocalSocketState>(spyStateChanged.at(j).at(0));
- qDebug() << s;
+ qDebug() << s;
}
#endif
if (canListen)
@@ -508,11 +509,11 @@ void tst_QLocalSocket::sendData()
if (server.hasPendingConnections()) {
QString testLine = "test";
#ifdef Q_OS_SYMBIAN
- for (int i = 0; i < 25 * 1024; ++i)
+ for (int i = 0; i < 25 * 1024; ++i)
#else
- for (int i = 0; i < 50000; ++i)
+ for (int i = 0; i < 50000; ++i)
#endif
- testLine += "a";
+ testLine += "a";
QLocalSocket *serverSocket = server.nextPendingConnection();
QVERIFY(serverSocket);
QCOMPARE(serverSocket->state(), QLocalSocket::ConnectedState);
@@ -646,7 +647,7 @@ public:
++tries;
} while ((socket.error() == QLocalSocket::ServerNotFoundError
|| socket.error() == QLocalSocket::ConnectionRefusedError)
- && tries < 1000);
+ && tries < 1000);
if (tries == 0 && socket.state() != QLocalSocket::ConnectedState) {
QVERIFY(socket.waitForConnected(3000));
QVERIFY(socket.state() == QLocalSocket::ConnectedState);
@@ -738,8 +739,8 @@ void tst_QLocalSocket::threadedConnection()
while (!clients.isEmpty()) {
QVERIFY(clients.first()->wait(3000));
Client *client =clients.takeFirst();
- client->terminate();
- delete client;
+ client->terminate();
+ delete client;
}
}
@@ -906,6 +907,52 @@ void tst_QLocalSocket::debug()
qDebug() << QLocalSocket::ConnectionRefusedError << QLocalSocket::UnconnectedState;
}
+class WriteThread : public QThread
+{
+Q_OBJECT
+public:
+ void run() {
+ QLocalSocket socket;
+ socket.connectToServer("qlocalsocket_readyread");
+
+ if (!socket.waitForConnected(3000))
+ exec();
+ connect(&socket, SIGNAL(bytesWritten(qint64)),
+ this, SLOT(bytesWritten(qint64)), Qt::QueuedConnection);
+ socket.write("testing\n");
+ exec();
+ }
+public slots:
+ void bytesWritten(qint64) {
+ exit();
+ }
+
+private:
+};
+
+/*
+ Tests the emission of the bytesWritten(qint64)
+ signal.
+
+ Create a thread that will write to a socket.
+ If the bytesWritten(qint64) signal is generated,
+ the slot connected to it will exit the thread,
+ indicating test success.
+
+*/
+void tst_QLocalSocket::bytesWrittenSignal()
+{
+ QLocalServer server;
+ QVERIFY(server.listen("qlocalsocket_readyread"));
+ WriteThread writeThread;
+ writeThread.start();
+ bool timedOut = false;
+ QVERIFY(server.waitForNewConnection(3000, &timedOut));
+ QVERIFY(!timedOut);
+ QTest::qWait(2000);
+ QVERIFY(writeThread.wait(2000));
+}
+
#ifdef Q_OS_SYMBIAN
void tst_QLocalSocket::unlink(QString name)
{