Removed recent regression issue with close()
[m6w6/libmemcached] / lib / memcached_connect.c
index 672b1c23b65e5ce4f1d0c29c9502352186425d42..f4c80d5cc53d97e612f318a8694b825c2b7d6957 100644 (file)
@@ -1,13 +1,5 @@
 #include "common.h"
 
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <netinet/tcp.h>
-#include <netdb.h>
-#include <netinet/in.h>
-
 static memcached_return set_hostinfo(memcached_server_st *server)
 {
   struct addrinfo *ai;
@@ -140,17 +132,24 @@ static memcached_return tcp_connect(memcached_st *ptr, unsigned int server_key)
                                            use->ai_protocol)) < 0)
     {
       ptr->cached_errno= errno;
+      WATCHPOINT_ERRNO(errno);
       return MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE;
     }
 
-    /* For the moment, not getting a nonblocking mode will note be fatal */
+    /* For the moment, not getting a nonblocking mode will not be fatal */
     if (ptr->flags & MEM_NO_BLOCK)
     {
       int flags;
 
       flags= fcntl(ptr->hosts[server_key].fd, F_GETFL, 0);
       if (flags != -1)
+      {
         (void)fcntl(ptr->hosts[server_key].fd, F_SETFL, flags | O_NONBLOCK);
+
+        flags= 1;
+        setsockopt(ptr->hosts[server_key].fd, IPPROTO_TCP, SO_LINGER, 
+                   &flags, (socklen_t)sizeof(int));
+      }
     }
 
     if (ptr->flags & MEM_TCP_NODELAY)