summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2012-04-06 10:33:52 -0700
committerPixel <pixel@nobis-crew.org>2012-04-06 10:33:52 -0700
commit0ffde5a99c4f1a6ea6fc9f4678e919953e48cfb8 (patch)
treebca9de505265d5b352e22f8d054128c7962c773d /src
parentd73c68540dcbec2e4c997b940144d9246828439c (diff)
Dodging SIGPIPE for Unix platforms.
Diffstat (limited to 'src')
-rw-r--r--src/Socket.cc27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/Socket.cc b/src/Socket.cc
index 18989af..d78c6e5 100644
--- a/src/Socket.cc
+++ b/src/Socket.cc
@@ -14,6 +14,26 @@
#include "Main.h"
#include "Atomic.h"
+#ifndef _WIN32
+namespace {
+
+class SigpipeBlocker : public Balau::AtStart {
+ public:
+ SigpipeBlocker() : AtStart(5) { }
+ virtual void doStart() {
+ struct sigaction new_actn, old_actn;
+ new_actn.sa_handler = SIG_IGN;
+ sigemptyset(&new_actn.sa_mask);
+ new_actn.sa_flags = 0;
+ sigaction(SIGPIPE, &new_actn, &old_actn);
+ }
+};
+
+static SigpipeBlocker sigpipeBlocker;
+
+};
+#endif
+
void Balau::Socket::SocketEvent::gotOwner(Task * task) {
Printer::elog(E_SOCKET, "Arming SocketEvent at %p", this);
if (!m_task) {
@@ -574,6 +594,13 @@ ssize_t Balau::Socket::write(const void * buf, size_t count) throw (GeneralExcep
if (r > 0)
return r;
+#ifndef _WIN32
+ if (errno == EPIPE) {
+ close();
+ return 0;
+ }
+#endif
+
if ((errno == EAGAIN) || (errno == EINTR) || (errno == EWOULDBLOCK)) {
Task::yield(m_evtW, true);
} else {