From 0ffde5a99c4f1a6ea6fc9f4678e919953e48cfb8 Mon Sep 17 00:00:00 2001 From: Pixel Date: Fri, 6 Apr 2012 10:33:52 -0700 Subject: Dodging SIGPIPE for Unix platforms. --- src/Socket.cc | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src') 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 { -- cgit v1.2.3