From 9cde1fdc1bbd49775c75a83e44c942354129f1d5 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Mon, 2 May 2011 18:20:00 -0700 Subject: [PATCH] Fixed up a few more places where we set the error in the memcached root. --- libmemcached/auto.cc | 6 +- libmemcached/error.cc | 14 +- libmemcached/error.h | 5 +- libmemcached/hosts.cc | 2 +- libmemcached/include.am | 9 + libmemcached/initialize_query.cc | 2 +- libmemcached/memcached.cc | 7 +- libmemcached/memcached.hpp | 285 ++++++++++++------------------- libmemcached/options.cc | 10 +- libmemcached/prefix_key.cc | 6 +- libmemcached/response.cc | 6 +- libmemcached/result.h | 39 ++++- libmemcached/return.h | 4 +- libmemcached/server.h | 43 +++-- libmemcached/string.h | 8 +- 15 files changed, 232 insertions(+), 214 deletions(-) diff --git a/libmemcached/auto.cc b/libmemcached/auto.cc index 42c3b5f0..804b8e0c 100644 --- a/libmemcached/auto.cc +++ b/libmemcached/auto.cc @@ -51,7 +51,7 @@ static memcached_return_t text_incr_decr(memcached_st *ptr, bool no_reply= ptr->flags.no_reply; if (ptr->flags.verify_key && (memcached_key_test((const char **)&key, &key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED)) - return MEMCACHED_BAD_KEY_PROVIDED; + return memcached_set_error(ptr, MEMCACHED_BAD_KEY_PROVIDED); server_key= memcached_generate_hash_with_redistribution(ptr, group_key, group_key_length); instance= memcached_server_instance_fetch(ptr, server_key); @@ -63,7 +63,7 @@ static memcached_return_t text_incr_decr(memcached_st *ptr, (int)key_length, key, offset, no_reply ? " noreply" : ""); if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE || send_length < 0) - return MEMCACHED_WRITE_FAILURE; + return memcached_set_error(ptr, MEMCACHED_WRITE_FAILURE); rc= memcached_do(instance, buffer, (size_t)send_length, true); if (no_reply || rc != MEMCACHED_SUCCESS) @@ -114,7 +114,7 @@ static memcached_return_t binary_incr_decr(memcached_st *ptr, uint8_t cmd, bool no_reply= ptr->flags.no_reply; if (memcached_server_count(ptr) == 0) - return memcached_set_error(ptr, MEMCACHED_NO_SERVERS, NULL); + return memcached_set_error(ptr, MEMCACHED_NO_SERVERS); server_key= memcached_generate_hash_with_redistribution(ptr, group_key, group_key_length); instance= memcached_server_instance_fetch(ptr, server_key); diff --git a/libmemcached/error.cc b/libmemcached/error.cc index 02169a28..947d4d41 100644 --- a/libmemcached/error.cc +++ b/libmemcached/error.cc @@ -92,10 +92,10 @@ memcached_return_t memcached_set_error_string(memcached_st *memc, memcached_retu memcached_string_t tmp; tmp.c_str= str; tmp.size= length; - return memcached_set_error(memc, rc, &tmp); + return memcached_set_error_message(memc, rc, &tmp); } -memcached_return_t memcached_set_error(memcached_st *memc, memcached_return_t rc, memcached_string_t *str) +memcached_return_t memcached_set_error_message(memcached_st *memc, memcached_return_t rc, memcached_string_t *str) { if (rc == MEMCACHED_SUCCESS) return MEMCACHED_SUCCESS; @@ -105,6 +105,16 @@ memcached_return_t memcached_set_error(memcached_st *memc, memcached_return_t rc return rc; } +memcached_return_t memcached_set_error(memcached_st *memc, memcached_return_t rc) +{ + if (rc == MEMCACHED_SUCCESS) + return MEMCACHED_SUCCESS; + + _set(memc, NULL, rc, 0); + + return rc; +} + memcached_return_t memcached_set_errno(memcached_st *memc, int local_errno, memcached_string_t *str) { _set(memc, str, MEMCACHED_ERRNO, local_errno); diff --git a/libmemcached/error.h b/libmemcached/error.h index c8b94806..a3b1f73d 100644 --- a/libmemcached/error.h +++ b/libmemcached/error.h @@ -42,7 +42,10 @@ extern "C" { #endif LIBMEMCACHED_LOCAL - memcached_return_t memcached_set_error(memcached_st *memc, memcached_return_t rc, memcached_string_t *str); + memcached_return_t memcached_set_error(memcached_st *memc, memcached_return_t rc); + +LIBMEMCACHED_LOCAL + memcached_return_t memcached_set_error_message(memcached_st *memc, memcached_return_t rc, memcached_string_t *str); LIBMEMCACHED_LOCAL memcached_return_t memcached_set_error_string(memcached_st *memc, memcached_return_t rc, const char *str, size_t length); diff --git a/libmemcached/hosts.cc b/libmemcached/hosts.cc index 7527cfbd..885a79b7 100644 --- a/libmemcached/hosts.cc +++ b/libmemcached/hosts.cc @@ -345,7 +345,7 @@ memcached_return_t memcached_server_push(memcached_st *ptr, const memcached_serv list[x].port, list[x].weight, list[x].type); if (! instance) { - return memcached_set_error(ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, NULL); + return memcached_set_error(ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE); } ptr->number_of_hosts++; } diff --git a/libmemcached/include.am b/libmemcached/include.am index 28c5513a..fe3c5fcd 100644 --- a/libmemcached/include.am +++ b/libmemcached/include.am @@ -78,6 +78,15 @@ noinst_LTLIBRARIES+= libmemcached/libmemcachedinternal.la libmemcached_libmemcachedinternal_la_SOURCES= \ libmemcached/error.cc \ libmemcached/string.cc +libmemcached_libmemcachedinternal_la_CFLAGS= \ + ${AM_CFLAGS} \ + ${NO_CONVERSION} \ + -DBUILDING_LIBMEMCACHED + +libmemcached_libmemcachedinternal_la_CXXFLAGS= \ + ${AM_CXXFLAGS} \ + ${NO_CONVERSION} \ + -DBUILDING_LIBMEMCACHED lib_LTLIBRARIES+= libmemcached/libmemcached.la libmemcached_libmemcached_la_CFLAGS= \ diff --git a/libmemcached/initialize_query.cc b/libmemcached/initialize_query.cc index 31a15fbc..09402ac3 100644 --- a/libmemcached/initialize_query.cc +++ b/libmemcached/initialize_query.cc @@ -50,7 +50,7 @@ memcached_return_t initialize_query(memcached_st *self) if (memcached_server_count(self) == 0) { - return memcached_set_error(self, MEMCACHED_NO_SERVERS, NULL); + return memcached_set_error(self, MEMCACHED_NO_SERVERS); } return MEMCACHED_SUCCESS; diff --git a/libmemcached/memcached.cc b/libmemcached/memcached.cc index 820efa50..a1551cd2 100644 --- a/libmemcached/memcached.cc +++ b/libmemcached/memcached.cc @@ -226,19 +226,22 @@ memcached_st *memcached_create(memcached_st *ptr) memcached_st *memcached(const char *string, size_t length) { - if (! length || ! string) + if ((not length and string) or (length and not string)) { errno= EINVAL; return NULL; } memcached_st *self= memcached_create(NULL); - if (! self) + if (not self) { errno= ENOMEM; return NULL; } + if (not length) + return self; + memcached_return_t rc; rc= memcached_parse_configuration(self, string, length); diff --git a/libmemcached/memcached.hpp b/libmemcached/memcached.hpp index b0985715..3bc1d227 100644 --- a/libmemcached/memcached.hpp +++ b/libmemcached/memcached.hpp @@ -35,67 +35,39 @@ class Memcache { public: - Memcache() : - servers_list(), - memc(), - result() + Memcache() { - memcached_create(&memc); + memc= memcached("", 0); } - Memcache(const std::string &in_servers_list) - : - servers_list(in_servers_list), - memc(), - result() + Memcache(const std::string &config) { - memcached_create(&memc); - init(); + memc= memcached(config.c_str(), config.size()); } - Memcache(const std::string &hostname, - in_port_t port) - : - servers_list(), - memc(), - result() + Memcache(const std::string &hostname, in_port_t port) { - memcached_create(&memc); - - servers_list.append(hostname); - servers_list.append(":"); - std::ostringstream strsmt; - strsmt << port; - servers_list.append(strsmt.str()); - - init(); + memc= memcached("", 0); + if (memc) + memcached_server_add(memc, hostname.c_str(), port); } Memcache(memcached_st *clone) - : - servers_list(), - memc(), - result() { - memcached_clone(&memc, clone); + memc= memcached_clone(NULL, clone); } Memcache(const Memcache &rhs) - : - servers_list(rhs.servers_list), - memc(), - result() { - memcached_clone(&memc, const_cast(&rhs.getImpl())); - init(); + memc= memcached_clone(NULL, rhs.getImpl()); } Memcache &operator=(const Memcache &rhs) { if (this != &rhs) { - memcached_clone(&memc, const_cast(&rhs.getImpl())); - init(); + memcached_free(memc); + memc= memcached_clone(NULL, rhs.getImpl()); } return *this; @@ -103,29 +75,13 @@ public: ~Memcache() { - memcached_free(&memc); - } - - void init() - { - memcached_server_st *servers; - servers= memcached_servers_parse(servers_list.c_str()); - memcached_server_push(&memc, servers); - memcached_server_free(servers); - } - - /** - * Get the internal memcached_st * - */ - memcached_st &getImpl() - { - return memc; + memcached_free(memc); } /** * Get the internal memcached_st * */ - const memcached_st &getImpl() const + const memcached_st *getImpl() const { return memc; } @@ -145,38 +101,23 @@ public: bool setBehavior(memcached_behavior_t flag, uint64_t data) { - memcached_return_t rc; - rc= memcached_behavior_set(&memc, flag, data); - return (rc == MEMCACHED_SUCCESS); - } - - uint64_t getBehavior(memcached_behavior_t flag) { - return memcached_behavior_get(&memc, flag); + return (memcached_success(memcached_behavior_set(memc, flag, data))); } - /** - * Return the string which contains the list of memcached servers being - * used. - * - * @return a std::string containing the list of memcached servers - */ - const std::string getServersList() const + uint64_t getBehavior(memcached_behavior_t flag) { - return servers_list; + return memcached_behavior_get(memc, flag); } /** - * Set the list of memcached servers to use. + * Configure the memcache object * - * @param[in] in_servers_list list of servers + * @param[in] in_config configuration * @return true on success; false otherwise */ - bool setServers(const std::string &in_servers_list) + bool configure(const std::string &configuration) { - servers_list.assign(in_servers_list); - init(); - - return (memcached_server_count(&memc)); + return (memcached_success(memcached_parse_configuration(memc, configuration.c_str(), configuration.size()))); } /** @@ -190,7 +131,7 @@ public: { memcached_return_t rc; - rc= memcached_server_add(&memc, server_name.c_str(), port); + rc= memcached_server_add(memc, server_name.c_str(), port); return (rc == MEMCACHED_SUCCESS); } @@ -233,7 +174,7 @@ public: size_t key_length= 0; memcached_return_t rc; uint32_t flags= 0; - char *value= memcached_fetch(&memc, ret_key, &key_length, + char *value= memcached_fetch(memc, ret_key, &key_length, &value_length, &flags, &rc); if (value && ret_val.empty()) { @@ -264,7 +205,7 @@ public: memcached_return_t rc; size_t value_length= 0; - char *value= memcached_get(&memc, key.c_str(), key.length(), + char *value= memcached_get(memc, key.c_str(), key.length(), &value_length, &flags, &rc); if (value != NULL && ret_val.empty()) { @@ -296,7 +237,7 @@ public: memcached_return_t rc; size_t value_length= 0; - char *value= memcached_get_by_key(&memc, + char *value= memcached_get_by_key(memc, master_key.c_str(), master_key.length(), key.c_str(), key.length(), &value_length, &flags, &rc); @@ -345,8 +286,7 @@ public: */ if (! real_keys.empty()) { - memcached_return_t rc= memcached_mget(&memc, &real_keys[0], &key_len[0], - real_keys.size()); + memcached_return_t rc= memcached_mget(memc, &real_keys[0], &key_len[0], real_keys.size()); return (rc == MEMCACHED_SUCCESS); } @@ -369,10 +309,10 @@ public: time_t expiration, uint32_t flags) { - memcached_return_t rc= memcached_set(&memc, - key.c_str(), key.length(), - &value[0], value.size(), - expiration, flags); + memcached_return_t rc= memcached_set(memc, + key.c_str(), key.length(), + &value[0], value.size(), + expiration, flags); return (rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); } @@ -393,12 +333,12 @@ public: time_t expiration, uint32_t flags) { - memcached_return_t rc= memcached_set_by_key(&memc, master_key.c_str(), - master_key.length(), - key.c_str(), key.length(), - &value[0], value.size(), - expiration, - flags); + memcached_return_t rc= memcached_set_by_key(memc, master_key.c_str(), + master_key.length(), + key.c_str(), key.length(), + &value[0], value.size(), + expiration, + flags); return (rc == MEMCACHED_SUCCESS); } @@ -474,8 +414,8 @@ public: */ bool increment(const std::string &key, uint32_t offset, uint64_t *value) { - memcached_return_t rc= memcached_increment(&memc, key.c_str(), key.length(), - offset, value); + memcached_return_t rc= memcached_increment(memc, key.c_str(), key.length(), + offset, value); return (rc == MEMCACHED_SUCCESS); } @@ -491,9 +431,9 @@ public: */ bool decrement(const std::string &key, uint32_t offset, uint64_t *value) { - memcached_return_t rc= memcached_decrement(&memc, key.c_str(), - key.length(), - offset, value); + memcached_return_t rc= memcached_decrement(memc, key.c_str(), + key.length(), + offset, value); return (rc == MEMCACHED_SUCCESS); } @@ -508,8 +448,8 @@ public: */ bool add(const std::string &key, const std::vector &value) { - memcached_return_t rc= memcached_add(&memc, key.c_str(), key.length(), - &value[0], value.size(), 0, 0); + memcached_return_t rc= memcached_add(memc, key.c_str(), key.length(), + &value[0], value.size(), 0, 0); return (rc == MEMCACHED_SUCCESS); } @@ -527,14 +467,14 @@ public: const std::string &key, const std::vector &value) { - memcached_return_t rc= memcached_add_by_key(&memc, - master_key.c_str(), - master_key.length(), - key.c_str(), - key.length(), - &value[0], - value.size(), - 0, 0); + memcached_return_t rc= memcached_add_by_key(memc, + master_key.c_str(), + master_key.length(), + key.c_str(), + key.length(), + &value[0], + value.size(), + 0, 0); return (rc == MEMCACHED_SUCCESS); } @@ -548,9 +488,9 @@ public: */ bool replace(const std::string &key, const std::vector &value) { - memcached_return_t rc= memcached_replace(&memc, key.c_str(), key.length(), - &value[0], value.size(), - 0, 0); + memcached_return_t rc= memcached_replace(memc, key.c_str(), key.length(), + &value[0], value.size(), + 0, 0); return (rc == MEMCACHED_SUCCESS); } @@ -568,14 +508,14 @@ public: const std::string &key, const std::vector &value) { - memcached_return_t rc= memcached_replace_by_key(&memc, - master_key.c_str(), - master_key.length(), - key.c_str(), - key.length(), - &value[0], - value.size(), - 0, 0); + memcached_return_t rc= memcached_replace_by_key(memc, + master_key.c_str(), + master_key.length(), + key.c_str(), + key.length(), + &value[0], + value.size(), + 0, 0); return (rc == MEMCACHED_SUCCESS); } @@ -588,8 +528,8 @@ public: */ bool prepend(const std::string &key, const std::vector &value) { - memcached_return_t rc= memcached_prepend(&memc, key.c_str(), key.length(), - &value[0], value.size(), 0, 0); + memcached_return_t rc= memcached_prepend(memc, key.c_str(), key.length(), + &value[0], value.size(), 0, 0); return (rc == MEMCACHED_SUCCESS); } @@ -607,15 +547,15 @@ public: const std::string &key, const std::vector &value) { - memcached_return_t rc= memcached_prepend_by_key(&memc, - master_key.c_str(), - master_key.length(), - key.c_str(), - key.length(), - &value[0], - value.size(), - 0, - 0); + memcached_return_t rc= memcached_prepend_by_key(memc, + master_key.c_str(), + master_key.length(), + key.c_str(), + key.length(), + &value[0], + value.size(), + 0, + 0); return (rc == MEMCACHED_SUCCESS); } @@ -628,7 +568,7 @@ public: */ bool append(const std::string &key, const std::vector &value) { - memcached_return_t rc= memcached_append(&memc, + memcached_return_t rc= memcached_append(memc, key.c_str(), key.length(), &value[0], @@ -651,7 +591,7 @@ public: const std::string &key, const std::vector &value) { - memcached_return_t rc= memcached_append_by_key(&memc, + memcached_return_t rc= memcached_append_by_key(memc, master_key.c_str(), master_key.length(), key.c_str(), @@ -674,9 +614,9 @@ public: const std::vector &value, uint64_t cas_arg) { - memcached_return_t rc= memcached_cas(&memc, key.c_str(), key.length(), - &value[0], value.size(), - 0, 0, cas_arg); + memcached_return_t rc= memcached_cas(memc, key.c_str(), key.length(), + &value[0], value.size(), + 0, 0, cas_arg); return (rc == MEMCACHED_SUCCESS); } @@ -695,14 +635,14 @@ public: const std::vector &value, uint64_t cas_arg) { - memcached_return_t rc= memcached_cas_by_key(&memc, - master_key.c_str(), - master_key.length(), - key.c_str(), - key.length(), - &value[0], - value.size(), - 0, 0, cas_arg); + memcached_return_t rc= memcached_cas_by_key(memc, + master_key.c_str(), + master_key.length(), + key.c_str(), + key.length(), + &value[0], + value.size(), + 0, 0, cas_arg); return (rc == MEMCACHED_SUCCESS); } @@ -714,7 +654,7 @@ public: */ bool remove(const std::string &key) { - memcached_return_t rc= memcached_delete(&memc, key.c_str(), key.length(), 0); + memcached_return_t rc= memcached_delete(memc, key.c_str(), key.length(), 0); return (rc == MEMCACHED_SUCCESS); } @@ -727,10 +667,10 @@ public: */ bool remove(const std::string &key, time_t expiration) { - memcached_return_t rc= memcached_delete(&memc, - key.c_str(), - key.length(), - expiration); + memcached_return_t rc= memcached_delete(memc, + key.c_str(), + key.length(), + expiration); return (rc == MEMCACHED_SUCCESS); } @@ -744,12 +684,12 @@ public: bool removeByKey(const std::string &master_key, const std::string &key) { - memcached_return_t rc= memcached_delete_by_key(&memc, - master_key.c_str(), - master_key.length(), - key.c_str(), - key.length(), - 0); + memcached_return_t rc= memcached_delete_by_key(memc, + master_key.c_str(), + master_key.length(), + key.c_str(), + key.length(), + 0); return (rc == MEMCACHED_SUCCESS); } @@ -765,12 +705,12 @@ public: const std::string &key, time_t expiration) { - memcached_return_t rc= memcached_delete_by_key(&memc, - master_key.c_str(), - master_key.length(), - key.c_str(), - key.length(), - expiration); + memcached_return_t rc= memcached_delete_by_key(memc, + master_key.c_str(), + master_key.length(), + key.c_str(), + key.length(), + expiration); return (rc == MEMCACHED_SUCCESS); } @@ -783,7 +723,7 @@ public: */ bool flush(time_t expiration) { - memcached_return_t rc= memcached_flush(&memc, expiration); + memcached_return_t rc= memcached_flush(memc, expiration); return (rc == MEMCACHED_SUCCESS); } @@ -810,7 +750,7 @@ public: &stats_map) { memcached_return_t rc; - memcached_stat_st *stats= memcached_stat(&memc, NULL, &rc); + memcached_stat_st *stats= memcached_stat(memc, NULL, &rc); if (rc != MEMCACHED_SUCCESS && rc != MEMCACHED_SOME_ERRORS) @@ -818,7 +758,7 @@ public: return false; } - uint32_t server_count= memcached_server_count(&memc); + uint32_t server_count= memcached_server_count(memc); /* * For each memcached server, construct a std::map for its stats and add @@ -827,7 +767,7 @@ public: for (uint32_t x= 0; x < server_count; x++) { memcached_server_instance_st instance= - memcached_server_instance_by_position(&memc, x); + memcached_server_instance_by_position(memc, x); std::ostringstream strstm; std::string server_name(memcached_server_name(instance)); server_name.append(":"); @@ -838,10 +778,10 @@ public: char **list= NULL; char **ptr= NULL; - list= memcached_stat_get_keys(&memc, &stats[x], &rc); + list= memcached_stat_get_keys(memc, &stats[x], &rc); for (ptr= list; *ptr; ptr++) { - char *value= memcached_stat_get_value(&memc, &stats[x], *ptr, &rc); + char *value= memcached_stat_get_value(memc, &stats[x], *ptr, &rc); server_stats[*ptr]= value; free(value); } @@ -850,15 +790,12 @@ public: free(list); } - memcached_stat_free(&memc, stats); + memcached_stat_free(memc, stats); return true; } private: - - std::string servers_list; - memcached_st memc; - memcached_result_st result; + memcached_st *memc; }; } diff --git a/libmemcached/options.cc b/libmemcached/options.cc index 55299559..f15a45ee 100644 --- a/libmemcached/options.cc +++ b/libmemcached/options.cc @@ -119,9 +119,9 @@ memcached_return_t libmemcached_check_configuration(const char *option_string, s memcached_return_t memcached_parse_configuration(memcached_st *self, char const *option_string, size_t length) { WATCHPOINT_ASSERT(self); - if (! self) + if (not self) { - return memcached_set_error(self, MEMCACHED_INVALID_ARGUMENTS, NULL); + return memcached_set_error(self, MEMCACHED_INVALID_ARGUMENTS); } memcached_return_t rc; @@ -140,11 +140,11 @@ void memcached_set_configuration_file(memcached_st *self, const char *filename, memcached_return_t memcached_parse_configure_file(memcached_st *self, const char *filename, size_t filename_length) { - if (! self) - return memcached_set_error(self, MEMCACHED_INVALID_ARGUMENTS, NULL); + if (not self) + return memcached_set_error(self, MEMCACHED_INVALID_ARGUMENTS); if (! filename || filename_length == 0) - return memcached_set_error(self, MEMCACHED_INVALID_ARGUMENTS, NULL); + return memcached_set_error(self, MEMCACHED_INVALID_ARGUMENTS); memcached_string_t tmp; tmp.c_str= filename; diff --git a/libmemcached/prefix_key.cc b/libmemcached/prefix_key.cc index 526f5fac..6bfc8374 100644 --- a/libmemcached/prefix_key.cc +++ b/libmemcached/prefix_key.cc @@ -42,16 +42,16 @@ memcached_return_t memcached_set_prefix_key(memcached_st *self, const char *key, if (key && key_length) { if (memcached_key_test((const char **)&key, &key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED) - return memcached_set_error(self, MEMCACHED_BAD_KEY_PROVIDED, NULL); + return memcached_set_error(self, MEMCACHED_BAD_KEY_PROVIDED); if ((key_length > MEMCACHED_PREFIX_KEY_MAX_SIZE -1)) - return memcached_set_error(self, MEMCACHED_KEY_TOO_BIG, NULL); + return memcached_set_error(self, MEMCACHED_KEY_TOO_BIG); memcached_array_free(self->prefix_key); self->prefix_key= memcached_strcpy(self, key, key_length); if (! self->prefix_key) - return memcached_set_error(self, MEMCACHED_MEMORY_ALLOCATION_FAILURE, NULL); + return memcached_set_error(self, MEMCACHED_MEMORY_ALLOCATION_FAILURE); } else { diff --git a/libmemcached/response.cc b/libmemcached/response.cc index 4035a5b9..3c996f94 100644 --- a/libmemcached/response.cc +++ b/libmemcached/response.cc @@ -122,7 +122,7 @@ static memcached_return_t textual_value_fetch(memcached_server_write_instance_st memcached_return_t rrc; if (ptr->root->flags.use_udp) - return MEMCACHED_NOT_SUPPORTED; + return memcached_set_error((memcached_st *)ptr->root, MEMCACHED_NOT_SUPPORTED); WATCHPOINT_ASSERT(ptr->root); end_ptr= buffer + MEMCACHED_DEFAULT_COMMAND_SIZE; @@ -201,7 +201,7 @@ static memcached_return_t textual_value_fetch(memcached_server_write_instance_st if (rc != MEMCACHED_SUCCESS) { value_length= 0; - return MEMCACHED_MEMORY_ALLOCATION_FAILURE; + return memcached_set_error((memcached_st *)ptr->root, MEMCACHED_MEMORY_ALLOCATION_FAILURE); } value_ptr= memcached_string_value_mutable(&result->value); @@ -552,7 +552,7 @@ static memcached_return_t binary_read_one_response(memcached_server_write_instan if ((rc= memcached_safe_read(ptr, hole, nr)) != MEMCACHED_SUCCESS) { WATCHPOINT_ERROR(rc); - return MEMCACHED_UNKNOWN_READ_FAILURE; + return memcached_set_error((memcached_st *)ptr->root, MEMCACHED_UNKNOWN_READ_FAILURE); } bodylen-= (uint32_t) nr; } diff --git a/libmemcached/result.h b/libmemcached/result.h index 701b89b7..5947cb85 100644 --- a/libmemcached/result.h +++ b/libmemcached/result.h @@ -1,14 +1,41 @@ -/* LibMemcached - * Copyright (C) 2006-2009 Brian Aker - * All rights reserved. +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library * - * Use and distribution licensed under the BSD license. See - * the COPYING file in the parent directory for full text. + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * Copyright (C) 2006-2009 Brian Aker All rights reserved. * - * Summary: Functions to manipulate the result structure. + * 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 #ifndef __LIBMEMCACHED_RESULT_H__ #define __LIBMEMCACHED_RESULT_H__ diff --git a/libmemcached/return.h b/libmemcached/return.h index 048c0670..5b4a4041 100644 --- a/libmemcached/return.h +++ b/libmemcached/return.h @@ -90,5 +90,7 @@ enum memcached_return_t { typedef enum memcached_return_t memcached_return_t; #endif -#define memcached_failed(A) (A) != MEMCACHED_SUCCESS ? true : false + +#define memcached_success(X) (X) == MEMCACHED_SUCCESS ? true : false +#define memcached_failed(A) (A) != MEMCACHED_SUCCESS ? true : false diff --git a/libmemcached/server.h b/libmemcached/server.h index fd731e0e..06142b96 100644 --- a/libmemcached/server.h +++ b/libmemcached/server.h @@ -1,17 +1,42 @@ -/* LibMemcached - * Copyright (C) 2006-2009 Brian Aker - * All rights reserved. +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library * - * Use and distribution licensed under the BSD license. See - * the COPYING file in the parent directory for full text. + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * Copyright (C) 2006-2009 Brian Aker All rights reserved. * - * Summary: String structure used for libmemcached. + * 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. * */ -#ifndef __LIBMEMCACHED_SERVER_H__ -#define __LIBMEMCACHED_SERVER_H__ +#pragma once struct memcached_server_st { struct { @@ -127,5 +152,3 @@ const char *memcached_server_error(memcached_server_instance_st ptr); #ifdef __cplusplus } // extern "C" #endif - -#endif /* __LIBMEMCACHED_SERVER_H__ */ diff --git a/libmemcached/string.h b/libmemcached/string.h index 8c57c8b0..50ad98bb 100644 --- a/libmemcached/string.h +++ b/libmemcached/string.h @@ -63,6 +63,12 @@ struct memcached_string_t { const char *c_str; }; +#define memcached_size(X) (X).size; +#define memcached_c_str(X) (X).c_str; +#define memcached_string_param(X) (X).c_str, (X).size + +#ifdef BUILDING_LIBMEMCACHED + #ifdef __cplusplus extern "C" { #endif @@ -108,8 +114,6 @@ void memcached_string_set_length(memcached_string_st *self, size_t length); } #endif -#ifdef BUILDING_LIBMEMCACHED - #ifdef __cplusplus #define memcached_string_with_size(X) (X), (static_cast((sizeof(X) - 1))) #define memcached_string_make(X) (static_cast((sizeof(X) - 1))), (X) -- 2.30.2