Minor code code cleanup, plus modification to while() loop around poll in
[m6w6/libmemcached] / libmemcached / quit.c
index 3c117ade71d79b64c916fb53f3a250456ee5b214..ebeffa5c0bd2f134a039ed881fa78f87152f5e67 100644 (file)
@@ -24,12 +24,15 @@ void memcached_quit_server(memcached_server_st *ptr, uint8_t io_death)
         request.message.header.request.magic = PROTOCOL_BINARY_REQ;
         request.message.header.request.opcode = PROTOCOL_BINARY_CMD_QUIT;
         request.message.header.request.datatype = PROTOCOL_BINARY_RAW_BYTES;
-        rc= memcached_do(ptr, request.bytes, sizeof(request.bytes), 1);
+        rc= memcached_do(ptr, request.bytes, sizeof(request.bytes), true);
       }
       else
-        rc= memcached_do(ptr, "quit\r\n", 6, 1);
+      {
+        rc= memcached_do(ptr, "quit\r\n", sizeof("quit\r\n"), true);
+      }
 
       WATCHPOINT_ASSERT(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_FETCH_NOTFINISHED);
+      (void)rc; // Shut up ICC
 
       /* read until socket is closed, or there is an error
        * closing the socket before all data is read
@@ -50,28 +53,35 @@ void memcached_quit_server(memcached_server_st *ptr, uint8_t io_death)
       ptr->server_failure_counter= 0;
     }
     memcached_io_close(ptr);
-
-    ptr->fd= -1;
-    ptr->write_buffer_offset= (size_t) ((ptr->type == MEMCACHED_CONNECTION_UDP) ? UDP_DATAGRAM_HEADER_LENGTH : 0);
-    ptr->read_buffer_length= 0;
-    ptr->read_ptr= ptr->read_buffer;
-    memcached_server_response_reset(ptr);
   }
 
-  if(io_death) ptr->server_failure_counter++;
+  ptr->fd= -1;
+  ptr->write_buffer_offset= (size_t) ((ptr->type == MEMCACHED_CONNECTION_UDP) ? UDP_DATAGRAM_HEADER_LENGTH : 0);
+  ptr->read_buffer_length= 0;
+  ptr->read_ptr= ptr->read_buffer;
+  memcached_server_response_reset(ptr);
+
+  if(io_death)
+  {
+    ptr->server_failure_counter++;
+  }
 }
 
 void memcached_quit(memcached_st *ptr)
 {
-  unsigned int x;
+  uint32_t x;
 
-  if (ptr->hosts == NULL ||
-      ptr->number_of_hosts == 0)
+  if (memcached_server_count(ptr) == 0)
     return;
 
-  if (ptr->hosts && ptr->number_of_hosts)
+  if (memcached_server_count(ptr))
   {
-    for (x= 0; x < ptr->number_of_hosts; x++)
-      memcached_quit_server(&ptr->hosts[x], 0);
+    for (x= 0; x < memcached_server_count(ptr); x++)
+    {
+      memcached_server_instance_st *instance=
+        memcached_server_instance_fetch(ptr, x);
+
+      memcached_quit_server(instance, 0);
+    }
   }
 }