libhashkit: fix #25
[awesomized/libmemcached] / libmemcached / quit.cc
index 8b33255bd7b1abc73d8369d8d20e753db6686b64..5d17b3133e76375e92d8f88498ee73d52784e967 100644 (file)
@@ -38,7 +38,7 @@
 #include <libmemcached/common.h>
 
 namespace {
-  memcached_return_t send_quit_message(org::libmemcached::Instance* instance)
+  memcached_return_t send_quit_message(memcached_instance_st* instance)
   {
     memcached_return_t rc;
     if (instance->root->flags.binary_protocol)
@@ -70,7 +70,7 @@ namespace {
     return rc;
   }
 
-  void drain_instance(org::libmemcached::Instance* instance)
+  void drain_instance(memcached_instance_st* instance)
   {
     /* read until socket is closed, or there is an error
      * closing the socket before all data is read
@@ -93,6 +93,7 @@ namespace {
      * sent to the server.
      */
     instance->server_failure_counter= 0;
+    instance->server_timeout_counter= 0;
   }
 }
 
@@ -105,7 +106,7 @@ namespace {
   will force data to be completed.
 */
 
-void memcached_quit_server(org::libmemcached::Instance* instance, bool io_death)
+void memcached_quit_server(memcached_instance_st* instance, bool io_death)
 {
   if (instance->valid())
   {
@@ -120,24 +121,32 @@ void memcached_quit_server(org::libmemcached::Instance* instance, bool io_death)
 
   instance->close_socket();
 
-  if (io_death)
+  if (io_death and memcached_is_udp(instance->root))
   {
+    /*
+       If using UDP, we should stop using the server briefly on every IO
+       failure. If using TCP, it may be that the connection went down a
+       short while ago (e.g. the server failed) and we've only just
+       noticed, so we should only set the retry timeout on a connect
+       failure (which doesn't call this method).
+       */
     memcached_mark_server_for_timeout(instance);
   }
 }
 
-void send_quit(memcached_st *memc)
+void send_quit(Memcached *memc)
 {
   for (uint32_t x= 0; x < memcached_server_count(memc); x++)
   {
-    org::libmemcached::Instance* instance= memcached_instance_fetch(memc, x);
+    memcached_instance_st* instance= memcached_instance_fetch(memc, x);
 
     memcached_quit_server(instance, false);
   }
 }
 
-void memcached_quit(memcached_st *memc)
+void memcached_quit(memcached_st *shell)
 {
+  Memcached* memc= memcached2Memcached(shell);
   memcached_return_t rc;
   if (memcached_failed(rc= initialize_query(memc, true)))
   {