qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From astitc...@apache.org
Subject svn commit: r1417550 - /qpid/proton/trunk/proton-c/src/driver.c
Date Wed, 05 Dec 2012 17:42:40 GMT
Author: astitcher
Date: Wed Dec  5 17:42:39 2012
New Revision: 1417550

URL: http://svn.apache.org/viewvc?rev=1417550&view=rev
Log:
PROTON-106: Abstract ignoring SIGPIPE so that the code works on MacOS X

Modified:
    qpid/proton/trunk/proton-c/src/driver.c

Modified: qpid/proton/trunk/proton-c/src/driver.c
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/src/driver.c?rev=1417550&r1=1417549&r2=1417550&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/src/driver.c (original)
+++ qpid/proton/trunk/proton-c/src/driver.c Wed Dec  5 17:42:39 2012
@@ -44,6 +44,35 @@
 #define PN_SEL_RD (0x0001)
 #define PN_SEL_WR (0x0002)
 
+/* Abstract away turning off SIGPIPE */
+#ifdef MSG_NOSIGNAL
+static inline ssize_t pn_send(int sockfd, const void *buf, size_t len) {
+    return send(sockfd, buf, len, MSG_NOSIGNAL);
+}
+
+static inline int pn_create_socket() {
+    return socket(AF_INET, SOCK_STREAM, getprotobyname("tcp")->p_proto);
+}
+#elif defined(SO_NOSIGPIPE)
+static inline ssize_t pn_send(int sockfd, const void *buf, size_t len) {
+    return send(sockfd, buf, len, 0);
+}
+
+static inline int pn_create_socket() {
+    int sock = socket(AF_INET, SOCK_STREAM, getprotobyname("tcp")->p_proto);
+    if (sock == -1) return sock;
+
+    int optval = 1;
+    if (setsockopt(sock, SOL_SOCKET, SO_NOSIGPIPE, &optval, sizeof(optval)) == -1) {
+        close(sock);
+        return -1;
+    }
+    return sock;
+}
+#else
+#error "Don't know how to turn off SIGPIPE on this platform"
+#endif
+
 struct pn_driver_t {
   pn_error_t *error;
   pn_listener_t *listener_head;
@@ -143,9 +172,9 @@ pn_listener_t *pn_listener(pn_driver_t *
     return NULL;
   }
 
-  int sock = socket(AF_INET, SOCK_STREAM, getprotobyname("tcp")->p_proto);
+  int sock = pn_create_socket();
   if (sock == -1) {
-    pn_error_from_errno(driver->error, "socket");
+    pn_error_from_errno(driver->error, "pn_create_socket");
     return NULL;
   }
 
@@ -319,9 +348,9 @@ pn_connector_t *pn_connector(pn_driver_t
     return NULL;
   }
 
-  int sock = socket(AF_INET, SOCK_STREAM, getprotobyname("tcp")->p_proto);
+  int sock = pn_create_socket();
   if (sock == -1) {
-    pn_error_from_errno(driver->error, "socket");
+    pn_error_from_errno(driver->error, "pn_create_socket");
     return NULL;
   }
 
@@ -551,7 +580,7 @@ void pn_connector_activate(pn_connector_
 static void pn_connector_write(pn_connector_t *ctor)
 {
   if (ctor->output_size > 0) {
-    ssize_t n = send(ctor->fd, ctor->output, ctor->output_size, MSG_NOSIGNAL);
+    ssize_t n = pn_send(ctor->fd, ctor->output, ctor->output_size);
     if (n < 0) {
       // XXX
         if (errno != EAGAIN) {



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message