summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Antonuk <alan.antonuk@gmail.com>2012-06-06 14:42:19 -0400
committerAlan Antonuk <alan.antonuk@gmail.com>2012-06-06 18:00:31 -0400
commitd2462806af2a2f58a689211f5b381c3a3eea1e8e (patch)
treecfc7421b2d4bf97fd50941f87598b81aa081349d
parent815f5215dcf2f0fb487dc89f4ec4f1ef6bfb2ff2 (diff)
downloadrabbitmq-c-github-ask-issue23.tar.gz
Disable sigpipe on Mac OSXissue23
Use setsockopt(SO_NOSIGPIPE) on platforms that don't have MSG_NOSIGNAL and do have SO_NOSIGPIPE
-rw-r--r--librabbitmq/amqp_socket.c8
-rw-r--r--librabbitmq/unix/socket.h8
-rw-r--r--librabbitmq/win32/socket.h4
3 files changed, 20 insertions, 0 deletions
diff --git a/librabbitmq/amqp_socket.c b/librabbitmq/amqp_socket.c
index 909f62d..2034f17 100644
--- a/librabbitmq/amqp_socket.c
+++ b/librabbitmq/amqp_socket.c
@@ -66,6 +66,14 @@ int amqp_open_socket(char const *hostname,
if (sockfd == -1)
return -amqp_socket_error();
+#ifdef DISABLE_SIGPIPE_WITH_SETSOCKOPT
+ if (0 != amqp_socket_setsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE, &one,
+ sizeof(one)))
+ {
+ return -amqp_socket_error();
+ }
+#endif
+
if (amqp_socket_setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, &one,
sizeof(one)) < 0
|| connect(sockfd, (struct sockaddr *) &addr, sizeof(addr)) < 0)
diff --git a/librabbitmq/unix/socket.h b/librabbitmq/unix/socket.h
index ff6fa73..d57cb7b 100644
--- a/librabbitmq/unix/socket.h
+++ b/librabbitmq/unix/socket.h
@@ -55,4 +55,12 @@ amqp_socket_error(void);
#define amqp_socket_close close
#define amqp_socket_writev writev
+#ifndef MSG_NOSIGNAL
+# define MSG_NOSIGNAL 0x0
+#endif
+
+#if defined(SO_NOSIGPIPE) && !defined(MSG_NOSIGNAL)
+# define DISABLE_SIGPIPE_WITH_SETSOCKOPT
+#endif
+
#endif
diff --git a/librabbitmq/win32/socket.h b/librabbitmq/win32/socket.h
index 4572410..3b9c452 100644
--- a/librabbitmq/win32/socket.h
+++ b/librabbitmq/win32/socket.h
@@ -57,4 +57,8 @@ amqp_socket_writev(int sock, struct iovec *iov, int nvecs);
int
amqp_socket_error(void);
+#ifndef MSG_NOSIGNAL
+# define MSG_NOSIGNAL 0x0
+#endif
+
#endif