From a4d26bc24934fbc862272565c8e7c9ca02df2bbc Mon Sep 17 00:00:00 2001 From: Andreas Date: Mon, 28 Jan 2013 22:45:26 +0100 Subject: [PATCH] - Actually fix the SIGPIPE (Broken Pipe) Error. It was caused by the QTcpSocket::flush(). - Revert previous SIGPIPE fixes. - Rename method in RemoteClient to match its function. --- src/main.cpp | 10 ---------- src/networkremote/remoteclient.cpp | 28 +++++++--------------------- src/networkremote/remoteclient.h | 4 +--- 3 files changed, 8 insertions(+), 34 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index d4955d1d2..c5c0190fe 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -104,10 +104,6 @@ using boost::scoped_ptr; # include "devices/wmdmthread.h" #endif -#ifndef Q_OS_WIN32 -#include -#endif - // Load sqlite plugin on windows and mac. #ifdef HAVE_STATIC_SQLITE # include @@ -410,12 +406,6 @@ int main(int argc, char *argv[]) { qtsparkle::LoadTranslations(language); #endif -#ifndef Q_OS_WIN32 - // This is needed to prevent SIGPIPE Errors, which occur under some - // circumstances in RemoteClient. They cause a program termination. - signal(SIGPIPE, SIG_IGN); -#endif - // Icons IconLoader::Init(); diff --git a/src/networkremote/remoteclient.cpp b/src/networkremote/remoteclient.cpp index 4f1621ef9..5888e30c6 100644 --- a/src/networkremote/remoteclient.cpp +++ b/src/networkremote/remoteclient.cpp @@ -35,12 +35,6 @@ RemoteClient::RemoteClient(Application* app, QTcpSocket* client) // Connect to the slot IncomingData when receiving data connect(client, SIGNAL(readyRead()), this, SLOT(IncomingData())); - // Connect the signals to see if an error occured or the client - // was disconnected. - connect(client, SIGNAL(disconnected()), this, SLOT(Disconnected())); - connect(client, SIGNAL(error(QAbstractSocket::SocketError)), - this, SLOT(Error(QAbstractSocket::SocketError))); - // Check if we use auth code QSettings s; @@ -91,7 +85,7 @@ void RemoteClient::ParseMessage(const QByteArray &data) { if (msg.type() == pb::remote::CONNECT && use_auth_code_) { if (msg.request_connect().auth_code() != auth_code_) { - DisconnectClient(); + DisconnectClientWrongAuthCode(); return; } } @@ -100,7 +94,7 @@ void RemoteClient::ParseMessage(const QByteArray &data) { emit Parse(msg); } -void RemoteClient::DisconnectClient() { +void RemoteClient::DisconnectClientWrongAuthCode() { pb::remote::Message msg; msg.set_type(pb::remote::DISCONNECT); msg.mutable_response_disconnect()->set_reason_disconnect(pb::remote::Wrong_Auth_Code); @@ -115,14 +109,15 @@ void RemoteClient::SendData(pb::remote::Message *msg) { // Serialize the message std::string data = msg->SerializeAsString(); - // write the length of the data first - if (client_->isWritable()) { + // Check if we are still connected + if (client_->state() == QTcpSocket::ConnectedState) { + // write the length of the data first QDataStream s(client_); s << qint32(data.length()); s.writeRawData(data.data(), data.length()); - // Flush data - client_->flush(); + // Do NOT flush data here! If the client is already disconnected, it + // causes a SIGPIPE termination!!! } else { client_->close(); } @@ -131,12 +126,3 @@ void RemoteClient::SendData(pb::remote::Message *msg) { QAbstractSocket::SocketState RemoteClient::State() { return client_->state(); } - -void RemoteClient::Disconnected() { - qLog(Info) << "Client Disconnected"; -} - -void RemoteClient::Error(QAbstractSocket::SocketError socket_error) { - qLog(Info) << "Client Error:" << socket_error; - client_->close(); -} diff --git a/src/networkremote/remoteclient.h b/src/networkremote/remoteclient.h index bd52a1d45..26494eb3d 100644 --- a/src/networkremote/remoteclient.h +++ b/src/networkremote/remoteclient.h @@ -25,9 +25,7 @@ signals: private: void ParseMessage(const QByteArray& data); - void DisconnectClient(); - void Disconnected(); - void Error(QAbstractSocket::SocketError); + void DisconnectClientWrongAuthCode(); Application* app_;