Committing for 0.17. Cleanups and one bad WATCHPOINT removed.
[m6w6/libmemcached] / lib / memcached_storage.c
index 38d6d0db3ca689ccb75d3717bdef30930ab488a9..0b5a73e10b3d45a0912f13c52ca47babf5cfdae7 100644 (file)
@@ -57,15 +57,15 @@ static inline memcached_return memcached_send(memcached_st *ptr,
   char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
   unsigned int server_key;
 
-  WATCHPOINT_ASSERT(!(value == NULL && value_length > 0));
-  WATCHPOINT_ASSERT(!(value && value_length == 0));
-
-  if (key_length == 0)
+  unlikely (key_length == 0)
     return MEMCACHED_NO_KEY_PROVIDED;
 
-  if (ptr->number_of_hosts == 0)
+  unlikely (ptr->number_of_hosts == 0)
     return MEMCACHED_NO_SERVERS;
 
+  if ((ptr->flags & MEM_VERIFY_KEY) && (memcachd_key_test(&key, &key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED))
+    return MEMCACHED_BAD_KEY_PROVIDED;
+
   server_key= memcached_generate_hash(ptr, master_key, master_key_length);
 
   if (cas)
@@ -86,11 +86,11 @@ static inline memcached_return memcached_send(memcached_st *ptr,
     goto error;
   }
 
-  rc=  memcached_do(ptr, server_key, buffer, write_length, 0);
+  rc=  memcached_do(&ptr->hosts[server_key], buffer, write_length, 0);
   if (rc != MEMCACHED_SUCCESS)
     goto error;
 
-  if ((sent_length= memcached_io_write(ptr, server_key, value, value_length, 0)) == -1)
+  if ((sent_length= memcached_io_write(&ptr->hosts[server_key], value, value_length, 0)) == -1)
   {
     rc= MEMCACHED_WRITE_FAILURE;
     goto error;
@@ -101,7 +101,7 @@ static inline memcached_return memcached_send(memcached_st *ptr,
   else
     to_write= 1;
 
-  if ((sent_length= memcached_io_write(ptr, server_key, "\r\n", 2, to_write)) == -1)
+  if ((sent_length= memcached_io_write(&ptr->hosts[server_key], "\r\n", 2, to_write)) == -1)
   {
     rc= MEMCACHED_WRITE_FAILURE;
     goto error;
@@ -110,7 +110,7 @@ static inline memcached_return memcached_send(memcached_st *ptr,
   if (to_write == 0)
     return MEMCACHED_BUFFERED;
 
-  rc= memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL, server_key);
+  rc= memcached_response(&ptr->hosts[server_key], buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
 
   if (rc == MEMCACHED_STORED)
     return MEMCACHED_SUCCESS;
@@ -118,7 +118,7 @@ static inline memcached_return memcached_send(memcached_st *ptr,
     return rc;
 
 error:
-  memcached_io_reset(ptr, server_key);
+  memcached_io_reset(&ptr->hosts[server_key]);
 
   return rc;
 }
@@ -203,7 +203,7 @@ memcached_return memcached_cas(memcached_st *ptr,
   memcached_return rc;
   rc= memcached_send(ptr, key, key_length, 
                      key, key_length, value, value_length,
-                     expiration, flags, cas, APPEND_OP);
+                     expiration, flags, cas, CAS_OP);
   return rc;
 }
 
@@ -294,6 +294,6 @@ memcached_return memcached_cas_by_key(memcached_st *ptr,
   memcached_return rc;
   rc= memcached_send(ptr, key, key_length, 
                      key, key_length, value, value_length,
-                     expiration, flags, cas, APPEND_OP);
+                     expiration, flags, cas, CAS_OP);
   return rc;
 }