Minor code code cleanup, plus modification to while() loop around poll in
[m6w6/libmemcached] / libmemcached / io.c
index 3a523213357aaf3c15a7c7f29ac3d472630c992e..17398aa37dd2bc54f790f6eec81b403b09456c69 100644 (file)
@@ -53,15 +53,30 @@ static memcached_return_t io_wait(memcached_server_instance_st *ptr,
   if (ptr->root->flags.no_block == false)
     timeout= -1;
 
-  error= poll(&fds, 1, timeout);
+  while (1)
+  {
+    error= poll(&fds, 1, timeout);
 
-  if (error == 1)
-    return MEMCACHED_SUCCESS;
-  else if (error == 0)
-    return MEMCACHED_TIMEOUT;
+    switch (error)
+    {
+    case 1:
+      return MEMCACHED_SUCCESS;
+    case 0:
+      return MEMCACHED_TIMEOUT;
+    case ERESTART:
+    case EINTR:
+      continue;
+    default:
+      ptr->cached_errno= error;
+      memcached_quit_server(ptr, 1);
+
+      return MEMCACHED_FAILURE;
+    }
+  }
 
   /* Imposssible for anything other then -1 */
   WATCHPOINT_ASSERT(error == -1);
+  ptr->cached_errno= error;
   memcached_quit_server(ptr, 1);
 
   return MEMCACHED_FAILURE;
@@ -127,20 +142,21 @@ static bool process_input_buffer(memcached_server_instance_st *ptr)
    */
     memcached_callback_st cb= *ptr->root->callbacks;
 
-    ptr->root->options.is_processing_input= true;
+    memcached_set_processing_input((memcached_st *)ptr->root, true);
 
     char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
     memcached_return_t error;
+    memcached_st *root= (memcached_st *)ptr->root;
     error= memcached_response(ptr, buffer, sizeof(buffer),
-                              &ptr->root->result);
+                              &root->result);
 
-    ptr->root->options.is_processing_input = false;
+    memcached_set_processing_input(root, false);
 
     if (error == MEMCACHED_SUCCESS)
     {
       for (unsigned int x= 0; x < cb.number_of_callback; x++)
       {
-        error= (*cb.callback[x])(ptr->root, &ptr->root->result, cb.context);
+        error= (*cb.callback[x])(ptr->root, &root->result, cb.context);
         if (error != MEMCACHED_SUCCESS)
           break;
       }
@@ -156,6 +172,7 @@ static bool process_input_buffer(memcached_server_instance_st *ptr)
 
 static inline void memcached_io_cork_push(memcached_server_st *ptr)
 {
+  (void)ptr;
 #ifdef CORK
   if (ptr->root->flags.cork == false || ptr->state.is_corked)
     return;
@@ -167,13 +184,12 @@ static inline void memcached_io_cork_push(memcached_server_st *ptr)
     ptr->state.is_corked= true;
 
   WATCHPOINT_ASSERT(ptr->state.is_corked == true);
-#else
-  (void)ptr;
 #endif
 }
 
 static inline void memcached_io_cork_pop(memcached_server_st *ptr)
 {
+  (void)ptr;
 #ifdef CORK
   if (ptr->root->flags.cork == false || ptr->state.is_corked == false)
     return;
@@ -185,12 +201,10 @@ static inline void memcached_io_cork_pop(memcached_server_st *ptr)
     ptr->state.is_corked= false;
 
   WATCHPOINT_ASSERT(ptr->state.is_corked == false);
-#else
-  (void)ptr;
 #endif
 }
 
-#ifdef UNUSED
+#if 0 // Dead code, this should be removed.
 void memcached_io_preread(memcached_st *ptr)
 {
   unsigned int x;
@@ -243,6 +257,7 @@ memcached_return_t memcached_io_read(memcached_server_instance_st *ptr,
           {
           case EAGAIN:
           case EINTR:
+          case ERESTART:
             if ((rc= io_wait(ptr, MEM_READ)) == MEMCACHED_SUCCESS)
               continue;
             /* fall through */
@@ -306,7 +321,7 @@ memcached_return_t memcached_io_read(memcached_server_instance_st *ptr,
 }
 
 ssize_t memcached_io_write(memcached_server_instance_st *ptr,
-                           const void *buffer, size_t length, char with_flush)
+                           const void *buffer, size_t length, bool with_flush)
 {
   size_t original_length;
   const char* buffer_ptr;