Update touch for batching.
authorBrian Aker <brian@tangent.org>
Tue, 27 Dec 2011 07:52:02 +0000 (23:52 -0800)
committerBrian Aker <brian@tangent.org>
Tue, 27 Dec 2011 07:52:02 +0000 (23:52 -0800)
libmemcached/touch.cc

index 1107139d4f2a2cd7c7a8f95a960bd4c6ce34f31c..ab1f70231dc317b20c64682a320200916b94e416 100644 (file)
@@ -42,15 +42,20 @@ static memcached_return_t ascii_touch(memcached_server_write_instance_st instanc
                                       const char *key, size_t key_length,
                                       time_t expiration)
 {
-  char buffer[21];
+  char expiration_buffer[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH +1];
+  int expiration_buffer_length= snprintf(expiration_buffer, sizeof(expiration_buffer), " %llu", (unsigned long long)expiration);
+  if (size_t(expiration_buffer_length) >= sizeof(expiration_buffer) or expiration_buffer_length < 0)
+  {
+    return memcached_set_error(*instance, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT, 
+                               memcached_literal_param("snprintf(MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH)"));
+  }
 
-  int buffer_length= snprintf(buffer, sizeof(buffer), " %u", uint32_t(expiration));
   struct libmemcached_io_vector_st vector[]=
   {
     { memcached_literal_param("touch ") },
     { memcached_array_string(instance->root->_namespace), memcached_array_size(instance->root->_namespace) },
     { key, key_length },
-    { buffer, buffer_length },
+    { expiration_buffer, expiration_buffer_length },
     { memcached_literal_param("\r\n") }
   };
 
@@ -137,7 +142,7 @@ memcached_return_t memcached_touch_by_key(memcached_st *ptr,
   }
 
   char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
-  rc= memcached_read_one_response(instance, buffer, sizeof(buffer), NULL);
+  rc= memcached_response(instance, buffer, sizeof(buffer), NULL);
 
   if (rc == MEMCACHED_SUCCESS or rc == MEMCACHED_NOTFOUND)
   {