diff options
Diffstat (limited to 'libmemcached')
-rw-r--r-- | libmemcached/auto.cc | 2 | ||||
-rw-r--r-- | libmemcached/common.h | 3 | ||||
-rw-r--r-- | libmemcached/fetch.cc | 58 | ||||
-rw-r--r-- | libmemcached/get.cc | 2 | ||||
-rw-r--r-- | libmemcached/include.am | 4 | ||||
-rw-r--r-- | libmemcached/memcached.cc | 2 | ||||
-rw-r--r-- | libmemcached/memcached.h | 39 | ||||
-rw-r--r-- | libmemcached/memcached.hpp | 40 | ||||
-rw-r--r-- | libmemcached/memcached/protocol_binary.h | 2 | ||||
-rw-r--r-- | libmemcached/response.cc | 69 | ||||
-rw-r--r-- | libmemcached/result.cc | 108 | ||||
-rw-r--r-- | libmemcached/result.h | 61 | ||||
-rw-r--r-- | libmemcached/util.h | 40 |
13 files changed, 167 insertions, 263 deletions
diff --git a/libmemcached/auto.cc b/libmemcached/auto.cc index 685528f2..111445fb 100644 --- a/libmemcached/auto.cc +++ b/libmemcached/auto.cc @@ -59,7 +59,7 @@ static void auto_response(memcached_instance_st* instance, const bool reply, me } else { - *value= instance->root->result.numeric_value; + *value= instance->root->result.impl()->numeric_value; } } diff --git a/libmemcached/common.h b/libmemcached/common.h index 897b0969..8e899b70 100644 --- a/libmemcached/common.h +++ b/libmemcached/common.h @@ -111,9 +111,10 @@ # include "libmemcached/windows.hpp" #endif -#include <libmemcached-1.0/memcached.h> +#include <libmemcached-1.2/memcached.h> #include "libmemcached/watchpoint.h" #include "libmemcached/is.h" + typedef struct memcached_st Memcached; #ifdef HAVE_POLL_H diff --git a/libmemcached/fetch.cc b/libmemcached/fetch.cc index 7f677d02..f6fefe66 100644 --- a/libmemcached/fetch.cc +++ b/libmemcached/fetch.cc @@ -42,14 +42,14 @@ char *memcached_fetch(memcached_st *shell, char *key, size_t *key_length, uint32_t *flags, memcached_return_t *error) { - Memcached* ptr= memcached2Memcached(shell); + Memcached* memc= memcached2Memcached(shell); memcached_return_t unused; if (error == NULL) { error= &unused; } - if (memcached_is_udp(ptr)) + if (memcached_is_udp(memc)) { if (value_length) { @@ -75,8 +75,8 @@ char *memcached_fetch(memcached_st *shell, char *key, size_t *key_length, return NULL; } - memcached_result_st *result_buffer= &ptr->result; - result_buffer= memcached_fetch_result(ptr, result_buffer, error); + memcached_result_st *result_buffer= &memc->result; + result_buffer= memcached_fetch_result(memc, result_buffer, error); if (result_buffer == NULL or memcached_failed(*error)) { WATCHPOINT_ASSERT(result_buffer == NULL); @@ -105,12 +105,12 @@ char *memcached_fetch(memcached_st *shell, char *key, size_t *key_length, if (value_length) { - *value_length= memcached_string_length(&result_buffer->value); + *value_length= memcached_string_length(&result_buffer->impl()->value); } if (key) { - if (result_buffer->key_length > MEMCACHED_MAX_KEY) + if (result_buffer->impl()->key_length > MEMCACHED_MAX_KEY) { *error= MEMCACHED_KEY_TOO_BIG; if (value_length) @@ -136,22 +136,22 @@ char *memcached_fetch(memcached_st *shell, char *key, size_t *key_length, return NULL; } - strncpy(key, result_buffer->item_key, result_buffer->key_length); // For the binary protocol we will cut off the key :( + strncpy(key, result_buffer->impl()->item_key, result_buffer->impl()->key_length); // For the binary protocol we will cut off the key :( if (key_length) { - *key_length= result_buffer->key_length; + *key_length= result_buffer->impl()->key_length; } } if (flags) { - *flags= result_buffer->item_flags; + *flags= result_buffer->impl()->item_flags; } - return memcached_string_take_value(&result_buffer->value); + return memcached_string_take_value(&result_buffer->impl()->value); } -memcached_result_st *memcached_fetch_result(memcached_st *ptr, +memcached_result_st *memcached_fetch_result(memcached_st *memc, memcached_result_st *result, memcached_return_t *error) { @@ -161,13 +161,13 @@ memcached_result_st *memcached_fetch_result(memcached_st *ptr, error= &unused; } - if (ptr == NULL) + if (memc == NULL) { *error= MEMCACHED_INVALID_ARGUMENTS; return NULL; } - if (memcached_is_udp(ptr)) + if (memcached_is_udp(memc)) { *error= MEMCACHED_NOT_SUPPORTED; return NULL; @@ -177,9 +177,9 @@ memcached_result_st *memcached_fetch_result(memcached_st *ptr, { // If we have already initialized (ie it is in use) our internal, we // create one. - if (memcached_is_initialized(&ptr->result)) + if (memcached_is_initialized(&memc->result)) { - if ((result= memcached_result_create(ptr, NULL)) == NULL) + if ((result= memcached_result_create(memc, NULL)) == NULL) { *error= MEMCACHED_MEMORY_ALLOCATION_FAILURE; return NULL; @@ -187,14 +187,14 @@ memcached_result_st *memcached_fetch_result(memcached_st *ptr, } else { - result= memcached_result_create(ptr, &ptr->result); + result= memcached_result_create(memc, &memc->result); } } *error= MEMCACHED_MAXIMUM_RETURN; // We use this to see if we ever go into the loop memcached_instance_st *server; memcached_return_t read_ret= MEMCACHED_SUCCESS; - while ((server= memcached_io_get_readable_server(ptr, read_ret))) + while ((server= memcached_io_get_readable_server(memc, read_ret))) { char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; *error= memcached_response(server, buffer, sizeof(buffer), result); @@ -205,7 +205,7 @@ memcached_result_st *memcached_fetch_result(memcached_st *ptr, } else if (*error == MEMCACHED_SUCCESS) { - result->count++; + result->impl()->count++; return result; } else if (*error == MEMCACHED_END) @@ -218,11 +218,11 @@ memcached_result_st *memcached_fetch_result(memcached_st *ptr, } } - if (*error == MEMCACHED_NOTFOUND and result->count) + if (*error == MEMCACHED_NOTFOUND and result->impl()->count) { *error= MEMCACHED_END; } - else if (*error == MEMCACHED_MAXIMUM_RETURN and result->count) + else if (*error == MEMCACHED_MAXIMUM_RETURN and result->impl()->count) { *error= MEMCACHED_END; } @@ -234,7 +234,7 @@ memcached_result_st *memcached_fetch_result(memcached_st *ptr, { *error= MEMCACHED_END; } - else if (result->count == 0) + else if (result->impl()->count == 0) { *error= MEMCACHED_NOTFOUND; } @@ -246,8 +246,8 @@ memcached_result_st *memcached_fetch_result(memcached_st *ptr, } else { - result->count= 0; - memcached_string_reset(&result->value); + result->impl()->count= 0; + memcached_string_reset(&result->impl()->value); } return NULL; @@ -258,12 +258,12 @@ memcached_return_t memcached_fetch_execute(memcached_st *shell, void *context, uint32_t number_of_callbacks) { - Memcached* ptr= memcached2Memcached(shell); - memcached_result_st *result= &ptr->result; + Memcached* memc= memcached2Memcached(shell); + memcached_result_st *result= &memc->result; memcached_return_t rc; bool some_errors= false; - while ((result= memcached_fetch_result(ptr, result, &rc))) + while ((result= memcached_fetch_result(memc, result, &rc))) { if (memcached_failed(rc) and rc == MEMCACHED_NOTFOUND) { @@ -271,18 +271,18 @@ memcached_return_t memcached_fetch_execute(memcached_st *shell, } else if (memcached_failed(rc)) { - memcached_set_error(*ptr, rc, MEMCACHED_AT); + memcached_set_error(*memc, rc, MEMCACHED_AT); some_errors= true; continue; } for (uint32_t x= 0; x < number_of_callbacks; x++) { - memcached_return_t ret= (*callback[x])(ptr, result, context); + memcached_return_t ret= (*callback[x])(memc, result, context); if (memcached_failed(ret)) { some_errors= true; - memcached_set_error(*ptr, ret, MEMCACHED_AT); + memcached_set_error(*memc, ret, MEMCACHED_AT); break; } } diff --git a/libmemcached/get.cc b/libmemcached/get.cc index 1f7e775c..65a1dcad 100644 --- a/libmemcached/get.cc +++ b/libmemcached/get.cc @@ -160,7 +160,7 @@ char *memcached_get_by_key(memcached_st *shell, *error= rc; *value_length= memcached_result_length(result_ptr); *flags= memcached_result_flags(result_ptr); - char *result_value= memcached_string_take_value(&result_ptr->value); + char *result_value= memcached_string_take_value(&result_ptr->impl()->value); memcached_result_free(result_ptr); return result_value; diff --git a/libmemcached/include.am b/libmemcached/include.am index 0aabc248..c6e1c6d6 100644 --- a/libmemcached/include.am +++ b/libmemcached/include.am @@ -9,10 +9,6 @@ include libmemcached/csl/include.am EXTRA_DIST+= libmemcached/libmemcached_probes.d EXTRA_DIST+= libmemcached/memcached/README.txt -nobase_include_HEADERS+= libmemcached/memcached.h -nobase_include_HEADERS+= libmemcached/memcached.hpp -nobase_include_HEADERS+= libmemcached/util.h - noinst_HEADERS+= libmemcached/array.h noinst_HEADERS+= libmemcached/assert.hpp noinst_HEADERS+= libmemcached/backtrace.hpp diff --git a/libmemcached/memcached.cc b/libmemcached/memcached.cc index a3c6a679..e1519d1e 100644 --- a/libmemcached/memcached.cc +++ b/libmemcached/memcached.cc @@ -58,7 +58,7 @@ static inline bool _memcached_init(Memcached *self) self->flags.tcp_nodelay= false; self->flags.use_sort_hosts= false; self->flags.use_udp= false; - self->flags.verify_key= false; + self->flags.verify_key= true; self->flags.tcp_keepalive= false; self->flags.is_aes= false; self->flags.is_fetching_version= false; diff --git a/libmemcached/memcached.h b/libmemcached/memcached.h deleted file mode 100644 index a45077ee..00000000 --- a/libmemcached/memcached.h +++ /dev/null @@ -1,39 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Libmemcached library - * - * Copyright (C) 2011 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -#include <libmemcached-1.0/memcached.h> diff --git a/libmemcached/memcached.hpp b/libmemcached/memcached.hpp deleted file mode 100644 index d38e6d24..00000000 --- a/libmemcached/memcached.hpp +++ /dev/null @@ -1,40 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Libmemcached library - * - * Copyright (C) 2011 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -#include <libmemcached-1.0/memcached.hpp> - diff --git a/libmemcached/memcached/protocol_binary.h b/libmemcached/memcached/protocol_binary.h index 51e2c422..ff9d6373 100644 --- a/libmemcached/memcached/protocol_binary.h +++ b/libmemcached/memcached/protocol_binary.h @@ -36,7 +36,7 @@ #ifndef PROTOCOL_BINARY_H #define PROTOCOL_BINARY_H -#include <libmemcachedprotocol-0.0/vbucket.h> +#include <libmemcached-1.2/memcached/vbucket.h> /** * \addtogroup Protocol diff --git a/libmemcached/response.cc b/libmemcached/response.cc index c01d5089..f382671d 100644 --- a/libmemcached/response.cc +++ b/libmemcached/response.cc @@ -60,8 +60,8 @@ static memcached_return_t textual_value_fetch(memcached_instance_st* instance, /* We load the key */ { - char *key= result->item_key; - result->key_length= 0; + char *key= result->impl()->item_key; + result->impl()->key_length= 0; for (ptrdiff_t prefix_length= memcached_array_size(instance->root->_namespace); !(iscntrl(*string_ptr) || isspace(*string_ptr)) ; string_ptr++) { @@ -69,12 +69,12 @@ static memcached_return_t textual_value_fetch(memcached_instance_st* instance, { *key= *string_ptr; key++; - result->key_length++; + result->impl()->key_length++; } else prefix_length--; } - result->item_key[result->key_length]= 0; + result->impl()->item_key[result->impl()->key_length]= 0; } if (end_ptr == string_ptr) @@ -90,8 +90,9 @@ static memcached_return_t textual_value_fetch(memcached_instance_st* instance, } for (next_ptr= string_ptr; isdigit(*string_ptr); string_ptr++) {}; + errno= 0; - result->item_flags= (uint32_t) strtoul(next_ptr, &string_ptr, 10); + result->impl()->item_flags= (uint32_t) strtoul(next_ptr, &string_ptr, 10); if (errno != 0 or end_ptr == string_ptr) { @@ -123,9 +124,11 @@ static memcached_return_t textual_value_fetch(memcached_instance_st* instance, else { string_ptr++; + for (next_ptr= string_ptr; isdigit(*string_ptr); string_ptr++) {}; + errno= 0; - result->item_cas= strtoull(next_ptr, &string_ptr, 10); + result->impl()->item_cas= strtoull(next_ptr, &string_ptr, 10); } if (errno != 0 or end_ptr < string_ptr) @@ -134,13 +137,13 @@ static memcached_return_t textual_value_fetch(memcached_instance_st* instance, } /* We add two bytes so that we can walk the \r\n */ - if (memcached_failed(memcached_string_check(&result->value, value_length +2))) + if (memcached_failed(memcached_string_check(&result->impl()->value, value_length +2))) { return memcached_set_error(*instance, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT); } { - char *value_ptr= memcached_string_value_mutable(&result->value); + char *value_ptr= memcached_string_value_mutable(&result->impl()->value); /* We read the \r\n into the string since not doing so is more cycles then the waster of memory to do so. @@ -169,10 +172,10 @@ static memcached_return_t textual_value_fetch(memcached_instance_st* instance, /* This next bit blows the API, but this is internal....*/ { char *char_ptr; - char_ptr= memcached_string_value_mutable(&result->value);; + char_ptr= memcached_string_value_mutable(&result->impl()->value); char_ptr[value_length]= 0; char_ptr[value_length +1]= 0; - memcached_string_set_length(&result->value, value_length); + memcached_string_set_length(&result->impl()->value, value_length); } if (memcached_is_encrypted(instance->root) and memcached_result_length(result)) @@ -453,24 +456,24 @@ static memcached_return_t textual_read_one_response(memcached_instance_st* insta if (auto_return_value == ULLONG_MAX and errno == ERANGE) { - result->numeric_value= UINT64_MAX; + result->impl()->numeric_value= UINT64_MAX; return memcached_set_error(*instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT, memcached_literal_param("Numeric response was out of range")); } else if (errno == EINVAL) { - result->numeric_value= UINT64_MAX; + result->impl()->numeric_value= UINT64_MAX; return memcached_set_error(*instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT, memcached_literal_param("Numeric response was out of range")); } else if (errno != 0) { - result->numeric_value= UINT64_MAX; + result->impl()->numeric_value= UINT64_MAX; return memcached_set_error(*instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT, memcached_literal_param("Numeric response was out of range")); } - result->numeric_value= uint64_t(auto_return_value); + result->impl()->numeric_value= uint64_t(auto_return_value); WATCHPOINT_STRING(buffer); return MEMCACHED_SUCCESS; @@ -536,53 +539,53 @@ static memcached_return_t binary_read_one_response(memcached_instance_st* instan { uint16_t keylen= header.response.keylen; memcached_result_reset(result); - result->item_cas= header.response.cas; + result->impl()->item_cas= header.response.cas; - if ((rc= memcached_safe_read(instance, &result->item_flags, sizeof (result->item_flags))) != MEMCACHED_SUCCESS) + if ((rc= memcached_safe_read(instance, &result->impl()->item_flags, sizeof (result->impl()->item_flags))) != MEMCACHED_SUCCESS) { WATCHPOINT_ERROR(rc); return MEMCACHED_UNKNOWN_READ_FAILURE; } - result->item_flags= ntohl(result->item_flags); + result->impl()->item_flags= ntohl(result->impl()->item_flags); bodylen -= header.response.extlen; - result->key_length= keylen; - if (memcached_failed(rc= memcached_safe_read(instance, result->item_key, keylen))) + result->impl()->key_length= keylen; + if (memcached_failed(rc= memcached_safe_read(instance, result->impl()->item_key, keylen))) { WATCHPOINT_ERROR(rc); return MEMCACHED_UNKNOWN_READ_FAILURE; } // Only bother with doing this if key_length > 0 - if (result->key_length) + if (result->impl()->key_length) { - if (memcached_array_size(instance->root->_namespace) and memcached_array_size(instance->root->_namespace) >= result->key_length) + if (memcached_array_size(instance->root->_namespace) and memcached_array_size(instance->root->_namespace) >= result->impl()->key_length) { return memcached_set_error(*instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT); } if (memcached_array_size(instance->root->_namespace)) { - result->key_length-= memcached_array_size(instance->root->_namespace); - memmove(result->item_key, result->item_key +memcached_array_size(instance->root->_namespace), result->key_length); + result->impl()->key_length-= memcached_array_size(instance->root->_namespace); + memmove(result->impl()->item_key, result->impl()->item_key +memcached_array_size(instance->root->_namespace), result->impl()->key_length); } } bodylen -= keylen; - if (memcached_failed(memcached_string_check(&result->value, bodylen))) + if (memcached_failed(memcached_string_check(&result->impl()->value, bodylen))) { return MEMCACHED_MEMORY_ALLOCATION_FAILURE; } - char *vptr= memcached_string_value_mutable(&result->value); + char *vptr= memcached_string_value_mutable(&result->impl()->value); if (memcached_failed(rc= memcached_safe_read(instance, vptr, bodylen))) { WATCHPOINT_ERROR(rc); return MEMCACHED_UNKNOWN_READ_FAILURE; } - memcached_string_set_length(&result->value, bodylen); + memcached_string_set_length(&result->impl()->value, bodylen); } break; @@ -591,18 +594,18 @@ static memcached_return_t binary_read_one_response(memcached_instance_st* instan { if (bodylen != sizeof(uint64_t)) { - result->numeric_value= UINT64_MAX; + result->impl()->numeric_value= UINT64_MAX; return memcached_set_error(*instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT); } uint64_t val; if ((rc= memcached_safe_read(instance, &val, sizeof(val))) != MEMCACHED_SUCCESS) { - result->numeric_value= UINT64_MAX; + result->impl()->numeric_value= UINT64_MAX; return MEMCACHED_UNKNOWN_READ_FAILURE; } - result->numeric_value= memcached_ntohll(val); + result->impl()->numeric_value= memcached_ntohll(val); } break; @@ -731,20 +734,20 @@ static memcached_return_t binary_read_one_response(memcached_instance_st* instan case PROTOCOL_BINARY_CMD_SASL_STEP: { memcached_result_reset(result); - result->item_cas= header.response.cas; + result->impl()->item_cas= header.response.cas; - if (memcached_string_check(&result->value, + if (memcached_string_check(&result->impl()->value, bodylen) != MEMCACHED_SUCCESS) return MEMCACHED_MEMORY_ALLOCATION_FAILURE; - char *vptr= memcached_string_value_mutable(&result->value); + char *vptr= memcached_string_value_mutable(&result->impl()->value); if ((rc= memcached_safe_read(instance, vptr, bodylen)) != MEMCACHED_SUCCESS) { WATCHPOINT_ERROR(rc); return MEMCACHED_UNKNOWN_READ_FAILURE; } - memcached_string_set_length(&result->value, bodylen); + memcached_string_set_length(&result->impl()->value, bodylen); } break; default: diff --git a/libmemcached/result.cc b/libmemcached/result.cc index 6fa507b2..a00664e1 100644 --- a/libmemcached/result.cc +++ b/libmemcached/result.cc @@ -43,98 +43,60 @@ to addjust the entire API. */ #include <libmemcached/common.h> - -static inline void _result_init(memcached_result_st *self, - Memcached *memc) -{ - self->item_flags= 0; - self->item_expiration= 0; - self->key_length= 0; - self->item_cas= 0; - self->root= memc; - self->numeric_value= UINT64_MAX; - self->count= 0; - self->item_key[0]= 0; -} +#include <memory> memcached_result_st *memcached_result_create(const memcached_st *shell, - memcached_result_st *ptr) + memcached_result_st *result_shell) { const Memcached* memc= memcached2Memcached(shell); - - /* Saving malloc calls :) */ - if (ptr) - { - ptr->options.is_allocated= false; - } - else + Result *result= new (std::nothrow) Result(result_shell, memc); + if (result) { - ptr= libmemcached_xmalloc(memc, memcached_result_st); - - if (not ptr) - { - return NULL; - } - - ptr->options.is_allocated= true; + return result->shell(); } - ptr->options.is_initialized= true; - - _result_init(ptr, (memcached_st *)memc); - - WATCHPOINT_SET(ptr->value.options.is_initialized= false); - memcached_string_create((memcached_st*)memc, &ptr->value, 0); - WATCHPOINT_ASSERT_INITIALIZED(&ptr->value); - WATCHPOINT_ASSERT(ptr->value.string == NULL); - - return ptr; + return NULL; } -void memcached_result_reset(memcached_result_st *ptr) +void memcached_result_reset(memcached_result_st *result) { - ptr->key_length= 0; - memcached_string_reset(&ptr->value); - ptr->item_flags= 0; - ptr->item_cas= 0; - ptr->item_expiration= 0; - ptr->numeric_value= UINT64_MAX; + result->impl()->key_length= 0; + memcached_string_reset(&result->impl()->value); + result->impl()->item_flags= 0; + result->impl()->item_cas= 0; + result->impl()->item_expiration= 0; + result->impl()->numeric_value= UINT64_MAX; } -void memcached_result_free(memcached_result_st *ptr) +void memcached_result_free(memcached_result_st* result) { - if (ptr == NULL) + if (result) { - return; - } + memcached_string_free(&result->impl()->value); - memcached_string_free(&ptr->value); - ptr->numeric_value= UINT64_MAX; + bool cleanup= memcached_is_allocated(result); + delete result->impl(); - if (memcached_is_allocated(ptr)) - { - WATCHPOINT_ASSERT(ptr->root); // Without a root, that means that result was not properly initialized. - libmemcached_free(ptr->root, ptr); - } - else - { - ptr->count= 0; - ptr->options.is_initialized= false; + if (cleanup == false) + { + memcached_set_initialized(result, false); + result->impl(NULL); + } } } void memcached_result_reset_value(memcached_result_st *ptr) { - memcached_string_reset(&ptr->value); + memcached_string_reset(&ptr->impl()->value); } memcached_return_t memcached_result_set_value(memcached_result_st *ptr, const char *value, size_t length) { - if (memcached_failed(memcached_string_append(&ptr->value, value, length))) + if (memcached_failed(memcached_string_append(&ptr->impl()->value, value, length))) { - return memcached_set_errno(*ptr->root, errno, MEMCACHED_AT); + return memcached_set_errno(*(ptr->impl())->root, errno, MEMCACHED_AT); } return MEMCACHED_SUCCESS; @@ -142,48 +104,48 @@ memcached_return_t memcached_result_set_value(memcached_result_st *ptr, const char *memcached_result_key_value(const memcached_result_st *self) { - return self->key_length ? self->item_key : NULL; + return self->impl()->key_length ? self->impl()->item_key : NULL; } size_t memcached_result_key_length(const memcached_result_st *self) { - return self->key_length; + return self->impl()->key_length; } const char *memcached_result_value(const memcached_result_st *self) { - const memcached_string_st *sptr= &self->value; + const memcached_string_st *sptr= &self->impl()->value; return memcached_string_value(sptr); } size_t memcached_result_length(const memcached_result_st *self) { - const memcached_string_st *sptr= &self->value; + const memcached_string_st *sptr= &self->impl()->value; return memcached_string_length(sptr); } char *memcached_result_take_value(memcached_result_st *self) { - memcached_string_st *sptr= &self->value; + memcached_string_st *sptr= &self->impl()->value; return memcached_string_take_value(sptr); } uint32_t memcached_result_flags(const memcached_result_st *self) { - return self->item_flags; + return self->impl()->item_flags; } uint64_t memcached_result_cas(const memcached_result_st *self) { - return self->item_cas; + return self->impl()->item_cas; } void memcached_result_set_flags(memcached_result_st *self, uint32_t flags) { - self->item_flags= flags; + self->impl()->item_flags= flags; } void memcached_result_set_expiration(memcached_result_st *self, time_t expiration) { - self->item_expiration= expiration; + self->impl()->item_expiration= expiration; } diff --git a/libmemcached/result.h b/libmemcached/result.h index 624ff5a8..315bd1ed 100644 --- a/libmemcached/result.h +++ b/libmemcached/result.h @@ -36,4 +36,65 @@ */ #pragma once + +#include "libmemcached/string.hpp" + +struct Result { + struct { + bool is_allocated; + bool is_initialized; + } options; + uint32_t item_flags; + time_t item_expiration; + size_t key_length; + uint64_t item_cas; + struct memcached_st *root; + memcached_string_st value; + uint64_t numeric_value; + uint64_t count; + char item_key[MEMCACHED_MAX_KEY]; + /* Add result callback function */ + + Result(memcached_result_st* shell_, const struct memcached_st* memc_) : + item_flags(0), + item_expiration(0), + key_length(0), + item_cas(0), + root(const_cast<memcached_st*>(memc_)), + numeric_value(UINT64_MAX), + count(0), + _shell(shell_) + { + item_key[0]= 0; + + if (shell_) + { + memcached_set_allocated(_shell, false); + } + else + { + _shell= &_owned_shell; + memcached_set_allocated(_shell, true); + } + + _shell->impl(this); + memcached_set_initialized(_shell, true); + + memcached_string_create((memcached_st*)root, &value, 0); + } + + ~Result() + { + } + + memcached_result_st* shell() + { + return _shell; + } + +private: + memcached_result_st* _shell; + memcached_result_st _owned_shell; +}; + void memcached_result_reset_value(memcached_result_st *ptr); diff --git a/libmemcached/util.h b/libmemcached/util.h deleted file mode 100644 index 03ed6da5..00000000 --- a/libmemcached/util.h +++ /dev/null @@ -1,40 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Libmemcached library - * - * Copyright (C) 2011 Data Differential, http://datadifferential.com/ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -#include <libmemcachedutil-1.0/util.h> - |