1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-17 12:02:48 +01:00

- 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" # include "devices/wmdmthread.h"
#endif #endif
#ifndef Q_OS_WIN32
#include <signal.h>
#endif
// Load sqlite plugin on windows and mac. // Load sqlite plugin on windows and mac.
#ifdef HAVE_STATIC_SQLITE #ifdef HAVE_STATIC_SQLITE
# include <QtPlugin> # include <QtPlugin>
@ -410,12 +406,6 @@ int main(int argc, char *argv[]) {
qtsparkle::LoadTranslations(language); qtsparkle::LoadTranslations(language);
#endif #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 // Icons
IconLoader::Init(); IconLoader::Init();

View File

@ -35,12 +35,6 @@ RemoteClient::RemoteClient(Application* app, QTcpSocket* client)
// Connect to the slot IncomingData when receiving data // Connect to the slot IncomingData when receiving data
connect(client, SIGNAL(readyRead()), this, SLOT(IncomingData())); 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 // Check if we use auth code
QSettings s; QSettings s;
@ -91,7 +85,7 @@ void RemoteClient::ParseMessage(const QByteArray &data) {
if (msg.type() == pb::remote::CONNECT && use_auth_code_) { if (msg.type() == pb::remote::CONNECT && use_auth_code_) {
if (msg.request_connect().auth_code() != auth_code_) { if (msg.request_connect().auth_code() != auth_code_) {
DisconnectClient(); DisconnectClientWrongAuthCode();
return; return;
} }
} }
@ -100,7 +94,7 @@ void RemoteClient::ParseMessage(const QByteArray &data) {
emit Parse(msg); emit Parse(msg);
} }
void RemoteClient::DisconnectClient() { void RemoteClient::DisconnectClientWrongAuthCode() {
pb::remote::Message msg; pb::remote::Message msg;
msg.set_type(pb::remote::DISCONNECT); msg.set_type(pb::remote::DISCONNECT);
msg.mutable_response_disconnect()->set_reason_disconnect(pb::remote::Wrong_Auth_Code); 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 // Serialize the message
std::string data = msg->SerializeAsString(); std::string data = msg->SerializeAsString();
// write the length of the data first // Check if we are still connected
if (client_->isWritable()) { if (client_->state() == QTcpSocket::ConnectedState) {
// write the length of the data first
QDataStream s(client_); QDataStream s(client_);
s << qint32(data.length()); s << qint32(data.length());
s.writeRawData(data.data(), data.length()); s.writeRawData(data.data(), data.length());
// Flush data // Do NOT flush data here! If the client is already disconnected, it
client_->flush(); // causes a SIGPIPE termination!!!
} else { } else {
client_->close(); client_->close();
} }
@ -131,12 +126,3 @@ void RemoteClient::SendData(pb::remote::Message *msg) {
QAbstractSocket::SocketState RemoteClient::State() { QAbstractSocket::SocketState RemoteClient::State() {
return client_->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: private:
void ParseMessage(const QByteArray& data); void ParseMessage(const QByteArray& data);
void DisconnectClient(); void DisconnectClientWrongAuthCode();
void Disconnected();
void Error(QAbstractSocket::SocketError);
Application* app_; Application* app_;