You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by ma...@apache.org on 2011/08/30 09:01:48 UTC

svn commit: r1163106 - in /zookeeper/trunk: CHANGES.txt src/c/src/zookeeper.c

Author: mahadev
Date: Tue Aug 30 07:01:48 2011
New Revision: 1163106

URL: http://svn.apache.org/viewvc?rev=1163106&view=rev
Log:
ZOOKEEPER-1051. SIGPIPE in Zookeeper 0.3.* when send'ing after cluster disconnection (Stephen Tyree via mahadev)

Modified:
    zookeeper/trunk/CHANGES.txt
    zookeeper/trunk/src/c/src/zookeeper.c

Modified: zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/trunk/CHANGES.txt?rev=1163106&r1=1163105&r2=1163106&view=diff
==============================================================================
--- zookeeper/trunk/CHANGES.txt (original)
+++ zookeeper/trunk/CHANGES.txt Tue Aug 30 07:01:48 2011
@@ -297,6 +297,9 @@ BUGFIXES: 
 
   ZOOKEEPER-1140. server shutdown is not stopping threads. (laxman via mahadev)
 
+  ZOOKEEPER-1051. SIGPIPE in Zookeeper 0.3.* when send'ing after 
+  cluster disconnection (Stephen Tyree via mahadev)
+
 IMPROVEMENTS:
   ZOOKEEPER-724. Improve junit test integration - log harness information 
   (phunt via mahadev)

Modified: zookeeper/trunk/src/c/src/zookeeper.c
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/c/src/zookeeper.c?rev=1163106&r1=1163105&r2=1163106&view=diff
==============================================================================
--- zookeeper/trunk/src/c/src/zookeeper.c (original)
+++ zookeeper/trunk/src/c/src/zookeeper.c Tue Aug 30 07:01:48 2011
@@ -205,6 +205,19 @@ static __attribute__((unused)) void prin
 static void *SYNCHRONOUS_MARKER = (void*)&SYNCHRONOUS_MARKER;
 static int isValidPath(const char* path, const int flags);
 
+#ifdef _WINDOWS
+static int zookeeper_send(SOCKET s, const char* buf, int len)
+#else
+static ssize_t zookeeper_send(int s, const void* buf, size_t len)
+#endif
+{
+#ifdef __linux__
+  return send(s, buf, len, MSG_NOSIGNAL);
+#else
+  return send(s, buf, len, 0);
+#endif
+}
+
 const void *zoo_get_context(zhandle_t *zh)
 {
     return zh->context;
@@ -1013,7 +1026,7 @@ static int send_buffer(int fd, buffer_li
         /* we need to send the length at the beginning */
         int nlen = htonl(len);
         char *b = (char*)&nlen;
-        rc = send(fd, b + off, sizeof(nlen) - off, 0);
+        rc = zookeeper_send(fd, b + off, sizeof(nlen) - off);
         if (rc == -1) {
 #ifndef _WINDOWS
             if (errno != EAGAIN) {
@@ -1032,7 +1045,7 @@ static int send_buffer(int fd, buffer_li
     if (off >= 4) {
         /* want off to now represent the offset into the buffer */
         off -= sizeof(buff->len);
-        rc = send(fd, buff->buffer + off, len - off, 0);
+        rc = zookeeper_send(fd, buff->buffer + off, len - off);
         if (rc == -1) {
 #ifndef _WINDOWS
             if (errno != EAGAIN) {
@@ -1449,9 +1462,9 @@ static int prime_connection(zhandle_t *z
     req.lastZxidSeen = zh->last_zxid;
     hlen = htonl(len);
     /* We are running fast and loose here, but this string should fit in the initial buffer! */
-    rc=send(zh->fd, &hlen, sizeof(len), 0);
+    rc=zookeeper_send(zh->fd, &hlen, sizeof(len));
     serialize_prime_connect(&req, buffer_req);
-    rc=rc<0 ? rc : send(zh->fd, buffer_req, len, 0);
+    rc=rc<0 ? rc : zookeeper_send(zh->fd, buffer_req, len);
     if (rc<0) {
         return handle_socket_error_msg(zh, __LINE__, ZCONNECTIONLOSS,
                 "failed to send a handshake packet: %s", strerror(errno));