- 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.
This commit is contained in:
Andreas 2013-01-28 22:45:26 +01:00
parent a2c07527bf
commit a4d26bc249
3 changed files with 8 additions and 34 deletions

View File

@ -104,10 +104,6 @@ using boost::scoped_ptr;
# include "devices/wmdmthread.h"
#endif
#ifndef Q_OS_WIN32
#include <signal.h>
#endif
// Load sqlite plugin on windows and mac.
#ifdef HAVE_STATIC_SQLITE
# include <QtPlugin>
@ -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();

View File

@ -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();
}

View File

@ -25,9 +25,7 @@ signals:
private:
void ParseMessage(const QByteArray& data);
void DisconnectClient();
void Disconnected();
void Error(QAbstractSocket::SocketError);
void DisconnectClientWrongAuthCode();
Application* app_;