Cleanup of linger call.
authorBrian Aker <brian@tangent.org>
Tue, 11 Dec 2007 02:34:49 +0000 (18:34 -0800)
committerBrian Aker <brian@tangent.org>
Tue, 11 Dec 2007 02:34:49 +0000 (18:34 -0800)
lib/memcached_connect.c
lib/memcached_io.c

index f4c80d5cc53d97e612f318a8694b825c2b7d6957..fd4518d59b24bb8a50707fbebf81c255399ed561 100644 (file)
@@ -145,31 +145,47 @@ static memcached_return tcp_connect(memcached_st *ptr, unsigned int server_key)
       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_NO_BLOCK)
+    {
+      int error;
+      struct linger linger;
+
+      linger.l_onoff= 1; 
+      linger.l_linger= 400; 
+      error= setsockopt(ptr->hosts[server_key].fd, SOL_SOCKET, SO_LINGER, 
+                        &linger, (socklen_t)sizeof(struct linger));
+      WATCHPOINT_ASSERT(error == 0);
+    }
+
     if (ptr->flags & MEM_TCP_NODELAY)
     {
       int flag= 1;
+      int error;
 
-      setsockopt(ptr->hosts[server_key].fd, IPPROTO_TCP, TCP_NODELAY, 
-                 &flag, (socklen_t)sizeof(int));
+      error= setsockopt(ptr->hosts[server_key].fd, IPPROTO_TCP, TCP_NODELAY, 
+                        &flag, (socklen_t)sizeof(int));
+      WATCHPOINT_ASSERT(error == 0);
     }
 
     if (ptr->send_size)
     {
-      setsockopt(ptr->hosts[server_key].fd, SOL_SOCKET, SO_SNDBUF, 
-                 &ptr->send_size, (socklen_t)sizeof(int));
+      int error;
+
+      error= setsockopt(ptr->hosts[server_key].fd, SOL_SOCKET, SO_SNDBUF, 
+                        &ptr->send_size, (socklen_t)sizeof(int));
+      WATCHPOINT_ASSERT(error == 0);
     }
 
     if (ptr->recv_size)
     {
-      setsockopt(ptr->hosts[server_key].fd, SOL_SOCKET, SO_SNDBUF, 
-                 &ptr->recv_size, (socklen_t)sizeof(int));
+      int error;
+
+      error= setsockopt(ptr->hosts[server_key].fd, SOL_SOCKET, SO_SNDBUF, 
+                        &ptr->recv_size, (socklen_t)sizeof(int));
+      WATCHPOINT_ASSERT(error == 0);
     }
 
     /* connect to server */
@@ -193,6 +209,7 @@ test_connect:
       }
       ptr->connected++;
     }
+
     WATCHPOINT_ASSERT(ptr->hosts[server_key].stack_responses == 0);
   }
 
index 85a27d962b3d4acc046e11c1bc9aca39b046db61..de3eda32875460018fa4aa320237197be0d40d53 100644 (file)
@@ -150,6 +150,19 @@ ssize_t memcached_io_write(memcached_st *ptr, unsigned int server_key,
 
 memcached_return memcached_io_close(memcached_st *ptr, unsigned int server_key)
 {
+  if (ptr->flags & MEM_NO_BLOCK && 0)
+  {
+    int sock_size;
+    int error;
+    socklen_t sock_length;
+
+    error= getsockopt(ptr->hosts[server_key].fd, IPPROTO_TCP, SO_LINGER,
+                      &sock_size, &sock_length);
+
+    WATCHPOINT_NUMBER(error);
+    WATCHPOINT_NUMBER(sock_size);
+  }
+
   close(ptr->hosts[server_key].fd);
 
   return MEMCACHED_SUCCESS;