diff --git a/src/core/comm/SocketComm.cc b/src/core/comm/SocketComm.cc index 0ae632e9..3cd7593c 100644 --- a/src/core/comm/SocketComm.cc +++ b/src/core/comm/SocketComm.cc @@ -1,10 +1,18 @@ #include #include +#include #include "SocketComm.hpp" namespace fail { +void SocketComm::init() +{ + // It's usually much easier to handle the error on write(), than to do + // anything intelligent in a SIGPIPE handler. + signal(SIGPIPE, SIG_IGN); +} + bool SocketComm::sendMsg(int sockfd, google::protobuf::Message& msg) { #ifdef USE_SIZE_PREFIX diff --git a/src/core/comm/SocketComm.hpp b/src/core/comm/SocketComm.hpp index 99459281..1d6ef1a8 100644 --- a/src/core/comm/SocketComm.hpp +++ b/src/core/comm/SocketComm.hpp @@ -21,6 +21,10 @@ namespace fail { class SocketComm { public: + /** + * This allows us to ignore SIGPIPE. + */ + static void init(); /** * Send Protobuf-generated message * @param sockfd open socket descriptor to write to diff --git a/src/core/cpn/JobServer.hpp b/src/core/cpn/JobServer.hpp index 5ab6d5ba..7c1bf521 100644 --- a/src/core/cpn/JobServer.hpp +++ b/src/core/cpn/JobServer.hpp @@ -7,6 +7,7 @@ #include "util/SynchronizedMap.hpp" #include "config/FailConfig.hpp" #include "comm/FailControlMessage.pb.h" +#include "comm/SocketComm.hpp" #include #include @@ -81,6 +82,7 @@ public: JobServer(int port = SERVER_COMM_TCP_PORT) : m_port(port), m_finish(false), m_noMoreExps(false), m_maxThreads(128), m_threadtimeout(0), m_undoneJobs(SERVER_OUT_QUEUE_SIZE) { + SocketComm::init(); m_runid = std::time(0); #ifndef __puma m_serverThread = new boost::thread(&JobServer::run, this); // run operator()() in a thread. diff --git a/src/core/efw/JobClient.cc b/src/core/efw/JobClient.cc index a102a10f..638cfe0a 100644 --- a/src/core/efw/JobClient.cc +++ b/src/core/efw/JobClient.cc @@ -1,4 +1,5 @@ #include "JobClient.hpp" +#include "comm/SocketComm.hpp" using namespace std; @@ -6,6 +7,7 @@ namespace fail { JobClient::JobClient(const std::string& server, int port) { + SocketComm::init(); m_server_port = port; m_server = server; m_server_ent = gethostbyname(m_server.c_str());