Updating for vector interface.
[awesomized/libmemcached] / libmemcached / auto.c
index fde81d47e3da67ceb19265a2d42cb1f203fee8e0..16e65b863a3ad85b4b987d8f596d0e2c3c4eeda4 100644 (file)
@@ -56,7 +56,12 @@ static memcached_return_t text_incr_decr(memcached_st *ptr,
     use it. We still called memcached_response() though since it
     worked its magic for non-blocking IO.
   */
-  if (!strncmp(buffer, "ERROR\r\n", 7))
+  if (! strncmp(buffer, "ERROR\r\n", 7))
+  {
+    *value= 0;
+    rc= MEMCACHED_PROTOCOL_ERROR;
+  } 
+  else if (! strncmp(buffer, "CLIENT_ERROR\r\n", 14))
   {
     *value= 0;
     rc= MEMCACHED_PROTOCOL_ERROR;
@@ -103,18 +108,23 @@ static memcached_return_t binary_incr_decr(memcached_st *ptr, uint8_t cmd,
 
   request.message.header.request.magic= PROTOCOL_BINARY_REQ;
   request.message.header.request.opcode= cmd;
-  request.message.header.request.keylen= htons((uint16_t) key_length);
+  request.message.header.request.keylen= htons((uint16_t)(key_length + ptr->prefix_key_length));
   request.message.header.request.extlen= 20;
   request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
-  request.message.header.request.bodylen= htonl((uint32_t) (key_length + request.message.header.request.extlen));
+  request.message.header.request.bodylen= htonl((uint32_t)(key_length + ptr->prefix_key_length +  request.message.header.request.extlen));
   request.message.body.delta= htonll(offset);
   request.message.body.initial= htonll(initial);
   request.message.body.expiration= htonl((uint32_t) expiration);
 
+  struct __write_vector_st vector[]= 
+  {
+    { .length= ptr->prefix_key_length, .buffer= ptr->prefix_key },
+    { .length= key_length, .buffer= key }
+  }; 
+
   memcached_return_t rc;
-  if (((rc= memcached_do(instance, request.bytes,
-                         sizeof(request.bytes), false)) != MEMCACHED_SUCCESS) ||
-      (memcached_io_write(instance, key, key_length, true) == -1))
+  if (((rc= memcached_do(instance, request.bytes, sizeof(request.bytes), false)) != MEMCACHED_SUCCESS) ||
+      (memcached_io_writev(instance, vector, 2, true) == -1))
   {
     memcached_io_reset(instance);
     return (rc == MEMCACHED_SUCCESS) ? MEMCACHED_WRITE_FAILURE : rc;