From b0b1a5e98cea0883bd2590a9215fe811f689f86d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Thu, 19 Jun 2014 20:35:28 +0200 Subject: [PATCH] avoid closing local sockets before writing is finished --- YACReader/yacreader_local_client.cpp | 5 +++++ YACReaderLibrary/yacreader_local_server.cpp | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/YACReader/yacreader_local_client.cpp b/YACReader/yacreader_local_client.cpp index c10abb6f..a6175b99 100644 --- a/YACReader/yacreader_local_client.cpp +++ b/YACReader/yacreader_local_client.cpp @@ -62,6 +62,8 @@ bool YACReaderLocalClient::requestComicInfo(quint64 libraryId, ComicDB & comic, return false; } + localSocket->waitForBytesWritten(2000); + //QByteArray data; tries = 0; int dataAvailable = 0; @@ -128,6 +130,7 @@ bool YACReaderLocalClient::sendComicInfo(quint64 libraryId, ComicDB & comic) localSocket->connectToServer(YACREADERLIBRARY_GUID); if(localSocket->isOpen()) { + //QLOG_INFO() << "Connection opened for sending ComicInfo"; QByteArray block; QDataStream out(&block, QIODevice::WriteOnly); out.setVersion(QDataStream::Qt_4_8); @@ -148,7 +151,9 @@ bool YACReaderLocalClient::sendComicInfo(quint64 libraryId, ComicDB & comic) tries++; previousWritten = written; } + localSocket->waitForBytesWritten(2000); localSocket->close(); + //QLOG_INFO() << QString("Sending Comic Info : writen data (%1,%2)").arg(written).arg(block.size()); if(tries == 100 && written != block.size()) { emit finished(); diff --git a/YACReaderLibrary/yacreader_local_server.cpp b/YACReaderLibrary/yacreader_local_server.cpp index 8b81cc6d..a24c184f 100644 --- a/YACReaderLibrary/yacreader_local_server.cpp +++ b/YACReaderLibrary/yacreader_local_server.cpp @@ -110,7 +110,7 @@ void YACReaderClientConnectionWorker::run() } if(tries == 20) { - QLOG_ERROR() << "Local connection: unable to read the message size"; + QLOG_ERROR() << "Local connection: unable to read the message size" << clientConnection->errorString(); return; } @@ -163,6 +163,7 @@ void YACReaderClientConnectionWorker::run() while(written != block.size() && tries < 200) { int ret = clientConnection->write(block); + clientConnection->waitForBytesWritten(10); if(ret != -1) { written += ret;