PROTON-1314: Fixing SIGPIPE ignore on Solaris OS Signed-off-by: aboutros <adel.bout...@murex.com>
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/3dd7be37 Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/3dd7be37 Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/3dd7be37 Branch: refs/heads/go1 Commit: 3dd7be374d0eb69dc9cf70e793de11bd765050a3 Parents: 6dabb37 Author: aboutros <adel.bout...@murex.com> Authored: Wed Oct 5 10:38:34 2016 +0200 Committer: Alan Conway <acon...@redhat.com> Committed: Wed Oct 19 17:14:47 2016 -0400 ---------------------------------------------------------------------- proton-c/src/posix/io.c | 48 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/3dd7be37/proton-c/src/posix/io.c ---------------------------------------------------------------------- diff --git a/proton-c/src/posix/io.c b/proton-c/src/posix/io.c index c0dc425..27d1a35 100644 --- a/proton-c/src/posix/io.c +++ b/proton-c/src/posix/io.c @@ -257,7 +257,53 @@ static inline int pn_create_socket(int af, int protocol) { return sock; } #else -#error "Don't know how to turn off SIGPIPE on this platform" + +#include <signal.h> + +static inline int pn_create_socket(int af, int protocol) { + return socket(af, SOCK_STREAM, protocol); +} + +static ssize_t nosigpipe_send(int fd, const void *buffer, size_t size) { + sigset_t pendingSignals, oldSignals, newSignals; + ssize_t count; + int sendErrno, sigmaskErr; + + sigpending(&pendingSignals); + int sigpipeIsPending = sigismember(&pendingSignals, SIGPIPE); + if (!sigpipeIsPending) { + sigemptyset(&newSignals); + sigaddset(&newSignals, SIGPIPE); + if (sigmaskErr = pthread_sigmask(SIG_BLOCK, (const sigset_t *)&newSignals, (sigset_t *)&oldSignals)) + { + errno = sigmaskErr; + return -1; + } + } + + count = send(fd, buffer, size, 0); + if (!sigpipeIsPending) { + sendErrno = errno; + if (count == -1 && errno == EPIPE) { + while (-1 == sigtimedwait(&newSignals, NULL, &(struct timespec){ 0, 0 }) && errno == EINTR) + ; //do nothing + } + if (sigmaskErr = pthread_sigmask(SIG_SETMASK, (const sigset_t *)&oldSignals, (sigset_t *)NULL)) + { + errno = sigmaskErr; + return -1; + } + errno = sendErrno; + } + return count; +} + +ssize_t pn_send(pn_io_t *io, pn_socket_t socket, const void *buf, size_t size) { + ssize_t count = nosigpipe_send(socket, buf, size); + io->wouldblock = (errno == EAGAIN || errno == EWOULDBLOCK); + if (count < 0) { pn_i_error_from_errno(io->error, "send"); } + return count; +} #endif ssize_t pn_recv(pn_io_t *io, pn_socket_t socket, void *buf, size_t size) --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org