Additional fixes/test. We will now limit the hostname when adding it into
[awesomized/libmemcached] / libmemcached / behavior.c
index 2f5311e5a01ddac70d96cc9c36576983d3b66f79..da111351bee3a942c43f643e4f9861557478639c 100644 (file)
@@ -12,8 +12,6 @@
 #include "common.h"
 #include <time.h>
 #include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/tcp.h>
 
 static bool set_flag(uint64_t data)
 {
@@ -229,6 +227,9 @@ memcached_return_t memcached_behavior_set(memcached_st *ptr,
         }
       }
       break;
+  case MEMCACHED_BEHAVIOR_LOAD_FROM_FILE:
+    ptr->flags.load_from_file= set_flag(data);
+    break;
   case MEMCACHED_BEHAVIOR_MAX:
   default:
     /* Shouldn't get here */
@@ -315,11 +316,20 @@ uint64_t memcached_behavior_get(memcached_st *ptr,
         /* REFACTOR */
         /* We just try the first host, and if it is down we return zero */
         if ((memcached_connect(instance)) != MEMCACHED_SUCCESS)
-          return 0;
+        {
+          return EXIT_SUCCESS;
+        }
+
+        if (memcached_io_wait_for_write(instance) != MEMCACHED_SUCCESS)
+        {
+          return EXIT_SUCCESS;
+        }
 
-        if (getsockopt(instance->fd, SOL_SOCKET,
-                       SO_SNDBUF, &sock_size, &sock_length))
-          return 0; /* Zero means error */
+        if (getsockopt(instance->fd, SOL_SOCKET, SO_SNDBUF, &sock_size, &sock_length) < 0)
+        {
+          ptr->cached_errno= errno;
+          return EXIT_SUCCESS; /* Zero means error */
+        }
       }
 
       return (uint64_t) sock_size;
@@ -342,11 +352,20 @@ uint64_t memcached_behavior_get(memcached_st *ptr,
       {
         /* We just try the first host, and if it is down we return zero */
         if ((memcached_connect(instance)) != MEMCACHED_SUCCESS)
-          return 0;
+        {
+          return EXIT_SUCCESS;
+        }
 
-        if (getsockopt(instance->fd, SOL_SOCKET,
-                       SO_RCVBUF, &sock_size, &sock_length))
-          return 0; /* Zero means error */
+        if (memcached_io_wait_for_write(instance) != MEMCACHED_SUCCESS)
+        {
+          return EXIT_SUCCESS;
+        }
+
+        if (getsockopt(instance->fd, SOL_SOCKET, SO_RCVBUF, &sock_size, &sock_length) < 0)
+        {
+          ptr->cached_errno= errno;
+          return EXIT_SUCCESS; /* Zero means error */
+        }
 
       }
 
@@ -366,10 +385,12 @@ uint64_t memcached_behavior_get(memcached_st *ptr,
     return ptr->flags.cork;
   case MEMCACHED_BEHAVIOR_TCP_KEEPALIVE:
     return ptr->flags.tcp_keepalive;
+  case MEMCACHED_BEHAVIOR_LOAD_FROM_FILE:
+    return ptr->flags.load_from_file;
   case MEMCACHED_BEHAVIOR_MAX:
   default:
     WATCHPOINT_ASSERT(0); /* Programming mistake if it gets this far */
-    return 0;
+    return EXIT_SUCCESS;
   }
 
   /* NOTREACHED */