summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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