C++: double underscores are reserved
[awesomized/libmemcached] / src / libmemcached / io.cc
index 087ae60665da251fb71e00b192876d6c4e5a8646..1cc62e47d942d077f329d400761d5938f37db5c6 100644 (file)
 */
 
 #include "libmemcached/common.h"
-
-#ifdef HAVE_SYS_SOCKET_H
-#  include <sys/socket.h>
-#endif
+#include "p9y/poll.hpp"
 
 void initialize_binary_request(memcached_instance_st *server,
                                protocol_binary_request_header &header) {
@@ -56,18 +53,20 @@ static bool repack_input_buffer(memcached_instance_st *instance) {
           memcached_set_error(*instance, MEMCACHED_CONNECTION_FAILURE, MEMCACHED_AT);
         } else {
           switch (get_socket_errno()) {
-          case EINTR: continue;
+          case EINTR:
+            continue;
 
 #if EWOULDBLOCK != EAGAIN
           case EWOULDBLOCK:
 #endif
           case EAGAIN:
-#ifdef __linux
+#ifdef HAVE_ERESTART
           case ERESTART:
 #endif
             break; // No IO is fine, we can just move on
 
-          default: memcached_set_errno(*instance, get_socket_errno(), MEMCACHED_AT);
+          default:
+            memcached_set_errno(*instance, get_socket_errno(), MEMCACHED_AT);
           }
         }
 
@@ -99,7 +98,7 @@ static bool process_input_buffer(memcached_instance_st *instance) {
    ** We might be able to process some of the response messages if we
    ** have a callback set up
    */
-  if (instance->root->callbacks != NULL) {
+  if (instance->root->callbacks) {
     /*
      * We might have responses... try to read them out and fire
      * callbacks
@@ -210,10 +209,11 @@ static memcached_return_t io_wait(memcached_instance_st *instance, const short e
     int local_errno = get_socket_errno(); // We cache in case memcached_quit_server() modifies errno
     assert_msg(active_fd == -1, "poll() returned an unexpected value");
     switch (local_errno) {
-#ifdef __linux
+#ifdef ERESTART
     case ERESTART:
 #endif
-    case EINTR: continue;
+    case EINTR:
+      continue;
 
     case EFAULT:
     case ENOMEM:
@@ -293,7 +293,8 @@ static bool io_flush(memcached_instance_st *instance, const bool with_flush,
       WATCHPOINT_NUMBER(get_socket_errno());
 #endif
       switch (get_socket_errno()) {
-      case ENOBUFS: continue;
+      case ENOBUFS:
+        continue;
 
 #if EWOULDBLOCK != EAGAIN
       case EWOULDBLOCK:
@@ -366,7 +367,7 @@ static memcached_return_t _io_fill(memcached_instance_st *instance) {
       case EWOULDBLOCK:
 #endif
       case EAGAIN:
-#ifdef __linux
+#ifdef HAVE_ERESTART
       case ERESTART:
 #endif
       {
@@ -495,7 +496,7 @@ memcached_return_t memcached_io_slurp(memcached_instance_st *instance) {
       case EWOULDBLOCK:
 #endif
       case EAGAIN:
-#ifdef __linux
+#ifdef ERESTART
       case ERESTART:
 #endif
         if (memcached_success(io_wait(instance, POLLIN))) {
@@ -515,7 +516,8 @@ memcached_return_t memcached_io_slurp(memcached_instance_st *instance) {
       case EINVAL:
       case EFAULT:
       case ECONNREFUSED:
-      default: return MEMCACHED_CONNECTION_FAILURE; // We want this!
+      default:
+        return MEMCACHED_CONNECTION_FAILURE; // We want this!
       }
     }
   } while (data_read > 0);
@@ -694,7 +696,8 @@ memcached_instance_st *memcached_io_get_readable_server(Memcached *memc, memcach
   case -1:
     memcached_set_errno(*memc, get_socket_errno(), MEMCACHED_AT);
     /* FALLTHROUGH */
-  case 0: break;
+  case 0:
+    break;
 
   default:
     for (nfds_t x = 0; x < host_index; ++x) {