X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fdelete.cc;h=f5a60e33e0eb0b919927147a0796bd72f2d00c2a;hb=5ba025a6fda8479e8f38ab690b0f89d4d1c4ffc3;hp=6be7e224ec70e52ee1502098b7779ac1fda02f4d;hpb=54b757ae099fb3db5132bd8a84b99a9a85492af1;p=m6w6%2Flibmemcached diff --git a/libmemcached/delete.cc b/libmemcached/delete.cc index 6be7e224..f5a60e33 100644 --- a/libmemcached/delete.cc +++ b/libmemcached/delete.cc @@ -41,8 +41,7 @@ memcached_return_t memcached_delete(memcached_st *ptr, const char *key, size_t key_length, time_t expiration) { - return memcached_delete_by_key(ptr, key, key_length, - key, key_length, expiration); + return memcached_delete_by_key(ptr, key, key_length, key, key_length, expiration); } static inline memcached_return_t ascii_delete(memcached_st *ptr, @@ -50,71 +49,19 @@ static inline memcached_return_t ascii_delete(memcached_st *ptr, uint32_t , const char *key, size_t key_length, - uint64_t expiration, bool& reply, bool& flush) { - char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; - int send_length; - - if (expiration) - { - if ((instance->major_version == 1 and - instance->minor_version > 2) or - instance->major_version > 1) - { - return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, - memcached_literal_param("Memcached server version does not allow expiration of deleted items")); - } - else - { - /* ensure that we are connected, otherwise we might bump the - * command counter before connection */ - memcached_return_t rc; - if ((rc= memcached_connect(instance)) != MEMCACHED_SUCCESS) - { - WATCHPOINT_ERROR(rc); - return rc; - } - - if (instance->minor_version == 0) - { - if (reply == false or flush == false) - { - /* We might get out of sync with the server if we send this command - * to a server newer than 1.2.x.. enable reply and buffered mode. - */ - flush= true; - if (reply == false) - { - memcached_server_response_increment(instance); - } - reply= true; - } - } - - send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, - "delete %.*s%.*s %u%s\r\n", - memcached_print_array(ptr->_namespace), - (int) key_length, key, - (uint32_t)expiration, - reply ? "" : " noreply"); - } - } - else + struct libmemcached_io_vector_st vector[]= { - send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, - "delete %.*s%.*s%s\r\n", - memcached_print_array(ptr->_namespace), - (int)key_length, key, - reply ? "" : " noreply"); - } + { memcached_literal_param("delete ") }, + { memcached_array_string(ptr->_namespace), memcached_array_size(ptr->_namespace) }, + { key, key_length }, + { " noreply", reply ? 0 : memcached_literal_param_size(" noreply") }, + { memcached_literal_param("\r\n") } + }; - if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE || send_length < 0) - { - return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT, - memcached_literal_param("snprintf(MEMCACHED_DEFAULT_COMMAND_SIZE)")); - } + size_t send_length= io_vector_total_size(vector, 5); if (ptr->flags.use_udp and flush == false) { @@ -129,7 +76,8 @@ static inline memcached_return_t ascii_delete(memcached_st *ptr, } } - return memcached_do(instance, buffer, (size_t)send_length, flush); + /* Send command header */ + return memcached_vdo(instance, vector, 5, flush); } static inline memcached_return_t binary_delete(memcached_st *ptr, @@ -137,18 +85,11 @@ static inline memcached_return_t binary_delete(memcached_st *ptr, uint32_t server_key, const char *key, size_t key_length, - time_t expiration, bool& reply, bool& flush) { protocol_binary_request_delete request= {}; - // No expiration is supported in the binary protocol - if (expiration) - { - return MEMCACHED_INVALID_ARGUMENTS; - } - request.message.header.request.magic= PROTOCOL_BINARY_REQ; if (reply) { @@ -178,9 +119,9 @@ static inline memcached_return_t binary_delete(memcached_st *ptr, struct libmemcached_io_vector_st vector[]= { - { sizeof(request.bytes), request.bytes}, - { memcached_array_size(ptr->_namespace), memcached_array_string(ptr->_namespace) }, - { key_length, key }, + { request.bytes, sizeof(request.bytes) }, + { memcached_array_string(ptr->_namespace), memcached_array_size(ptr->_namespace) }, + { key, key_length } }; memcached_return_t rc= MEMCACHED_SUCCESS; @@ -236,6 +177,12 @@ memcached_return_t memcached_delete_by_key(memcached_st *ptr, { return rc; } + + if (expiration) + { + return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, + memcached_literal_param("Memcached server version does not allow expiration of deleted items")); + } // If a delete trigger exists, we need a response, so no buffering/noreply if (ptr->delete_trigger) @@ -264,11 +211,11 @@ memcached_return_t memcached_delete_by_key(memcached_st *ptr, if (ptr->flags.binary_protocol) { - rc= binary_delete(ptr, instance, server_key, key, key_length, expiration, reply, to_write); + rc= binary_delete(ptr, instance, server_key, key, key_length, reply, to_write); } else { - rc= ascii_delete(ptr, instance, server_key, key, key_length, expiration, reply, to_write); + rc= ascii_delete(ptr, instance, server_key, key, key_length, reply, to_write); } if (rc == MEMCACHED_SUCCESS)