Merge in version util.
[m6w6/libmemcached] / libmemcached / connect.c
index cb093d12a1ce5af1fecc0b5050e9d32877a830bc..a43de9563a89d2017b4658a3404abc8ad534bfd8 100644 (file)
@@ -105,6 +105,21 @@ static memcached_return_t set_socket_options(memcached_server_st *ptr)
   }
 #endif
 
+
+#if defined(__MACH__) && defined(__APPLE__) || defined(__FreeBSD__)
+  {
+    int set = 1;
+    int error= setsockopt(ptr->fd, SOL_SOCKET, SO_NOSIGPIPE, (void *)&set, sizeof(int));
+
+    // This is not considered a fatal error
+    if (error == -1)
+    {
+      WATCHPOINT_ERRNO(errno);
+      perror("setsockopt(SO_NOSIGPIPE)");
+    }
+  }
+#endif
+
   if (ptr->root->flags.no_block)
   {
     int error;
@@ -244,6 +259,7 @@ test_connect:
   }
 
   WATCHPOINT_ASSERT(ptr->fd != -1);
+
   return MEMCACHED_SUCCESS;
 }
 
@@ -300,7 +316,7 @@ static memcached_return_t network_connect(memcached_server_st *ptr)
           fds[0].events = POLLOUT;
 
           int timeout= ptr->root->connect_timeout;
-          if (ptr->root->flags.no_block == false)
+          if (ptr->root->flags.no_block == true)
             timeout= -1;
 
           size_t loop_max= 5;
@@ -314,6 +330,8 @@ static memcached_return_t network_connect(memcached_server_st *ptr)
               loop_max= 1;
               break;
             case 0:
+              if (loop_max==1) 
+                return MEMCACHED_TIMEOUT;
               continue;
               // A real error occurred and we need to completely bail
             default:
@@ -355,7 +373,7 @@ static memcached_return_t network_connect(memcached_server_st *ptr)
       }
 
 #ifdef LIBMEMCACHED_WITH_SASL_SUPPORT
-      if (ptr->fd != -1 && ptr->root->sasl.callbacks != NULL)
+      if (ptr->fd != -1 && ptr->root->sasl && ptr->root->sasl->callbacks)
       {
         memcached_return rc= memcached_sasl_authenticate_connection(ptr);
         if (rc != MEMCACHED_SUCCESS)