Fix connect with timeouts
[awesomized/libmemcached] / libmemcached / memcached_get.c
index a84ef4f2a12c2416c49748e93580f61e875bc779..2cc40151b4bcf4911549af13eb9e6b10e692c62a 100644 (file)
@@ -250,7 +250,7 @@ static memcached_return binary_mget_by_key(memcached_st *ptr,
                                            unsigned int number_of_keys)
 {
   memcached_return rc= MEMCACHED_NOTFOUND;
-  int x;
+  uint32_t x;
 
   int flush= number_of_keys == 1;
 
@@ -274,13 +274,22 @@ static memcached_return binary_mget_by_key(memcached_st *ptr,
         continue;
     }
      
-    protocol_binary_request_getk request= {0};
+    protocol_binary_request_getk request= {.bytes= {0}};
     request.message.header.request.magic= PROTOCOL_BINARY_REQ;
     if (number_of_keys == 1)
       request.message.header.request.opcode= PROTOCOL_BINARY_CMD_GETK;
     else
       request.message.header.request.opcode= PROTOCOL_BINARY_CMD_GETKQ;
 
+    memcached_return vk;
+    vk= memcached_validate_key_length(key_length[x],
+                                      ptr->flags & MEM_BINARY_PROTOCOL);
+    unlikely (vk != MEMCACHED_SUCCESS) {
+      if (x > 0)
+        memcached_io_reset(&ptr->hosts[server_key]);
+      return vk;
+    }
+
     request.message.header.request.keylen= htons((uint16_t)key_length[x]);
     request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
     request.message.header.request.bodylen= htonl(key_length[x]);
@@ -302,7 +311,7 @@ static memcached_return binary_mget_by_key(memcached_st *ptr,
     /*
      * Send a noop command to flush the buffers
      */
-    protocol_binary_request_noop request= {0};
+    protocol_binary_request_noop request= {.bytes= {0}};
     request.message.header.request.magic= PROTOCOL_BINARY_REQ;
     request.message.header.request.opcode= PROTOCOL_BINARY_CMD_NOOP;
     request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;