From ae6bc7501efd5aeaaee92dabe2da0ec2d1625c5b Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Wed, 27 Apr 2011 17:28:00 -0700 Subject: [PATCH] Merge in conversion to C++. --- Makefile.am | 6 +- clients/{execute.c => execute.cc} | 2 +- clients/execute.h | 13 +- clients/{generator.c => generator.cc} | 0 clients/generator.h | 9 +- clients/include.am | 49 +++-- clients/{memcapable.c => memcapable.cc} | 43 ++-- clients/{memcat.c => memcat.cc} | 6 +- clients/{memcp.c => memcp.cc} | 8 +- clients/{memdump.c => memdump.cc} | 0 clients/{memerror.c => memerror.cc} | 0 clients/{memflush.c => memflush.cc} | 0 clients/{memrm.c => memrm.cc} | 0 clients/{memslap.c => memslap.cc} | 4 +- clients/{memstat.c => memstat.cc} | 18 +- clients/ms_conn.h | 6 +- clients/ms_memslap.h | 2 +- clients/ms_setting.h | 4 +- clients/{utilities.c => utilities.cc} | 30 ++- clients/utilities.h | 10 + configure.ac | 2 +- example/include.am | 5 +- libhashkit/{algorithm.c => algorithm.cc} | 0 libhashkit/{behavior.c => behavior.cc} | 0 libhashkit/common.h | 5 +- libhashkit/{crc32.c => crc32.cc} | 0 libhashkit/{digest.c => digest.cc} | 0 libhashkit/{fnv.c => fnv.cc} | 0 libhashkit/{function.c => function.cc} | 4 +- libhashkit/{hashkit.c => hashkit.cc} | 17 +- libhashkit/hashkit.h | 136 +++++------- libhashkit/hashkit.hpp | 97 +++++++++ libhashkit/{hsieh.c => hsieh.cc} | 0 libhashkit/include.am | 37 ++-- libhashkit/{jenkins.c => jenkins.cc} | 0 libhashkit/{ketama.c => ketama.cc} | 0 libhashkit/{md5.c => md5.cc} | 33 +-- libhashkit/{murmur.c => murmur.cc} | 0 .../{one_at_a_time.c => one_at_a_time.cc} | 0 .../{str_algorithm.c => str_algorithm.cc} | 0 libhashkit/{strerror.c => strerror.cc} | 0 libhashkit/visibility.h | 5 +- libmemcached/{allocators.c => allocators.cc} | 11 +- libmemcached/allocators.h | 53 ++++- libmemcached/{analyze.c => analyze.cc} | 0 libmemcached/{auto.c => auto.cc} | 122 ++++++++--- libmemcached/auto.h | 43 +++- libmemcached/{behavior.c => behavior.cc} | 0 libmemcached/byteorder.c | 43 ---- libmemcached/byteorder.cc | 69 ++++++ libmemcached/byteorder.h | 61 ++++-- libmemcached/{callback.c => callback.cc} | 4 +- libmemcached/callback.h | 1 + libmemcached/common.h | 13 +- libmemcached/{connect.c => connect.cc} | 47 +++- libmemcached/{delete.c => delete.cc} | 12 +- libmemcached/delete.h | 44 +++- libmemcached/{do.c => do.cc} | 0 libmemcached/{dump.c => dump.cc} | 0 libmemcached/error.cc | 5 +- libmemcached/{flush.c => flush.cc} | 42 +++- libmemcached/flush.h | 43 +++- libmemcached/flush_buffers.c | 29 --- libmemcached/flush_buffers.cc | 66 ++++++ libmemcached/flush_buffers.h | 43 +++- libmemcached/{get.c => get.cc} | 60 +++--- libmemcached/{hash.c => hash.cc} | 2 +- libmemcached/{hosts.c => hosts.cc} | 23 +- libmemcached/include.am | 123 ++++------- libmemcached/initialize_query.cc | 10 +- libmemcached/internal.h | 46 ++-- libmemcached/{io.c => io.cc} | 16 +- libmemcached/io.h | 11 +- libmemcached/{key.c => key.cc} | 10 +- libmemcached/{memcached.c => memcached.cc} | 38 +++- libmemcached/memcached.h | 12 +- libmemcached/memcached.hpp | 200 +++--------------- libmemcached/memcached/protocol_binary.h | 5 +- libmemcached/options/context.h | 2 +- libmemcached/parse.c | 73 ------- libmemcached/parse.cc | 110 ++++++++++ libmemcached/protocol/ascii_handler.c | 46 +++- libmemcached/protocol/ascii_handler.h | 42 +++- libmemcached/protocol/binary_handler.c | 40 +++- libmemcached/protocol/binary_handler.h | 42 +++- libmemcached/protocol/common.h | 49 ++++- libmemcached/protocol/include.am | 26 +++ libmemcached/{purge.c => purge.cc} | 0 libmemcached/{quit.c => quit.cc} | 41 +++- libmemcached/quit.h | 43 +++- libmemcached/{response.c => response.cc} | 42 +++- libmemcached/response.h | 43 +++- libmemcached/{result.c => result.cc} | 43 +++- libmemcached/return.h | 1 + libmemcached/{server.c => server.cc} | 36 ++-- .../{server_list.c => server_list.cc} | 0 libmemcached/{stats.c => stats.cc} | 24 ++- libmemcached/{storage.c => storage.cc} | 33 ++- libmemcached/{strerror.c => strerror.cc} | 0 libmemcached/{string.c => string.cc} | 49 ++++- libmemcached/string.h | 42 +++- libmemcached/types.h | 1 + libmemcached/util/include.am | 32 +++ libmemcached/util/version.cc | 50 +++-- libmemcached/verbosity.c | 60 ------ libmemcached/verbosity.cc | 97 +++++++++ libmemcached/verbosity.h | 43 +++- libmemcached/{version.c => version.cc} | 40 +++- libmemcached/version.h | 43 +++- libmemcached/visibility.h | 5 +- libtest/test.c | 6 - libtest/test.h | 21 ++ tests/atomsmasher.c | 4 +- tests/hash_plus.cc | 5 +- tests/include.am | 25 ++- tests/libmemcached_world.h | 4 + tests/mem_functions.c | 44 +++- tests/plus.cpp | 167 ++++----------- tests/string.cc | 8 +- 119 files changed, 2087 insertions(+), 1253 deletions(-) rename clients/{execute.c => execute.cc} (98%) rename clients/{generator.c => generator.cc} (100%) rename clients/{memcapable.c => memcapable.cc} (99%) rename clients/{memcat.c => memcat.cc} (95%) rename clients/{memcp.c => memcp.cc} (97%) rename clients/{memdump.c => memdump.cc} (100%) rename clients/{memerror.c => memerror.cc} (100%) rename clients/{memflush.c => memflush.cc} (100%) rename clients/{memrm.c => memrm.cc} (100%) rename clients/{memslap.c => memslap.cc} (98%) rename clients/{memstat.c => memstat.cc} (98%) rename clients/{utilities.c => utilities.cc} (92%) rename libhashkit/{algorithm.c => algorithm.cc} (100%) rename libhashkit/{behavior.c => behavior.cc} (100%) rename libhashkit/{crc32.c => crc32.cc} (100%) rename libhashkit/{digest.c => digest.cc} (100%) rename libhashkit/{fnv.c => fnv.cc} (100%) rename libhashkit/{function.c => function.cc} (93%) rename libhashkit/{hashkit.c => hashkit.cc} (85%) create mode 100644 libhashkit/hashkit.hpp rename libhashkit/{hsieh.c => hsieh.cc} (100%) rename libhashkit/{jenkins.c => jenkins.cc} (100%) rename libhashkit/{ketama.c => ketama.cc} (100%) rename libhashkit/{md5.c => md5.cc} (92%) rename libhashkit/{murmur.c => murmur.cc} (100%) rename libhashkit/{one_at_a_time.c => one_at_a_time.cc} (100%) rename libhashkit/{str_algorithm.c => str_algorithm.cc} (100%) rename libhashkit/{strerror.c => strerror.cc} (100%) rename libmemcached/{allocators.c => allocators.cc} (89%) rename libmemcached/{analyze.c => analyze.cc} (100%) rename libmemcached/{auto.c => auto.cc} (79%) rename libmemcached/{behavior.c => behavior.cc} (100%) delete mode 100644 libmemcached/byteorder.c create mode 100644 libmemcached/byteorder.cc rename libmemcached/{callback.c => callback.cc} (97%) rename libmemcached/{connect.c => connect.cc} (88%) rename libmemcached/{delete.c => delete.cc} (96%) rename libmemcached/{do.c => do.cc} (100%) rename libmemcached/{dump.c => dump.cc} (100%) rename libmemcached/{flush.c => flush.cc} (65%) delete mode 100644 libmemcached/flush_buffers.c create mode 100644 libmemcached/flush_buffers.cc rename libmemcached/{get.c => get.cc} (91%) rename libmemcached/{hash.c => hash.cc} (99%) rename libmemcached/{hosts.c => hosts.cc} (95%) rename libmemcached/{io.c => io.cc} (98%) rename libmemcached/{key.c => key.cc} (77%) rename libmemcached/{memcached.c => memcached.cc} (92%) delete mode 100644 libmemcached/parse.c create mode 100644 libmemcached/parse.cc create mode 100644 libmemcached/protocol/include.am rename libmemcached/{purge.c => purge.cc} (100%) rename libmemcached/{quit.c => quit.cc} (63%) rename libmemcached/{response.c => response.cc} (90%) rename libmemcached/{result.c => result.cc} (62%) rename libmemcached/{server.c => server.cc} (92%) rename libmemcached/{server_list.c => server_list.cc} (100%) rename libmemcached/{stats.c => stats.cc} (96%) rename libmemcached/{storage.c => storage.cc} (95%) rename libmemcached/{strerror.c => strerror.cc} (100%) rename libmemcached/{string.c => string.cc} (66%) create mode 100644 libmemcached/util/include.am delete mode 100644 libmemcached/verbosity.c create mode 100644 libmemcached/verbosity.cc rename libmemcached/{version.c => version.cc} (73%) diff --git a/Makefile.am b/Makefile.am index 80b2c03e..2c276016 100644 --- a/Makefile.am +++ b/Makefile.am @@ -35,6 +35,8 @@ EXTRA_DIST= \ include libtest/include.am include libmemcached/include.am +include libmemcached/protocol/include.am +include libmemcached/util/include.am include clients/include.am include libhashkit/include.am include tests/include.am @@ -93,6 +95,4 @@ lcov-clean: clean find . -name '*.gcno' | xargs rm -f find . -name '*.gcda' | xargs rm -f -CLEANFILES+= config/top.h - - +DISTCLEANFILES+= config/top.h diff --git a/clients/execute.c b/clients/execute.cc similarity index 98% rename from clients/execute.c rename to clients/execute.cc index 0beaae4b..7f89f773 100644 --- a/clients/execute.c +++ b/clients/execute.cc @@ -102,7 +102,7 @@ unsigned int execute_mget(memcached_st *memc, unsigned int number_of) { unsigned int retrieved= 0; - memcached_execute_fn callbacks[1]= { [0]= &callback_counter }; + memcached_execute_fn callbacks[]= { callback_counter }; memcached_return_t rc; rc= memcached_mget_execute(memc, keys, key_length, (size_t)number_of, callbacks, &retrieved, 1); diff --git a/clients/execute.h b/clients/execute.h index 176c6fff..05678c4d 100644 --- a/clients/execute.h +++ b/clients/execute.h @@ -9,17 +9,22 @@ * */ -#ifndef CLIENTS_EXECUTE_H -#define CLIENTS_EXECUTE_H +#pragma once #include #include "libmemcached/memcached.h" -#include "generator.h" +#include "clients/generator.h" + +#ifdef __cplusplus +extern "C" { +#endif unsigned int execute_set(memcached_st *memc, pairs_st *pairs, unsigned int number_of); unsigned int execute_get(memcached_st *memc, pairs_st *pairs, unsigned int number_of); unsigned int execute_mget(memcached_st *memc, const char * const *keys, size_t *key_length, unsigned int number_of); -#endif +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/clients/generator.c b/clients/generator.cc similarity index 100% rename from clients/generator.c rename to clients/generator.cc diff --git a/clients/generator.h b/clients/generator.h index 196e71b2..e60bfb38 100644 --- a/clients/generator.h +++ b/clients/generator.h @@ -13,8 +13,7 @@ Code to generate data to be pushed into memcached */ -#ifndef __GENERATOR_H__ -#define __GENERATOR_H__ +#pragma once typedef struct pairs_st pairs_st; @@ -25,7 +24,13 @@ struct pairs_st { size_t value_length; }; +#ifdef __cplusplus +extern "C" { +#endif + pairs_st *pairs_generate(uint64_t number_of, size_t value_length); void pairs_free(pairs_st *pairs); +#ifdef __cplusplus +} // extern "C" #endif diff --git a/clients/include.am b/clients/include.am index 07d49a70..05b1ed7e 100644 --- a/clients/include.am +++ b/clients/include.am @@ -2,10 +2,10 @@ # included from Top Level Makefile.am # All paths should be given relative to the root -CLIENTS_LDADDS = \ - $(LIBM) \ - clients/libutilities.la \ - libmemcached/libmemcached.la +CLIENTS_LDADDS= \ + $(LIBM) \ + clients/libutilities.la \ + libmemcached/libmemcached.la if HAVE_SASL CLIENTS_LDADDS+= $(LIBSASL) @@ -44,53 +44,52 @@ noinst_HEADERS+= \ clients/utilities.h noinst_LTLIBRARIES+= clients/libutilities.la -clients_libutilities_la_SOURCES= clients/utilities.c +clients_libutilities_la_SOURCES= clients/utilities.cc noinst_LTLIBRARIES+= clients/libgenexec.la -clients_libgenexec_la_SOURCES= clients/generator.c clients/execute.c +clients_libgenexec_la_SOURCES= clients/generator.cc clients/execute.cc -clients_memcat_SOURCES= clients/memcat.c +clients_memcat_SOURCES= clients/memcat.cc clients_memcat_LDADD= $(CLIENTS_LDADDS) clients_memparse_SOURCES= clients/memparse.cc clients_memparse_LDADD= $(CLIENTS_LDADDS) -clients_memcp_SOURCES= clients/memcp.c +clients_memcp_SOURCES= clients/memcp.cc clients_memcp_LDADD= $(CLIENTS_LDADDS) -clients_memdump_SOURCES= clients/memdump.c +clients_memdump_SOURCES= clients/memdump.cc clients_memdump_LDADD= $(CLIENTS_LDADDS) -clients_memstat_SOURCES= clients/memstat.c +clients_memstat_SOURCES= clients/memstat.cc clients_memstat_LDADD= $(CLIENTS_LDADDS) -clients_memrm_SOURCES= clients/memrm.c +clients_memrm_SOURCES= clients/memrm.cc clients_memrm_LDADD= $(CLIENTS_LDADDS) -clients_memflush_SOURCES= clients/memflush.c +clients_memflush_SOURCES= clients/memflush.cc clients_memflush_LDADD= $(CLIENTS_LDADDS) -clients_memerror_SOURCES= clients/memerror.c +clients_memerror_SOURCES= clients/memerror.cc clients_memerror_LDADD= $(CLIENTS_LDADDS) -clients_memslap_SOURCES = clients/memslap.c +clients_memslap_SOURCES = clients/memslap.cc clients_memslap_LDADD = $(PTHREAD_LIBS) clients/libgenexec.la $(CLIENTS_LDADDS) clients_memaslap_SOURCES= \ - clients/memaslap.c \ - clients/ms_conn.c \ - clients/ms_setting.c \ - clients/ms_sigsegv.c \ - clients/ms_stats.c \ - clients/ms_task.c \ - clients/ms_thread.c + clients/memaslap.c \ + clients/ms_conn.c \ + clients/ms_setting.c \ + clients/ms_sigsegv.c \ + clients/ms_stats.c \ + clients/ms_task.c \ + clients/ms_thread.c clients_memaslap_LDADD= $(LTLIBEVENT) clients/libgenexec.la $(CLIENTS_LDADDS) -clients_memcapable_SOURCES= clients/memcapable.c +clients_memcapable_SOURCES= \ + clients/memcapable.cc \ + libmemcached/byteorder.cc clients_memcapable_LDADD= $(CLIENTS_LDADDS) -if BUILD_BYTEORDER -clients_memcapable_LDADD+= libmemcached/libbyteorder.la -endif test-start-server: clients/memflush --servers=localhost diff --git a/clients/memcapable.c b/clients/memcapable.cc similarity index 99% rename from clients/memcapable.c rename to clients/memcapable.cc index 69d2557e..baac28b2 100644 --- a/clients/memcapable.c +++ b/clients/memcapable.cc @@ -11,6 +11,7 @@ /* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */ #undef NDEBUG + #include "config.h" #include #include @@ -88,11 +89,13 @@ enum test_return static struct addrinfo *lookuphost(const char *hostname, const char *port) { struct addrinfo *ai= 0; - struct addrinfo hints= {.ai_family=AF_UNSPEC, - .ai_protocol=IPPROTO_TCP, - .ai_socktype=SOCK_STREAM}; - int error= getaddrinfo(hostname, port, &hints, &ai); + struct addrinfo hints; + memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_family=AF_UNSPEC; + hints.ai_protocol=IPPROTO_TCP; + hints.ai_socktype=SOCK_STREAM; + int error= getaddrinfo(hostname, port, &hints, &ai); if (error != 0) { if (error != EAI_SYSTEM) @@ -182,24 +185,32 @@ static ssize_t timeout_io_op(memcached_socket_t fd, short direction, void *buf, ssize_t ret; if (direction == POLLOUT) - ret= send(fd, buf, len, 0); + { + ret= send(fd, buf, len, 0); + } else - ret= recv(fd, buf, len, 0); + { + ret= recv(fd, buf, len, 0); + } - if (ret == SOCKET_ERROR && get_socket_errno() == EWOULDBLOCK) { - struct pollfd fds= { - .events= direction, - .fd= fd - }; + if (ret == SOCKET_ERROR && get_socket_errno() == EWOULDBLOCK) + { + struct pollfd fds; + memset(&fds, 0, sizeof(struct pollfd)); + fds.events= direction; + fds.fd= fd; int err= poll(&fds, 1, timeout * 1000); - if (err == 1) { if (direction == POLLOUT) - ret= send(fd, buf, len, 0); + { + ret= send(fd, buf, len, 0); + } else - ret= recv(fd, buf, len, 0); + { + ret= recv(fd, buf, len, 0); + } } else if (err == 0) { @@ -246,7 +257,7 @@ static enum test_return ensure(bool val, const char *expression, const char *fil static enum test_return retry_write(const void* buf, size_t len) { size_t offset= 0; - const char* ptr= buf; + const char* ptr= static_cast(buf); do { @@ -1338,7 +1349,7 @@ static enum test_return ascii_get_unknown_value(char **key, char **value, ssize_ ++end; verify(*end == '\n'); - *value= malloc((size_t)*ndata); + *value= static_cast(malloc((size_t)*ndata)); verify(*value != NULL); execute(retry_read(*value, (size_t)*ndata)); diff --git a/clients/memcat.c b/clients/memcat.cc similarity index 95% rename from clients/memcat.c rename to clients/memcat.cc index 3f0d92b4..12df3479 100644 --- a/clients/memcat.c +++ b/clients/memcat.cc @@ -95,8 +95,8 @@ int main(int argc, char *argv[]) { if (opt_verbose) { - printf("key: %s\nflags: %x\nlength: %zu\nvalue: ", - argv[optind], flags, string_length); + printf("key: %s\nflags: %x\nlength: %lu\nvalue: ", + argv[optind], flags, (unsigned long)string_length); } if (opt_file) @@ -115,7 +115,7 @@ int main(int argc, char *argv[]) written= fwrite(string, 1, string_length, fp); if (written != string_length) { - fprintf(stderr, "error writing file (written %zu, should be %zu)\n", written, string_length); + fprintf(stderr, "error writing file (written %lu, should be %lu)\n", (unsigned long)written, (unsigned long)string_length); return_code= -1; break; } diff --git a/clients/memcp.c b/clients/memcp.cc similarity index 97% rename from clients/memcp.c rename to clients/memcp.cc index bf3828ae..3869242b 100644 --- a/clients/memcp.c +++ b/clients/memcp.cc @@ -147,10 +147,10 @@ int main(int argc, char *argv[]) if (opt_verbose) { static const char *opstr[] = { "set", "add", "replace" }; - printf("op: %s\nsource file: %s\nlength: %zu\n" - "key: %s\nflags: %x\nexpires: %llu\n", - opstr[opt_method - OPT_SET], argv[optind], (size_t)sbuf.st_size, - ptr, opt_flags, (unsigned long long)opt_expires); + printf("op: %s\nsource file: %s\nlength: %lu\n" + "key: %s\nflags: %x\nexpires: %lu\n", + opstr[opt_method - OPT_SET], argv[optind], (unsigned long)sbuf.st_size, + ptr, opt_flags, (unsigned long)opt_expires); } if ((file_buffer_ptr= (char *)malloc(sizeof(char) * (size_t)sbuf.st_size)) == NULL) diff --git a/clients/memdump.c b/clients/memdump.cc similarity index 100% rename from clients/memdump.c rename to clients/memdump.cc diff --git a/clients/memerror.c b/clients/memerror.cc similarity index 100% rename from clients/memerror.c rename to clients/memerror.cc diff --git a/clients/memflush.c b/clients/memflush.cc similarity index 100% rename from clients/memflush.c rename to clients/memflush.cc diff --git a/clients/memrm.c b/clients/memrm.cc similarity index 100% rename from clients/memrm.c rename to clients/memrm.cc diff --git a/clients/memslap.c b/clients/memslap.cc similarity index 98% rename from clients/memslap.c rename to clients/memslap.cc index 0d77fd6e..d8927e7e 100644 --- a/clients/memslap.c +++ b/clients/memslap.cc @@ -203,8 +203,8 @@ void scheduler(memcached_server_st *servers, conclusions_st *conclusion) if (opt_createial_load) pairs= load_create_data(memc, opt_createial_load, &actual_loaded); - char **keys= calloc(actual_loaded, sizeof(char*)); - size_t *key_lengths= calloc(actual_loaded, sizeof(size_t)); + char **keys= static_cast(calloc(actual_loaded, sizeof(char*))); + size_t *key_lengths= static_cast(calloc(actual_loaded, sizeof(size_t))); if (keys == NULL || key_lengths == NULL) { diff --git a/clients/memstat.c b/clients/memstat.cc similarity index 98% rename from clients/memstat.c rename to clients/memstat.cc index d3518458..a3b85108 100644 --- a/clients/memstat.c +++ b/clients/memstat.cc @@ -13,14 +13,15 @@ */ #include "config.h" -#include -#include -#include -#include +#include +#include +#include #include -#include #include +#include #include +#include +#include #include @@ -153,13 +154,13 @@ static void run_analyzer(memcached_st *memc, memcached_stat_st *memc_stat) } else if (strcmp(analyze_mode, "latency") == 0) { - memcached_st **servers; uint32_t flags, server_count= memcached_server_count(memc); uint32_t num_of_tests= 32; const char *test_key= "libmemcached_test_key"; - servers= malloc(sizeof(memcached_st*) * server_count); - if (!servers) + memcached_st **servers; + servers= static_cast(malloc(sizeof(memcached_st*) * server_count)); + if (not servers) { fprintf(stderr, "Failed to allocate memory\n"); return; @@ -176,6 +177,7 @@ static void run_analyzer(memcached_st *memc, memcached_stat_st *memc_stat) if (x > 0) memcached_free(servers[0]); x--; + for (; x > 0; x--) memcached_free(servers[x]); diff --git a/clients/ms_conn.h b/clients/ms_conn.h index cf1e8c0f..b915888d 100644 --- a/clients/ms_conn.h +++ b/clients/ms_conn.h @@ -60,7 +60,7 @@ enum conn_states { conn_read, /* reading in a command line */ conn_write, /* writing out a simple response */ - conn_closing, /* closing this connection */ + conn_closing /* closing this connection */ }; /* returned states of memcached command */ @@ -78,7 +78,7 @@ enum mcd_ret MCD_NOTFOUND, /* server not find the object */ MCD_END, /* end of the response of get command */ MCD_DELETED, /* server delete the object successfully */ - MCD_STAT, /* response of stats command */ + MCD_STAT /* response of stats command */ }; /* used to store the current or previous running command state */ @@ -103,7 +103,7 @@ typedef struct udppkt enum protocol { ascii_prot = 3, /* ASCII protocol */ - binary_prot, /* binary protocol */ + binary_prot /* binary protocol */ }; /** diff --git a/clients/ms_memslap.h b/clients/ms_memslap.h index dc0844d8..1c1b29eb 100644 --- a/clients/ms_memslap.h +++ b/clients/ms_memslap.h @@ -55,7 +55,7 @@ typedef enum OPT_BINARY_PROTOCOL= 'B', OPT_OVERWRITE= 'o', OPT_TPS= 'P', - OPT_REP_WRITE_SRV= 'p', + OPT_REP_WRITE_SRV= 'p' } ms_options_t; /* global statistic of response time */ diff --git a/clients/ms_setting.h b/clients/ms_setting.h index d8ccf8bb..964dc400 100644 --- a/clients/ms_setting.h +++ b/clients/ms_setting.h @@ -88,7 +88,7 @@ typedef enum cmd_type { CMD_SET, CMD_GET, - CMD_NULL, + CMD_NULL } ms_cmd_type_t; /* types in the configuration file */ @@ -97,7 +97,7 @@ typedef enum conf_type CONF_KEY, CONF_VALUE, CONF_CMD, - CONF_NULL, + CONF_NULL } ms_conf_type_t; /* information of command distribution */ diff --git a/clients/utilities.c b/clients/utilities.cc similarity index 92% rename from clients/utilities.c rename to clients/utilities.cc index 92987471..ca109adc 100644 --- a/clients/utilities.c +++ b/clients/utilities.cc @@ -10,10 +10,10 @@ */ #include "config.h" -#include +#include +#include +#include #include -#include -#include "utilities.h" long int timedif(struct timeval a, struct timeval b) @@ -86,7 +86,7 @@ void help_command(const char *command_name, const char *description, printf("\t --%s%c\n", long_options[x].name, long_options[x].has_arg ? '=' : ' '); - if ((help_message= lookup_help(long_options[x].val))) + if ((help_message= lookup_help(memcached_options(long_options[x].val)))) printf("\t\t%s\n", help_message); } @@ -131,8 +131,7 @@ void process_hash_option(memcached_st *memc, char *opt_hash) static char *username; static char *passwd; -static int get_username(void *context, int id, const char **result, - unsigned int *len) +static int get_username(void *context, int id, const char **result, unsigned int *len) { (void)context; if (!result || (id != SASL_CB_USER && id != SASL_CB_AUTHNAME)) @@ -161,8 +160,8 @@ static int get_password(sasl_conn_t *conn, void *context, int id, } size_t len= strlen(passwd); - ptr= malloc(sizeof(sasl_secret_t) + len +1); - if (! ptr) + ptr= (sasl_secret_t *)malloc(sizeof(sasl_secret_t) + len +1); + if (not ptr) return SASL_NOMEM; ptr->len= len; @@ -173,17 +172,14 @@ static int get_password(sasl_conn_t *conn, void *context, int id, return SASL_OK; } +typedef int (*local_sasl_fn)(void); + /* callbacks we support */ static sasl_callback_t sasl_callbacks[] = { - { - SASL_CB_USER, &get_username, NULL - }, { - SASL_CB_AUTHNAME, &get_username, NULL - }, { - SASL_CB_PASS, &get_password, NULL - }, { - SASL_CB_LIST_END, NULL, NULL - } + { SASL_CB_USER, (local_sasl_fn)get_username, NULL }, + { SASL_CB_AUTHNAME, (local_sasl_fn)get_username, NULL }, + { SASL_CB_PASS, (local_sasl_fn)get_password, NULL }, + { SASL_CB_LIST_END, NULL, NULL } }; #endif diff --git a/clients/utilities.h b/clients/utilities.h index a998773b..685be6a5 100644 --- a/clients/utilities.h +++ b/clients/utilities.h @@ -9,6 +9,8 @@ * */ +#pragma once + #include #include #include "libmemcached/watchpoint.h" @@ -41,6 +43,10 @@ struct memcached_programs_help_st char *not_used_yet; }; +#ifdef __cplusplus +extern "C" { +#endif + char *strdup_cleanup(const char *str); void cleanup(void); long int timedif(struct timeval a, struct timeval b); @@ -52,3 +58,7 @@ void process_hash_option(memcached_st *memc, char *opt_hash); bool initialize_sasl(memcached_st *memc, char *user, char *password); void shutdown_sasl(void); void initialize_sockets(void); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/configure.ac b/configure.ac index ea993358..9b8a82c5 100644 --- a/configure.ac +++ b/configure.ac @@ -9,7 +9,7 @@ AC_PREREQ(2.59) AC_INIT([libmemcached],[0.49],[http://libmemcached.org/]) -AC_CONFIG_SRCDIR([libmemcached/memcached.c]) +AC_CONFIG_SRCDIR([libmemcached/memcached.cc]) AC_CONFIG_AUX_DIR(config) PANDORA_CANONICAL_TARGET(no-vc-changelog) diff --git a/example/include.am b/example/include.am index ae9bae93..561eebc8 100644 --- a/example/include.am +++ b/example/include.am @@ -10,16 +10,13 @@ example_memcached_light_SOURCES= \ example/interface_v0.c \ example/interface_v1.c \ example/memcached_light.c \ + libmemcached/byteorder.cc \ example/memcached_light.h \ example/storage.h example_memcached_light_LDADD= libmemcached/libmemcachedprotocol.la \ $(LIBINNODB) $(LTLIBEVENT) -if BUILD_BYTEORDER -example_memcached_light_LDADD+= libmemcached/libbyteorder.la -endif - if HAVE_LIBINNODB example_memcached_light_SOURCES+= example/storage_innodb.c else diff --git a/libhashkit/algorithm.c b/libhashkit/algorithm.cc similarity index 100% rename from libhashkit/algorithm.c rename to libhashkit/algorithm.cc diff --git a/libhashkit/behavior.c b/libhashkit/behavior.cc similarity index 100% rename from libhashkit/behavior.c rename to libhashkit/behavior.cc diff --git a/libhashkit/common.h b/libhashkit/common.h index 73b198f5..5cf8b9f5 100644 --- a/libhashkit/common.h +++ b/libhashkit/common.h @@ -6,8 +6,7 @@ * the COPYING file in the parent directory for full text. */ -#ifndef HASHKIT_COMMON_H -#define HASHKIT_COMMON_H +#pragma once #include @@ -32,5 +31,3 @@ int update_continuum(hashkit_st *hashkit); #ifdef __cplusplus } #endif - -#endif /* HASHKIT_COMMON_H */ diff --git a/libhashkit/crc32.c b/libhashkit/crc32.cc similarity index 100% rename from libhashkit/crc32.c rename to libhashkit/crc32.cc diff --git a/libhashkit/digest.c b/libhashkit/digest.cc similarity index 100% rename from libhashkit/digest.c rename to libhashkit/digest.cc diff --git a/libhashkit/fnv.c b/libhashkit/fnv.cc similarity index 100% rename from libhashkit/fnv.c rename to libhashkit/fnv.cc diff --git a/libhashkit/function.c b/libhashkit/function.cc similarity index 93% rename from libhashkit/function.c rename to libhashkit/function.cc index 3560abd7..7ac91007 100644 --- a/libhashkit/function.c +++ b/libhashkit/function.cc @@ -8,7 +8,7 @@ #include -static hashkit_return_t _set_function(struct hashkit_function_st *self, hashkit_hash_algorithm_t hash_algorithm) +static hashkit_return_t _set_function(struct hashkit_st::hashkit_function_st *self, hashkit_hash_algorithm_t hash_algorithm) { switch (hash_algorithm) { @@ -72,7 +72,7 @@ hashkit_return_t hashkit_set_distribution_function(hashkit_st *self, hashkit_has return _set_function(&self->distribution_hash, hash_algorithm); } -static hashkit_return_t _set_custom_function(struct hashkit_function_st *self, hashkit_hash_fn function, void *context) +static hashkit_return_t _set_custom_function(struct hashkit_st::hashkit_function_st *self, hashkit_hash_fn function, void *context) { if (function) { diff --git a/libhashkit/hashkit.c b/libhashkit/hashkit.cc similarity index 85% rename from libhashkit/hashkit.c rename to libhashkit/hashkit.cc index 7214c144..201a6dff 100644 --- a/libhashkit/hashkit.c +++ b/libhashkit/hashkit.cc @@ -8,21 +8,12 @@ #include -static const hashkit_st global_default_hash= { - .base_hash= { - .function= hashkit_one_at_a_time, - .context= NULL - }, - .flags= { - .is_base_same_distributed= false, - } -}; - static inline bool _hashkit_init(hashkit_st *self) { - self->base_hash= global_default_hash.base_hash; - self->distribution_hash= global_default_hash.base_hash; - self->flags= global_default_hash.flags; + self->base_hash.function= hashkit_one_at_a_time; + self->base_hash.context= NULL; + self->distribution_hash.function= self->base_hash.function; + self->flags.is_base_same_distributed= false; return true; } diff --git a/libhashkit/hashkit.h b/libhashkit/hashkit.h index 2d8ad3a2..9b8761f1 100644 --- a/libhashkit/hashkit.h +++ b/libhashkit/hashkit.h @@ -1,13 +1,42 @@ -/* HashKit - * Copyright (C) 2009-2010 Brian Aker - * All rights reserved. +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * HashKit library + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * Copyright (C) 2009-2010 Brian Aker All rights reserved. + * + * 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. * - * Use and distribution licensed under the BSD license. See - * the COPYING file in the parent directory for full text. */ -#ifndef HASHKIT_H -#define HASHKIT_H + +#pragma once #if !defined(__cplusplus) @@ -15,6 +44,7 @@ #endif #include #include + #include #include #include @@ -25,29 +55,6 @@ #include #include -#ifdef __cplusplus -extern "C" { -#endif - -HASHKIT_API -hashkit_st *hashkit_create(hashkit_st *hash); - -HASHKIT_API -hashkit_st *hashkit_clone(hashkit_st *destination, const hashkit_st *ptr); - -HASHKIT_API -bool hashkit_compare(const hashkit_st *first, const hashkit_st *second); - -HASHKIT_API -void hashkit_free(hashkit_st *hash); - -#define hashkit_is_allocated(__object) ((__object)->options.is_allocated) -#define hashkit_is_initialized(__object) ((__object)->options.is_initialized) - -#ifdef __cplusplus -} // extern "C" -#endif - struct hashkit_st { struct hashkit_function_st { @@ -65,65 +72,24 @@ struct hashkit_st }; #ifdef __cplusplus +extern "C" { +#endif -#include - -class Hashkit { - -public: - - Hashkit() - { - hashkit_create(&self); - } - - Hashkit(const Hashkit& source) - { - hashkit_clone(&self, &source.self); - } - - Hashkit& operator=(const Hashkit& source) - { - hashkit_free(&self); - hashkit_clone(&self, &source.self); - - return *this; - } - - friend bool operator==(const Hashkit &left, const Hashkit &right) - { - return hashkit_compare(&left.self, &right.self); - } - - uint32_t digest(std::string& str) - { - return hashkit_digest(&self, str.c_str(), str.length()); - } +HASHKIT_API +hashkit_st *hashkit_create(hashkit_st *hash); - uint32_t digest(const char *key, size_t key_length) - { - return hashkit_digest(&self, key, key_length); - } +HASHKIT_API +hashkit_st *hashkit_clone(hashkit_st *destination, const hashkit_st *ptr); - hashkit_return_t set_function(hashkit_hash_algorithm_t hash_algorithm) - { - return hashkit_set_function(&self, hash_algorithm); - } +HASHKIT_API +bool hashkit_compare(const hashkit_st *first, const hashkit_st *second); - hashkit_return_t set_distribution_function(hashkit_hash_algorithm_t hash_algorithm) - { - return hashkit_set_function(&self, hash_algorithm); - } +HASHKIT_API +void hashkit_free(hashkit_st *hash); - ~Hashkit() - { - hashkit_free(&self); - } -private: +#define hashkit_is_allocated(__object) ((__object)->options.is_allocated) +#define hashkit_is_initialized(__object) ((__object)->options.is_initialized) - hashkit_st self; -}; +#ifdef __cplusplus +} // extern "C" #endif - - -#endif /* HASHKIT_H */ diff --git a/libhashkit/hashkit.hpp b/libhashkit/hashkit.hpp new file mode 100644 index 00000000..7ead63d0 --- /dev/null +++ b/libhashkit/hashkit.hpp @@ -0,0 +1,97 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * Copyright (C) 2006-2009 Brian Aker All rights reserved. + * + * 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 +#include + +class Hashkit { + +public: + + Hashkit() + { + hashkit_create(&self); + } + + Hashkit(const Hashkit& source) + { + hashkit_clone(&self, &source.self); + } + + Hashkit& operator=(const Hashkit& source) + { + hashkit_free(&self); + hashkit_clone(&self, &source.self); + + return *this; + } + + friend bool operator==(const Hashkit &left, const Hashkit &right) + { + return hashkit_compare(&left.self, &right.self); + } + + uint32_t digest(std::string& str) + { + return hashkit_digest(&self, str.c_str(), str.length()); + } + + uint32_t digest(const char *key, size_t key_length) + { + return hashkit_digest(&self, key, key_length); + } + + hashkit_return_t set_function(hashkit_hash_algorithm_t hash_algorithm) + { + return hashkit_set_function(&self, hash_algorithm); + } + + hashkit_return_t set_distribution_function(hashkit_hash_algorithm_t hash_algorithm) + { + return hashkit_set_function(&self, hash_algorithm); + } + + ~Hashkit() + { + hashkit_free(&self); + } +private: + + hashkit_st self; +}; diff --git a/libhashkit/hsieh.c b/libhashkit/hsieh.cc similarity index 100% rename from libhashkit/hsieh.c rename to libhashkit/hsieh.cc diff --git a/libhashkit/include.am b/libhashkit/include.am index 12575dfb..43300585 100644 --- a/libhashkit/include.am +++ b/libhashkit/include.am @@ -22,6 +22,7 @@ nobase_include_HEADERS+= \ libhashkit/digest.h \ libhashkit/function.h \ libhashkit/hashkit.h \ + libhashkit/hashkit.hpp \ libhashkit/strerror.h \ libhashkit/str_algorithm.h \ libhashkit/types.h \ @@ -31,31 +32,31 @@ noinst_HEADERS+= \ libhashkit/common.h libhashkit_libhashkit_la_SOURCES= \ - libhashkit/algorithm.c \ - libhashkit/behavior.c \ - libhashkit/crc32.c \ - libhashkit/digest.c \ - libhashkit/fnv.c \ - libhashkit/function.c \ - libhashkit/hashkit.c \ - libhashkit/jenkins.c \ - libhashkit/ketama.c \ - libhashkit/md5.c \ - libhashkit/one_at_a_time.c \ - libhashkit/str_algorithm.c \ - libhashkit/strerror.c + libhashkit/algorithm.cc \ + libhashkit/behavior.cc \ + libhashkit/crc32.cc \ + libhashkit/digest.cc \ + libhashkit/fnv.cc \ + libhashkit/function.cc \ + libhashkit/hashkit.cc \ + libhashkit/jenkins.cc \ + libhashkit/ketama.cc \ + libhashkit/md5.cc \ + libhashkit/one_at_a_time.cc \ + libhashkit/str_algorithm.cc \ + libhashkit/strerror.cc if INCLUDE_HSIEH_SRC -libhashkit_libhashkit_la_SOURCES+= libhashkit/hsieh.c +libhashkit_libhashkit_la_SOURCES+= libhashkit/hsieh.cc endif if INCLUDE_MURMUR_SRC -libhashkit_libhashkit_la_SOURCES+= libhashkit/murmur.c +libhashkit_libhashkit_la_SOURCES+= libhashkit/murmur.cc endif -libhashkit_libhashkit_la_CFLAGS= \ - ${AM_CFLAGS} \ - -DBUILDING_HASHKIT +libhashkit_libhashkit_la_CXXFLAGS= \ + ${AM_CXXFLAGS} \ + -DBUILDING_HASHKIT libhashkit_libhashkit_la_LDFLAGS= \ $(LIBM) \ diff --git a/libhashkit/jenkins.c b/libhashkit/jenkins.cc similarity index 100% rename from libhashkit/jenkins.c rename to libhashkit/jenkins.cc diff --git a/libhashkit/ketama.c b/libhashkit/ketama.cc similarity index 100% rename from libhashkit/ketama.c rename to libhashkit/ketama.cc diff --git a/libhashkit/md5.c b/libhashkit/md5.cc similarity index 92% rename from libhashkit/md5.c rename to libhashkit/md5.cc index 1af5e6c0..86822f54 100644 --- a/libhashkit/md5.c +++ b/libhashkit/md5.cc @@ -36,6 +36,7 @@ documentation and/or software. /* POINTER defines a generic pointer type */ typedef unsigned char *POINTER; +typedef const unsigned char *CONST_POINTER; /* UINT4 defines a four byte word */ @@ -77,11 +78,11 @@ static void MD5Final ( unsigned char digest[16], /* mess static void MD5Transform (UINT4 state[4], - unsigned char block[64]); + const unsigned char block[64]); static void Encode (unsigned char *output, UINT4 *input, unsigned int len); -static void Decode(UINT4 *output, unsigned char *input, unsigned int len); +static void Decode(UINT4 *output, const unsigned char *input, unsigned int len); static unsigned char PADDING[64] = { 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -178,20 +179,20 @@ static void MD5Update ( /* Transform as many times as possible. */ if (inputLen >= partLen) { - memcpy((POINTER)&context->buffer[idx], (POINTER)input, partLen); - MD5Transform(context->state, context->buffer); + memcpy((POINTER)&context->buffer[idx], (CONST_POINTER)input, partLen); + MD5Transform(context->state, context->buffer); - for (i = partLen; i + 63 < inputLen; i += 64) - MD5Transform (context->state, (unsigned char *)&input[i]); + for (i = partLen; i + 63 < inputLen; i += 64) + MD5Transform (context->state, (CONST_POINTER)&input[i]); - idx = 0; + idx = 0; } else - i = 0; + i = 0; /* Buffer remaining input */ - memcpy((POINTER)&context->buffer[idx], (POINTER)&input[i], - inputLen-i); + memcpy((POINTER)&context->buffer[idx], (CONST_POINTER)&input[i], + inputLen-i); } /* MD5 finalization. Ends an MD5 message-digest operation, writing the @@ -229,7 +230,7 @@ static void MD5Final ( */ static void MD5Transform ( UINT4 state[4], - unsigned char block[64]) + const unsigned char block[64]) { UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16]; @@ -341,15 +342,15 @@ unsigned int len) a multiple of 4. */ static void Decode ( -UINT4 *output, -unsigned char *input, -unsigned int len) + UINT4 *output, + const unsigned char *input, + unsigned int len) { unsigned int i, j; for (i = 0, j = 0; j < len; i++, j += 4) - output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) | - (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24); + output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) | + (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24); } uint32_t hashkit_md5(const char *key, size_t key_length, void *context) diff --git a/libhashkit/murmur.c b/libhashkit/murmur.cc similarity index 100% rename from libhashkit/murmur.c rename to libhashkit/murmur.cc diff --git a/libhashkit/one_at_a_time.c b/libhashkit/one_at_a_time.cc similarity index 100% rename from libhashkit/one_at_a_time.c rename to libhashkit/one_at_a_time.cc diff --git a/libhashkit/str_algorithm.c b/libhashkit/str_algorithm.cc similarity index 100% rename from libhashkit/str_algorithm.c rename to libhashkit/str_algorithm.cc diff --git a/libhashkit/strerror.c b/libhashkit/strerror.cc similarity index 100% rename from libhashkit/strerror.c rename to libhashkit/strerror.cc diff --git a/libhashkit/visibility.h b/libhashkit/visibility.h index 7691d4b5..b8f194c5 100644 --- a/libhashkit/visibility.h +++ b/libhashkit/visibility.h @@ -13,8 +13,7 @@ * @brief Visibility control macros */ -#ifndef HASHKIT_VISIBILITY_H -#define HASHKIT_VISIBILITY_H +#pragma once /** * @@ -47,5 +46,3 @@ # define HASHKIT_LOCAL # endif /* defined(_MSC_VER) */ #endif /* defined(BUILDING_HASHKIT) */ - -#endif /* HASHKIT_VISIBILITY_H */ diff --git a/libmemcached/allocators.c b/libmemcached/allocators.cc similarity index 89% rename from libmemcached/allocators.c rename to libmemcached/allocators.cc index fe7b296c..e716bee3 100644 --- a/libmemcached/allocators.c +++ b/libmemcached/allocators.cc @@ -35,16 +35,9 @@ void *_libmemcached_calloc(const memcached_st *ptr, size_t nelem, size_t size, v return calloc(nelem, size); } -static const struct _allocators_st global_default_allocator= { - .calloc= _libmemcached_calloc, - .context= NULL, - .free= _libmemcached_free, - .malloc= _libmemcached_malloc, - .realloc= _libmemcached_realloc -}; - -struct _allocators_st memcached_allocators_return_default(void) +struct memcached_allocator_t memcached_allocators_return_default(void) { + static struct memcached_allocator_t global_default_allocator= { _libmemcached_calloc, _libmemcached_free, _libmemcached_malloc, _libmemcached_realloc, 0 }; return global_default_allocator; } diff --git a/libmemcached/allocators.h b/libmemcached/allocators.h index b525e901..6e4455f0 100644 --- a/libmemcached/allocators.h +++ b/libmemcached/allocators.h @@ -1,16 +1,49 @@ -/* LibMemcached - * Copyright (C) 2010 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) 2010 Brian Aker All rights reserved. * - * Summary: work with user defined memory allocators + * 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_ALLOCATORS_H__ -#define __LIBMEMCACHED_ALLOCATORS_H__ +#pragma once + +struct memcached_allocator_t { + memcached_calloc_fn calloc; + memcached_free_fn free; + memcached_malloc_fn malloc; + memcached_realloc_fn realloc; + void *context; +}; #ifdef __cplusplus extern "C" { @@ -47,10 +80,8 @@ LIBMEMCACHED_LOCAL void *_libmemcached_calloc(const memcached_st *ptr, size_t nelem, size_t size, void *context); LIBMEMCACHED_LOCAL -struct _allocators_st memcached_allocators_return_default(void); +struct memcached_allocator_t memcached_allocators_return_default(void); #ifdef __cplusplus } #endif - -#endif /* __LIBMEMCACHED_ALLOCATORS_H__ */ diff --git a/libmemcached/analyze.c b/libmemcached/analyze.cc similarity index 100% rename from libmemcached/analyze.c rename to libmemcached/analyze.cc diff --git a/libmemcached/auto.c b/libmemcached/auto.cc similarity index 79% rename from libmemcached/auto.c rename to libmemcached/auto.cc index 325ddb6b..42c3b5f0 100644 --- a/libmemcached/auto.c +++ b/libmemcached/auto.cc @@ -1,15 +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: Methods for adding or decrementing values from an object in memcached + * 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. * */ -#include "libmemcached/common.h" +#include static memcached_return_t text_incr_decr(memcached_st *ptr, const char *verb, @@ -24,9 +50,6 @@ static memcached_return_t text_incr_decr(memcached_st *ptr, memcached_server_write_instance_st instance; bool no_reply= ptr->flags.no_reply; - if (memcached_server_count(ptr) == 0) - return memcached_set_error(ptr, MEMCACHED_NO_SERVERS, NULL); - if (ptr->flags.verify_key && (memcached_key_test((const char **)&key, &key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED)) return MEMCACHED_BAD_KEY_PROVIDED; @@ -103,7 +126,7 @@ static memcached_return_t binary_incr_decr(memcached_st *ptr, uint8_t cmd, if(cmd == PROTOCOL_BINARY_CMD_INCREMENT) cmd= PROTOCOL_BINARY_CMD_INCREMENTQ; } - protocol_binary_request_incr request= {.bytes= {0}}; + protocol_binary_request_incr request= {}; // = {.bytes= {0}}; request.message.header.request.magic= PROTOCOL_BINARY_REQ; request.message.header.request.opcode= cmd; @@ -117,9 +140,9 @@ static memcached_return_t binary_incr_decr(memcached_st *ptr, uint8_t cmd, struct libmemcached_io_vector_st vector[]= { - { .length= sizeof(request.bytes), .buffer= request.bytes }, - { .length= memcached_array_size(ptr->prefix_key), .buffer= ptr->prefix_key }, - { .length= key_length, .buffer= key } + { sizeof(request.bytes), request.bytes }, + { memcached_array_size(ptr->prefix_key), ptr->prefix_key }, + { key_length, key } }; memcached_return_t rc; @@ -131,6 +154,7 @@ static memcached_return_t binary_incr_decr(memcached_st *ptr, uint8_t cmd, if (no_reply) return MEMCACHED_SUCCESS; + return memcached_response(instance, (char*)value, sizeof(*value), NULL); } @@ -164,14 +188,21 @@ memcached_return_t memcached_increment_by_key(memcached_st *ptr, uint64_t offset, uint64_t *value) { - memcached_return_t rc= memcached_validate_key_length(key_length, ptr->flags.binary_protocol); - unlikely (rc != MEMCACHED_SUCCESS) - return rc; - + memcached_return_t rc; uint64_t local_value; - if (! value) + if (not value) value= &local_value; + if (memcached_failed(rc= initialize_query(ptr))) + { + return rc; + } + + if (memcached_failed(rc= memcached_validate_key_length(key_length, ptr->flags.binary_protocol))) + { + return rc; + } + LIBMEMCACHED_MEMCACHED_INCREMENT_START(); if (ptr->flags.binary_protocol) { @@ -196,14 +227,22 @@ memcached_return_t memcached_decrement_by_key(memcached_st *ptr, uint64_t offset, uint64_t *value) { - memcached_return_t rc= memcached_validate_key_length(key_length, ptr->flags.binary_protocol); - unlikely (rc != MEMCACHED_SUCCESS) - return rc; - uint64_t local_value; - if (! value) + if (not value) value= &local_value; + memcached_return_t rc; + if (memcached_failed(rc= initialize_query(ptr))) + { + return rc; + } + + if (memcached_failed(rc= memcached_validate_key_length(key_length, ptr->flags.binary_protocol))) + { + return rc; + } + + LIBMEMCACHED_MEMCACHED_DECREMENT_START(); if (ptr->flags.binary_protocol) { @@ -249,14 +288,21 @@ memcached_return_t memcached_increment_with_initial_by_key(memcached_st *ptr, time_t expiration, uint64_t *value) { - memcached_return_t rc= memcached_validate_key_length(key_length, ptr->flags.binary_protocol); - unlikely (rc != MEMCACHED_SUCCESS) - return rc; - uint64_t local_value; - if (! value) + if (not value) value= &local_value; + memcached_return_t rc; + if (memcached_failed(rc= initialize_query(ptr))) + { + return rc; + } + + if (memcached_failed(rc= memcached_validate_key_length(key_length, ptr->flags.binary_protocol))) + { + return rc; + } + LIBMEMCACHED_MEMCACHED_INCREMENT_WITH_INITIAL_START(); if (ptr->flags.binary_protocol) rc= binary_incr_decr(ptr, PROTOCOL_BINARY_CMD_INCREMENT, @@ -298,14 +344,22 @@ memcached_return_t memcached_decrement_with_initial_by_key(memcached_st *ptr, time_t expiration, uint64_t *value) { - memcached_return_t rc= memcached_validate_key_length(key_length, ptr->flags.binary_protocol); - unlikely (rc != MEMCACHED_SUCCESS) - return rc; - uint64_t local_value; - if (! value) + if (not value) value= &local_value; + memcached_return_t rc; + if (memcached_failed(rc= memcached_validate_key_length(key_length, ptr->flags.binary_protocol))) + { + return rc; + } + + if (memcached_failed(rc= initialize_query(ptr))) + { + return rc; + } + + LIBMEMCACHED_MEMCACHED_INCREMENT_WITH_INITIAL_START(); if (ptr->flags.binary_protocol) { diff --git a/libmemcached/auto.h b/libmemcached/auto.h index 14ee90b5..f37d50fc 100644 --- a/libmemcached/auto.h +++ b/libmemcached/auto.h @@ -1,16 +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: Change the behavior of the memcached connection. + * 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_AUTO_H__ -#define __LIBMEMCACHED_AUTO_H__ +#pragma once #ifdef __cplusplus extern "C" { @@ -84,5 +109,3 @@ LIBMEMCACHED_API #ifdef __cplusplus } #endif - -#endif /* __LIBMEMCACHED_AUTO_H__ */ diff --git a/libmemcached/behavior.c b/libmemcached/behavior.cc similarity index 100% rename from libmemcached/behavior.c rename to libmemcached/behavior.cc diff --git a/libmemcached/byteorder.c b/libmemcached/byteorder.c deleted file mode 100644 index 97d14f2b..00000000 --- a/libmemcached/byteorder.c +++ /dev/null @@ -1,43 +0,0 @@ -/* LibMemcached - * Copyright (C) 2006-2009 Brian Aker - * All rights reserved. - * - * Use and distribution licensed under the BSD license. See - * the COPYING file in the parent directory for full text. - * - * Summary: - * - */ - -#include "byteorder.h" - -/* Byte swap a 64-bit number. */ -#ifndef swap64 -static inline uint64_t swap64(uint64_t in) -{ -#ifndef WORDS_BIGENDIAN - /* Little endian, flip the bytes around until someone makes a faster/better - * way to do this. */ - uint64_t rv= 0; - for (uint8_t x= 0; x < 8; x++) - { - rv= (rv << 8) | (in & 0xff); - in >>= 8; - } - return rv; -#else - /* big-endian machines don't need byte swapping */ - return in; -#endif // WORDS_BIGENDIAN -} -#endif - -uint64_t memcached_ntohll(uint64_t value) -{ - return swap64(value); -} - -uint64_t memcached_htonll(uint64_t value) -{ - return swap64(value); -} diff --git a/libmemcached/byteorder.cc b/libmemcached/byteorder.cc new file mode 100644 index 00000000..ab35a9ef --- /dev/null +++ b/libmemcached/byteorder.cc @@ -0,0 +1,69 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * Copyright (C) 2006-2009 Brian Aker All rights reserved. + * + * 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. + * + */ + +#include + +/* Byte swap a 64-bit number. */ +#ifndef swap64 +static inline uint64_t swap64(uint64_t in) +{ +#ifndef WORDS_BIGENDIAN + /* Little endian, flip the bytes around until someone makes a faster/better + * way to do this. */ + uint64_t rv= 0; + for (uint8_t x= 0; x < 8; x++) + { + rv= (rv << 8) | (in & 0xff); + in >>= 8; + } + return rv; +#else + /* big-endian machines don't need byte swapping */ + return in; +#endif // WORDS_BIGENDIAN +} +#endif + +uint64_t memcached_ntohll(uint64_t value) +{ + return swap64(value); +} + +uint64_t memcached_htonll(uint64_t value) +{ + return swap64(value); +} diff --git a/libmemcached/byteorder.h b/libmemcached/byteorder.h index 90a71ee4..f78790a8 100644 --- a/libmemcached/byteorder.h +++ b/libmemcached/byteorder.h @@ -1,39 +1,62 @@ -/* 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: + * 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_BYTEORDER_H__ -#define __LIBMEMCACHED_BYTEORDER_H__ - -#include "config.h" +#pragma once #if HAVE_SYS_TYPES_H #include #endif - -/* Define this here, which will turn on the visibilty controls while we're - * building libmemcached. - */ -#define BUILDING_LIBMEMCACHED 1 - -#include "libmemcached/memcached.h" - #ifndef HAVE_HTONLL #define ntohll(a) memcached_ntohll(a) #define htonll(a) memcached_htonll(a) +#ifdef __cplusplus +extern "C" { +#endif + LIBMEMCACHED_LOCAL uint64_t memcached_ntohll(uint64_t); LIBMEMCACHED_LOCAL uint64_t memcached_htonll(uint64_t); +#ifdef __cplusplus +} +#endif + #endif #ifdef linux @@ -47,5 +70,3 @@ uint64_t memcached_htonll(uint64_t); #undef htons #undef htonl #endif - -#endif /*__LIBMEMCACHED_BYTEORDER_H__ */ diff --git a/libmemcached/callback.c b/libmemcached/callback.cc similarity index 97% rename from libmemcached/callback.c rename to libmemcached/callback.cc index dcb3ddeb..9818af4f 100644 --- a/libmemcached/callback.c +++ b/libmemcached/callback.cc @@ -9,9 +9,11 @@ * */ -#include "libmemcached/common.h" +#include #include +#pragma GCC diagnostic ignored "-Wstrict-aliasing" + /* These functions provide data and function callback support */ diff --git a/libmemcached/callback.h b/libmemcached/callback.h index 4c3a95f4..b4da8080 100644 --- a/libmemcached/callback.h +++ b/libmemcached/callback.h @@ -9,6 +9,7 @@ * */ +#pragma once #ifndef __LIBMEMCACHED_CALLBACK_H__ #define __LIBMEMCACHED_CALLBACK_H__ diff --git a/libmemcached/common.h b/libmemcached/common.h index d0a4ab4c..ec58fd8e 100644 --- a/libmemcached/common.h +++ b/libmemcached/common.h @@ -65,16 +65,14 @@ # endif #endif -/* Define this here, which will turn on the visibilty controls while we're - * building libmemcached. - */ -#define BUILDING_LIBMEMCACHED 1 - #include #include #include -#include + +#ifdef __cplusplus +extern "C" { +#endif typedef struct memcached_server_st * memcached_server_write_instance_st; @@ -87,6 +85,9 @@ LIBMEMCACHED_LOCAL memcached_return_t memcached_server_execute(memcached_st *ptr, memcached_server_execute_fn callback, void *context); +#ifdef __cplusplus +} // extern "C" +#endif /* These are private not to be installed headers */ diff --git a/libmemcached/connect.c b/libmemcached/connect.cc similarity index 88% rename from libmemcached/connect.c rename to libmemcached/connect.cc index a7b17f0c..1914bc0f 100644 --- a/libmemcached/connect.c +++ b/libmemcached/connect.cc @@ -1,14 +1,41 @@ -/* LibMemcached - * Copyright (C) 2006-2010 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-2010 Brian Aker All rights reserved. * - * Summary: Server IO, Not public! + * 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. * */ + #include #include #include @@ -87,7 +114,6 @@ static memcached_return_t connect_poll(memcached_server_st *ptr) static memcached_return_t set_hostinfo(memcached_server_st *server) { - struct addrinfo hints; char str_port[NI_MAXSERV]; assert(! server->address_info); // We cover the case where a programming mistake has been made. @@ -102,7 +128,8 @@ static memcached_return_t set_hostinfo(memcached_server_st *server) if (length >= NI_MAXSERV || length < 0) return MEMCACHED_FAILURE; - memset(&hints, 0, sizeof(hints)); + struct addrinfo hints; + memset(&hints, 0, sizeof(struct addrinfo)); #if 0 hints.ai_family= AF_INET; @@ -332,8 +359,6 @@ static memcached_return_t set_socket_options(memcached_server_st *ptr) static memcached_return_t unix_socket_connect(memcached_server_st *ptr) { #ifndef WIN32 - struct sockaddr_un servAddr; - WATCHPOINT_ASSERT(ptr->fd == -1); if ((ptr->fd= socket(AF_UNIX, SOCK_STREAM, 0)) < 0) @@ -342,6 +367,8 @@ static memcached_return_t unix_socket_connect(memcached_server_st *ptr) return MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE; } + struct sockaddr_un servAddr; + memset(&servAddr, 0, sizeof (struct sockaddr_un)); servAddr.sun_family= AF_UNIX; strncpy(servAddr.sun_path, ptr->hostname, sizeof(servAddr.sun_path)); /* Copy filename */ diff --git a/libmemcached/delete.c b/libmemcached/delete.cc similarity index 96% rename from libmemcached/delete.c rename to libmemcached/delete.cc index 78f08f26..1005cb90 100644 --- a/libmemcached/delete.c +++ b/libmemcached/delete.cc @@ -194,15 +194,19 @@ static inline memcached_return_t binary_delete(memcached_st *ptr, bool flush) { memcached_server_write_instance_st instance; - protocol_binary_request_delete request= {.bytes= {0}}; + protocol_binary_request_delete request= {}; instance= memcached_server_instance_fetch(ptr, server_key); request.message.header.request.magic= PROTOCOL_BINARY_REQ; if (ptr->flags.no_reply) + { request.message.header.request.opcode= PROTOCOL_BINARY_CMD_DELETEQ; + } else + { request.message.header.request.opcode= PROTOCOL_BINARY_CMD_DELETE; + } request.message.header.request.keylen= htons((uint16_t)(key_length + memcached_array_size(ptr->prefix_key))); request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; request.message.header.request.bodylen= htonl((uint32_t)(key_length + memcached_array_size(ptr->prefix_key))); @@ -218,9 +222,9 @@ static inline memcached_return_t binary_delete(memcached_st *ptr, struct libmemcached_io_vector_st vector[]= { - { .length= sizeof(request.bytes), .buffer= request.bytes}, - { .length= memcached_array_size(ptr->prefix_key), .buffer= memcached_array_string(ptr->prefix_key) }, - { .length= key_length, .buffer= key }, + { sizeof(request.bytes), request.bytes}, + { memcached_array_size(ptr->prefix_key), memcached_array_string(ptr->prefix_key) }, + { key_length, key }, }; memcached_return_t rc= MEMCACHED_SUCCESS; diff --git a/libmemcached/delete.h b/libmemcached/delete.h index 8d0d7eda..617d5857 100644 --- a/libmemcached/delete.h +++ b/libmemcached/delete.h @@ -1,16 +1,42 @@ -/* LibMemcached - * Copyright (C) 2010 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) 2010 Brian Aker All rights reserved. * - * Summary: Delete a key from the server. + * 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_DELETE_H__ -#define __LIBMEMCACHED_DELETE_H__ + +#pragma once #ifdef __cplusplus extern "C" { @@ -29,5 +55,3 @@ memcached_return_t memcached_delete_by_key(memcached_st *ptr, #ifdef __cplusplus } #endif - -#endif /* __LIBMEMCACHED_DELETE_H__ */ diff --git a/libmemcached/do.c b/libmemcached/do.cc similarity index 100% rename from libmemcached/do.c rename to libmemcached/do.cc diff --git a/libmemcached/dump.c b/libmemcached/dump.cc similarity index 100% rename from libmemcached/dump.c rename to libmemcached/dump.cc diff --git a/libmemcached/error.cc b/libmemcached/error.cc index ef207a95..02169a28 100644 --- a/libmemcached/error.cc +++ b/libmemcached/error.cc @@ -139,7 +139,7 @@ void memcached_error_print(const memcached_st *self) static void _error_free(memcached_error_t *error) { - if (! error) + if (not error) return; _error_free(error->next); @@ -156,10 +156,11 @@ static void _error_free(memcached_error_t *error) void memcached_error_free(memcached_st *self) { - if (! self) + if (not self) return; _error_free(self->error_messages); + self->error_messages= NULL; } const char *memcached_last_error_message(memcached_st *memc) diff --git a/libmemcached/flush.c b/libmemcached/flush.cc similarity index 65% rename from libmemcached/flush.c rename to libmemcached/flush.cc index 8da6b5b5..6a1364c2 100644 --- a/libmemcached/flush.c +++ b/libmemcached/flush.cc @@ -1,4 +1,40 @@ -#include "common.h" +/* 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. + * + */ + +#include static memcached_return_t memcached_flush_binary(memcached_st *ptr, time_t expiration); @@ -8,7 +44,7 @@ static memcached_return_t memcached_flush_textual(memcached_st *ptr, memcached_return_t memcached_flush(memcached_st *ptr, time_t expiration) { memcached_return_t rc; - if ((rc= initialize_query(ptr)) != MEMCACHED_SUCCESS) + if (memcached_failed(rc= initialize_query(ptr))) { return rc; } @@ -67,7 +103,7 @@ static memcached_return_t memcached_flush_textual(memcached_st *ptr, static memcached_return_t memcached_flush_binary(memcached_st *ptr, time_t expiration) { - protocol_binary_request_flush request= {.bytes= {0}}; + protocol_binary_request_flush request= {}; unlikely (memcached_server_count(ptr) == 0) return MEMCACHED_NO_SERVERS; diff --git a/libmemcached/flush.h b/libmemcached/flush.h index 36c07598..820a98e7 100644 --- a/libmemcached/flush.h +++ b/libmemcached/flush.h @@ -1,16 +1,41 @@ -/* LibMemcached - * Copyright (C) 2010 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) 2010 Brian Aker All rights reserved. * - * Summary: Flush connections. + * 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_FLUSH_H__ -#define __LIBMEMCACHED_FLUSH_H__ +#pragma once #ifdef __cplusplus extern "C" { @@ -22,5 +47,3 @@ memcached_return_t memcached_flush(memcached_st *ptr, time_t expiration); #ifdef __cplusplus } #endif - -#endif /* __LIBMEMCACHED_FLUSH_H__ */ diff --git a/libmemcached/flush_buffers.c b/libmemcached/flush_buffers.c deleted file mode 100644 index 649db983..00000000 --- a/libmemcached/flush_buffers.c +++ /dev/null @@ -1,29 +0,0 @@ -#include "common.h" - -memcached_return_t memcached_flush_buffers(memcached_st *memc) -{ - memcached_return_t ret= MEMCACHED_SUCCESS; - - for (uint32_t x= 0; x < memcached_server_count(memc); ++x) - { - memcached_server_write_instance_st instance= - memcached_server_instance_fetch(memc, x); - - if (instance->write_buffer_offset != 0) - { - if (instance->fd == -1 && - (ret= memcached_connect(instance)) != MEMCACHED_SUCCESS) - { - WATCHPOINT_ERROR(ret); - return ret; - } - - if (memcached_io_write(instance, NULL, 0, true) == -1) - { - ret= MEMCACHED_SOME_ERRORS; - } - } - } - - return ret; -} diff --git a/libmemcached/flush_buffers.cc b/libmemcached/flush_buffers.cc new file mode 100644 index 00000000..bb3c4dec --- /dev/null +++ b/libmemcached/flush_buffers.cc @@ -0,0 +1,66 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * Copyright (C) 2010 Brian Aker All rights reserved. + * + * 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. + * + */ + +#include + +memcached_return_t memcached_flush_buffers(memcached_st *memc) +{ + memcached_return_t ret= MEMCACHED_SUCCESS; + + for (uint32_t x= 0; x < memcached_server_count(memc); ++x) + { + memcached_server_write_instance_st instance= + memcached_server_instance_fetch(memc, x); + + if (instance->write_buffer_offset != 0) + { + if (instance->fd == -1 && + (ret= memcached_connect(instance)) != MEMCACHED_SUCCESS) + { + WATCHPOINT_ERROR(ret); + return ret; + } + + if (memcached_io_write(instance, NULL, 0, true) == -1) + { + ret= MEMCACHED_SOME_ERRORS; + } + } + } + + return ret; +} diff --git a/libmemcached/flush_buffers.h b/libmemcached/flush_buffers.h index 88d8a81c..31b58687 100644 --- a/libmemcached/flush_buffers.h +++ b/libmemcached/flush_buffers.h @@ -1,16 +1,41 @@ -/* LibMemcached - * Copyright (C) 2010 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) 2010 Brian Aker All rights reserved. * - * Summary: Work with fetching results + * 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_FLUSH_BUFFERS_H__ -#define __LIBMEMCACHED_FLUSH_BUFFERS_H__ +#pragma once #ifdef __cplusplus extern "C" { @@ -22,5 +47,3 @@ memcached_return_t memcached_flush_buffers(memcached_st *mem); #ifdef __cplusplus } #endif - -#endif /* __LIBMEMCACHED_FLUSH_BUFFERS_H__ */ diff --git a/libmemcached/get.c b/libmemcached/get.cc similarity index 91% rename from libmemcached/get.c rename to libmemcached/get.cc index 46b6319c..29d01bc8 100644 --- a/libmemcached/get.c +++ b/libmemcached/get.cc @@ -151,7 +151,7 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr, bool is_group_key_set= false; memcached_return_t rc; - if ((rc= initialize_query(ptr)) != MEMCACHED_SUCCESS) + if (memcached_failed(rc= initialize_query(ptr))) { return rc; } @@ -165,12 +165,15 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr, return MEMCACHED_NOTFOUND; if (ptr->flags.verify_key && (memcached_key_test(keys, key_length, number_of_keys) == MEMCACHED_BAD_KEY_PROVIDED)) + { return MEMCACHED_BAD_KEY_PROVIDED; + } if (group_key && group_key_length) { - if (ptr->flags.verify_key && (memcached_key_test((const char * const *)&group_key, &group_key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED)) + if (ptr->flags.verify_key and (memcached_key_test((const char * const *)&group_key, &group_key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED)) return MEMCACHED_BAD_KEY_PROVIDED; + master_server_key= memcached_generate_hash_with_redistribution(ptr, group_key, group_key_length); is_group_key_set= true; } @@ -234,10 +237,10 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr, struct libmemcached_io_vector_st vector[]= { - { .length= get_command_length, .buffer= get_command }, - { .length= memcached_array_size(ptr->prefix_key), .buffer= memcached_array_string(ptr->prefix_key) }, - { .length= key_length[x], .buffer= keys[x] }, - { .length= 1, .buffer= " " } + { get_command_length, get_command }, + { memcached_array_size(ptr->prefix_key), memcached_array_string(ptr->prefix_key) }, + { key_length[x], keys[x] }, + { 1, " " } }; @@ -356,9 +359,9 @@ memcached_return_t memcached_mget_execute_by_key(memcached_st *ptr, memcached_return_t rc; memcached_callback_st *original_callbacks= ptr->callbacks; memcached_callback_st cb= { - .callback= callback, - .context= context, - .number_of_callback= number_of_callbacks + callback, + context, + number_of_callbacks }; ptr->callbacks= &cb; @@ -406,7 +409,7 @@ static memcached_return_t simple_binary_mget(memcached_st *ptr, continue; } - protocol_binary_request_getk request= {.bytes= {0}}; + protocol_binary_request_getk request= { }; //= {.bytes= {0}}; request.message.header.request.magic= PROTOCOL_BINARY_REQ; if (mget_mode) request.message.header.request.opcode= PROTOCOL_BINARY_CMD_GETKQ; @@ -432,9 +435,9 @@ static memcached_return_t simple_binary_mget(memcached_st *ptr, struct libmemcached_io_vector_st vector[]= { - { .length= sizeof(request.bytes), .buffer= request.bytes }, - { .length= memcached_array_size(ptr->prefix_key), .buffer= memcached_array_string(ptr->prefix_key) }, - { .length= key_length[x], .buffer= keys[x] } + { sizeof(request.bytes), request.bytes }, + { memcached_array_size(ptr->prefix_key), memcached_array_string(ptr->prefix_key) }, + { key_length[x], keys[x] } }; if (memcached_io_writev(instance, vector, 3, flush) == -1) @@ -456,9 +459,9 @@ static memcached_return_t simple_binary_mget(memcached_st *ptr, if (mget_mode) { /* - * Send a noop command to flush the buffers - */ - protocol_binary_request_noop request= {.bytes= {0}}; + Send a noop command to flush the buffers + */ + protocol_binary_request_noop request= {}; //= {.bytes= {0}}; request.message.header.request.magic= PROTOCOL_BINARY_REQ; request.message.header.request.opcode= PROTOCOL_BINARY_CMD_NOOP; request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; @@ -544,15 +547,12 @@ static memcached_return_t replication_binary_mget(memcached_st *ptr, } } - protocol_binary_request_getk request= { - .message.header.request= { - .magic= PROTOCOL_BINARY_REQ, - .opcode= PROTOCOL_BINARY_CMD_GETK, - .keylen= htons((uint16_t)(key_length[x] + memcached_array_size(ptr->prefix_key))), - .datatype= PROTOCOL_BINARY_RAW_BYTES, - .bodylen= htonl((uint32_t)(key_length[x] + memcached_array_size(ptr->prefix_key))) - } - }; + protocol_binary_request_getk request= {}; + request.message.header.request.magic= PROTOCOL_BINARY_REQ; + request.message.header.request.opcode= PROTOCOL_BINARY_CMD_GETK; + request.message.header.request.keylen= htons((uint16_t)(key_length[x] + memcached_array_size(ptr->prefix_key))); + request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; + request.message.header.request.bodylen= htonl((uint32_t)(key_length[x] + memcached_array_size(ptr->prefix_key))); /* * We need to disable buffering to actually know that the request was @@ -566,9 +566,9 @@ static memcached_return_t replication_binary_mget(memcached_st *ptr, */ struct libmemcached_io_vector_st vector[]= { - { .length= sizeof(request.bytes), .buffer= request.bytes }, - { .length= memcached_array_size(ptr->prefix_key), .buffer= memcached_array_string(ptr->prefix_key) }, - { .length= key_length[x], .buffer= keys[x] } + { sizeof(request.bytes), request.bytes }, + { memcached_array_size(ptr->prefix_key), memcached_array_string(ptr->prefix_key) }, + { key_length[x], keys[x] } }; if (memcached_io_writev(instance, vector, 3, true) == -1) @@ -610,8 +610,8 @@ static memcached_return_t binary_mget_by_key(memcached_st *ptr, uint32_t* hash; bool* dead_servers; - hash= libmemcached_malloc(ptr, sizeof(uint32_t) * number_of_keys); - dead_servers= libmemcached_calloc(ptr, memcached_server_count(ptr), sizeof(bool)); + hash= static_cast(libmemcached_malloc(ptr, sizeof(uint32_t) * number_of_keys)); + dead_servers= static_cast(libmemcached_calloc(ptr, memcached_server_count(ptr), sizeof(bool))); if (hash == NULL || dead_servers == NULL) { diff --git a/libmemcached/hash.c b/libmemcached/hash.cc similarity index 99% rename from libmemcached/hash.c rename to libmemcached/hash.cc index e5f87a75..0e6295b8 100644 --- a/libmemcached/hash.c +++ b/libmemcached/hash.cc @@ -108,7 +108,7 @@ static inline uint32_t _generate_hash_wrapper(const memcached_st *ptr, const cha if (ptr->flags.hash_with_prefix_key) { size_t temp_length= memcached_array_size(ptr->prefix_key) + key_length; - char temp[temp_length]; + char temp[MEMCACHED_MAX_KEY]; if (temp_length > MEMCACHED_MAX_KEY -1) return 0; diff --git a/libmemcached/hosts.c b/libmemcached/hosts.cc similarity index 95% rename from libmemcached/hosts.c rename to libmemcached/hosts.cc index 7e687667..14b45589 100644 --- a/libmemcached/hosts.c +++ b/libmemcached/hosts.cc @@ -152,8 +152,8 @@ static memcached_return_t update_continuum(memcached_st *ptr) { memcached_continuum_item_st *new_ptr; - new_ptr= libmemcached_realloc(ptr, ptr->ketama.continuum, - sizeof(memcached_continuum_item_st) * (live_servers + MEMCACHED_CONTINUUM_ADDITION) * points_per_server); + new_ptr= static_cast(libmemcached_realloc(ptr, ptr->ketama.continuum, + sizeof(memcached_continuum_item_st) * (live_servers + MEMCACHED_CONTINUUM_ADDITION) * points_per_server)); if (new_ptr == 0) return MEMCACHED_MEMORY_ALLOCATION_FAILURE; @@ -310,17 +310,16 @@ static memcached_return_t update_continuum(memcached_st *ptr) memcached_return_t memcached_server_push(memcached_st *ptr, const memcached_server_list_st list) { - uint32_t count; - memcached_server_st *new_host_list; - - if (! list) + if (not list) return MEMCACHED_SUCCESS; - count= memcached_server_list_count(list); - new_host_list= libmemcached_realloc(ptr, memcached_server_list(ptr), - sizeof(memcached_server_st) * (count + memcached_server_count(ptr))); + uint32_t count= memcached_server_list_count(list); + + memcached_server_st *new_host_list; + new_host_list= static_cast(libmemcached_realloc(ptr, memcached_server_list(ptr), + sizeof(memcached_server_st) * (count + memcached_server_count(ptr)))); - if (! new_host_list) + if (not new_host_list) return MEMCACHED_MEMORY_ALLOCATION_FAILURE; memcached_server_list_set(ptr, new_host_list); @@ -431,8 +430,8 @@ static memcached_return_t server_add(memcached_st *ptr, const char *hostname, || ( (type == MEMCACHED_CONNECTION_UDP) && (! ptr->flags.use_udp) ) ) return MEMCACHED_INVALID_HOST_PROTOCOL; - new_host_list= libmemcached_realloc(ptr, memcached_server_list(ptr), - sizeof(memcached_server_st) * (ptr->number_of_hosts + 1)); + new_host_list= static_cast(libmemcached_realloc(ptr, memcached_server_list(ptr), + sizeof(memcached_server_st) * (ptr->number_of_hosts + 1))); if (new_host_list == NULL) return MEMCACHED_MEMORY_ALLOCATION_FAILURE; diff --git a/libmemcached/include.am b/libmemcached/include.am index f243f12f..28c5513a 100644 --- a/libmemcached/include.am +++ b/libmemcached/include.am @@ -71,104 +71,73 @@ nobase_include_HEADERS+= \ libmemcached/visibility.h \ libmemcached/watchpoint.h -lib_LTLIBRARIES+= libmemcached/libmemcachedprotocol.la -libmemcached_libmemcachedprotocol_la_SOURCES = \ - libmemcached/protocol/ascii_handler.c \ - libmemcached/protocol/binary_handler.c \ - libmemcached/protocol/cache.c \ - libmemcached/protocol/pedantic.c \ - libmemcached/protocol/protocol_handler.c - -libmemcached_libmemcachedprotocol_la_CFLAGS= ${AM_CFLAGS} ${NO_CONVERSION} ${PTHREAD_CFLAGS} -libmemcached_libmemcachedprotocol_la_LDFLAGS= ${AM_LDFLAGS} ${PTHREAD_LIBS} -version-info ${MEMCACHED_PROTOCAL_LIBRARY_VERSION} - -noinst_LTLIBRARIES+= \ - libmemcached/libmemcachedcallbacks.la - -libmemcached_libmemcachedcallbacks_la_CFLAGS = ${AM_CFLAGS} ${NO_STRICT_ALIASING} -libmemcached_libmemcachedcallbacks_la_SOURCES = libmemcached/callback.c - # This noinst lib contains things we want to be ABI private but still want to # either use in client programs or be able to test in test cases # These symbols will not be exposed in the shipped .so noinst_LTLIBRARIES+= libmemcached/libmemcachedinternal.la libmemcached_libmemcachedinternal_la_SOURCES= \ libmemcached/error.cc \ - libmemcached/string.c + libmemcached/string.cc lib_LTLIBRARIES+= libmemcached/libmemcached.la -libmemcached_libmemcached_la_CFLAGS= ${AM_CFLAGS} ${NO_CONVERSION} +libmemcached_libmemcached_la_CFLAGS= \ + ${AM_CFLAGS} \ + ${NO_CONVERSION} \ + -DBUILDING_LIBMEMCACHED + +libmemcached_libmemcached_la_CXXFLAGS= \ + ${AM_CXXFLAGS} \ + ${NO_CONVERSION} \ + -DBUILDING_LIBMEMCACHED + libmemcached_libmemcached_la_SOURCES+= \ - libmemcached/allocators.c \ - libmemcached/analyze.c \ + ${libhashkit_libhashkit_la_SOURCES} \ + libmemcached/allocators.cc \ + libmemcached/analyze.cc \ libmemcached/array.c \ - libmemcached/auto.c \ - libmemcached/behavior.c \ - libmemcached/connect.c \ - libmemcached/delete.c \ - libmemcached/do.c \ - libmemcached/dump.c \ + libmemcached/auto.cc \ + libmemcached/behavior.cc \ + libmemcached/byteorder.cc \ + libmemcached/callback.cc \ + libmemcached/connect.cc \ + libmemcached/delete.cc \ + libmemcached/do.cc \ + libmemcached/dump.cc \ + libmemcached/error.cc \ libmemcached/fetch.c \ - libmemcached/flush.c \ - libmemcached/flush_buffers.c \ - libmemcached/get.c \ - libmemcached/hash.c \ - libmemcached/hosts.c \ + libmemcached/flush.cc \ + libmemcached/flush_buffers.cc \ + libmemcached/get.cc \ + libmemcached/hash.cc \ + libmemcached/hosts.cc \ libmemcached/initialize_query.cc \ - libmemcached/io.c \ - libmemcached/key.c \ - libmemcached/memcached.c \ + libmemcached/io.cc \ + libmemcached/key.cc \ + libmemcached/memcached.cc \ libmemcached/options.cc \ - libmemcached/parse.c \ + libmemcached/parse.cc \ libmemcached/prefix_key.cc \ - libmemcached/purge.c \ - libmemcached/quit.c \ - libmemcached/response.c \ - libmemcached/result.c \ - libmemcached/server.c \ - libmemcached/server_list.c \ - libmemcached/stats.c \ - libmemcached/storage.c \ - libmemcached/strerror.c \ - libmemcached/verbosity.c \ - libmemcached/version.c \ + libmemcached/purge.cc \ + libmemcached/quit.cc \ + libmemcached/response.cc \ + libmemcached/result.cc \ + libmemcached/server.cc \ + libmemcached/server_list.cc \ + libmemcached/stats.cc \ + libmemcached/storage.cc \ + libmemcached/strerror.cc \ + libmemcached/string.cc \ + libmemcached/verbosity.cc \ + libmemcached/version.cc \ libmemcached/virtual_bucket.c libmemcached/options.cc: libmemcached/options/parser.h -libmemcached_libmemcached_la_DEPENDENCIES= libmemcached/libmemcachedcallbacks.la libmemcached/libmemcachedinternal.la libhashkit/libhashkitinc.la -libmemcached_libmemcached_la_LIBADD= $(LIBM) libmemcached/libmemcachedcallbacks.la libmemcached/libmemcachedinternal.la libhashkit/libhashkitinc.la +libmemcached_libmemcached_la_DEPENDENCIES= +libmemcached_libmemcached_la_LIBADD= $(LIBM) libmemcached_libmemcached_la_LDFLAGS= ${AM_LDFLAGS} -version-info ${MEMCACHED_LIBRARY_VERSION} -if BUILD_LIBMEMCACHEDUTIL -nobase_include_HEADERS+= \ - libmemcached/memcached_util.h \ - libmemcached/util.h \ - libmemcached/util/ping.h \ - libmemcached/util/pool.h \ - libmemcached/util/version.h -lib_LTLIBRARIES+= libmemcached/libmemcachedutil.la -endif - -libmemcached_libmemcachedutil_la_SOURCES= \ - libmemcached/util/ping.cc \ - libmemcached/util/pool.cc \ - libmemcached/util/version.cc -libmemcached_libmemcachedutil_la_CFLAGS= ${AM_CFLAGS} ${NO_CONVERSION} ${PTHREAD_CFLAGS} -libmemcached_libmemcachedutil_la_LIBADD= libmemcached/libmemcached.la -libmemcached_libmemcachedutil_la_LDFLAGS= ${AM_LDFLAGS} ${PTHREAD_LIBS} -version-info ${MEMCACHED_UTIL_LIBRARY_VERSION} -libmemcached_libmemcachedutil_la_DEPENDENCIES= libmemcached/libmemcached.la - -if BUILD_BYTEORDER -noinst_LTLIBRARIES += libmemcached/libbyteorder.la -libmemcached_libbyteorder_la_SOURCES= libmemcached/byteorder.c -libmemcached_libmemcached_la_LIBADD += libmemcached/libbyteorder.la -libmemcached_libmemcached_la_DEPENDENCIES+= libmemcached/libbyteorder.la -libmemcached_libmemcachedprotocol_la_LIBADD=libmemcached/libbyteorder.la -libmemcached_libmemcachedprotocol_la_DEPENDENCIES=libmemcached/libbyteorder.la -endif - if HAVE_SASL libmemcached_libmemcached_la_LDFLAGS+= $(LTLIBSASL) $(LTLIBSASL2) libmemcached_libmemcached_la_SOURCES += libmemcached/sasl.c diff --git a/libmemcached/initialize_query.cc b/libmemcached/initialize_query.cc index abc8dfdc..31a15fbc 100644 --- a/libmemcached/initialize_query.cc +++ b/libmemcached/initialize_query.cc @@ -35,13 +35,14 @@ */ #include -#include memcached_return_t initialize_query(memcached_st *self) { - if (! self) + if (not self) return MEMCACHED_INVALID_ARGUMENTS; + self->query_id++; + if (self->state.is_time_for_rebuild) { memcached_reset(self); @@ -52,15 +53,12 @@ memcached_return_t initialize_query(memcached_st *self) return memcached_set_error(self, MEMCACHED_NO_SERVERS, NULL); } - - self->query_id++; - return MEMCACHED_SUCCESS; } memcached_return_t initialize_const_query(const memcached_st *self) { - if (! self) + if (not self) return MEMCACHED_INVALID_ARGUMENTS; if (memcached_server_count(self) == 0) diff --git a/libmemcached/internal.h b/libmemcached/internal.h index 743bf870..67ae67d5 100644 --- a/libmemcached/internal.h +++ b/libmemcached/internal.h @@ -1,18 +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: Internal functions used by the library. Not for public use! + * 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_INTERNAL_H__ -#define __LIBMEMCACHED_INTERNAL_H__ - -#if defined(BUILDING_LIBMEMCACHED) +#pragma once #ifdef __cplusplus extern "C" { @@ -21,6 +44,3 @@ extern "C" { #ifdef __cplusplus } #endif - -#endif /* BUILDING_LIBMEMCACHED */ -#endif /* __LIBMEMCACHED_INTERNAL_H__ */ diff --git a/libmemcached/io.c b/libmemcached/io.cc similarity index 98% rename from libmemcached/io.c rename to libmemcached/io.cc index 5acbbd52..74aa4a23 100644 --- a/libmemcached/io.c +++ b/libmemcached/io.cc @@ -52,10 +52,10 @@ static void increment_udp_message_id(memcached_server_write_instance_st ptr); static memcached_return_t io_wait(memcached_server_write_instance_st ptr, memc_read_or_write read_or_write) { - struct pollfd fds= { - .fd= ptr->fd, - .events = POLLIN - }; + struct pollfd fds; + fds.fd= ptr->fd; + fds.events= POLLIN; + int error; if (read_or_write == MEM_WRITE) /* write */ @@ -259,11 +259,11 @@ memcached_return_t memcached_io_read(memcached_server_write_instance_st ptr, { char *buffer_ptr; - buffer_ptr= buffer; + buffer_ptr= static_cast(buffer); while (length) { - if (!ptr->read_buffer_length) + if (not ptr->read_buffer_length) { ssize_t data_read; @@ -360,7 +360,7 @@ static ssize_t _io_write(memcached_server_write_instance_st ptr, WATCHPOINT_ASSERT(ptr->fd != INVALID_SOCKET); original_length= length; - buffer_ptr= buffer; + buffer_ptr= static_cast(buffer); while (length) { @@ -705,7 +705,7 @@ memcached_return_t memcached_safe_read(memcached_server_write_instance_st ptr, size_t size) { size_t offset= 0; - char *data= dta; + char *data= static_cast(dta); while (offset < size) { diff --git a/libmemcached/io.h b/libmemcached/io.h index 85d56b16..a5d34474 100644 --- a/libmemcached/io.h +++ b/libmemcached/io.h @@ -36,12 +36,9 @@ * */ -#ifndef __LIBMEMCACHED_IO_H__ -#define __LIBMEMCACHED_IO_H__ +#pragma once -#if defined(BUILDING_LIBMEMCACHED) - -#include "libmemcached/memcached.h" +#include #define MAX_UDP_DATAGRAM_LENGTH 1400 #define UDP_DATAGRAM_HEADER_LENGTH 8 @@ -117,7 +114,3 @@ memcached_server_write_instance_st memcached_io_get_readable_server(memcached_st #ifdef __cplusplus } #endif - -#endif /* BUILDING_LIBMEMCACHED */ - -#endif /* __LIBMEMCACHED_IO_H__ */ diff --git a/libmemcached/key.c b/libmemcached/key.cc similarity index 77% rename from libmemcached/key.c rename to libmemcached/key.cc index 76a7d8ed..c2c2b14b 100644 --- a/libmemcached/key.c +++ b/libmemcached/key.cc @@ -4,18 +4,14 @@ memcached_return_t memcached_key_test(const char * const *keys, const size_t *key_length, size_t number_of_keys) { - uint32_t x; - memcached_return_t rc; - - for (x= 0; x < number_of_keys; x++) + for (uint32_t x= 0; x < number_of_keys; x++) { - size_t y; - + memcached_return_t rc; rc= memcached_validate_key_length(*(key_length + x), false); if (rc != MEMCACHED_SUCCESS) return rc; - for (y= 0; y < *(key_length + x); y++) + for (size_t y= 0; y < *(key_length + x); y++) { if ((isgraph(keys[x][y])) == 0) return MEMCACHED_BAD_KEY_PROVIDED; diff --git a/libmemcached/memcached.c b/libmemcached/memcached.cc similarity index 92% rename from libmemcached/memcached.c rename to libmemcached/memcached.cc index c57b2577..1197dd5d 100644 --- a/libmemcached/memcached.c +++ b/libmemcached/memcached.cc @@ -38,10 +38,11 @@ #include #include +#if 0 static const memcached_st global_copy= { .state= { - .is_purging= false, - .is_processing_input= false, + .is_purging= false, // .is_purging + .is_processing_input= false, // is_processing_input .is_time_for_rebuild= false, }, .flags= { @@ -60,11 +61,28 @@ static const memcached_st global_copy= { .tcp_keepalive= false, }, }; +#endif static inline bool _memcached_init(memcached_st *self) { - self->state= global_copy.state; - self->flags= global_copy.flags; + self->state.is_purging= false; + self->state.is_processing_input= false; + self->state.is_time_for_rebuild= false; + + self->flags.auto_eject_hosts= false; + self->flags.binary_protocol= false; + self->flags.buffer_requests= false; + self->flags.hash_with_prefix_key= false; + self->flags.no_block= false; + self->flags.no_reply= false; + self->flags.randomize_replica_read= false; + self->flags.support_cas= false; + self->flags.tcp_nodelay= false; + self->flags.use_sort_hosts= false; + self->flags.use_udp= false; + self->flags.verify_key= false; + self->flags.tcp_keepalive= false; + self->virtual_bucket= NULL; self->distribution= MEMCACHED_DISTRIBUTION_MODULA; @@ -87,7 +105,7 @@ static inline bool _memcached_init(memcached_st *self) self->snd_timeout= 0; self->rcv_timeout= 0; self->server_failure_limit= 0; - self->query_id= 0; + self->query_id= 1; // 0 is considered invalid /* TODO, Document why we picked these defaults */ self->io_msg_watermark= 500; @@ -249,7 +267,7 @@ memcached_st *memcached(const char *string, size_t length) memcached_return_t memcached_reset(memcached_st *ptr) { WATCHPOINT_ASSERT(ptr); - if (! ptr) + if (not ptr) return MEMCACHED_INVALID_ARGUMENTS; bool stored_is_allocated= memcached_is_allocated(ptr); @@ -436,3 +454,11 @@ memcached_server_instance_st memcached_server_instance_by_position(const memcach { return &ptr->servers[server_key]; } + +uint64_t memcached_query_id(const memcached_st *self) +{ + if (not self) + return 0; + + return self->query_id; +} diff --git a/libmemcached/memcached.h b/libmemcached/memcached.h index 1baab961..f32fe0e7 100644 --- a/libmemcached/memcached.h +++ b/libmemcached/memcached.h @@ -57,6 +57,7 @@ #include #include #include + // Everything above this line must be in the order specified. #include #include @@ -142,13 +143,7 @@ struct memcached_st { struct memcached_virtual_bucket_t *virtual_bucket; - struct _allocators_st { - memcached_calloc_fn calloc; - memcached_free_fn free; - memcached_malloc_fn malloc; - memcached_realloc_fn realloc; - void *context; - } allocators; + struct memcached_allocator_t allocators; memcached_clone_fn on_clone; memcached_cleanup_fn on_cleanup; @@ -210,6 +205,9 @@ memcached_server_instance_st memcached_server_instance_by_position(const memcach LIBMEMCACHED_API uint32_t memcached_server_count(const memcached_st *); +LIBMEMCACHED_API +uint64_t memcached_query_id(const memcached_st *); + #ifdef __cplusplus } // extern "C" #endif diff --git a/libmemcached/memcached.hpp b/libmemcached/memcached.hpp index 55f96c7e..b0985715 100644 --- a/libmemcached/memcached.hpp +++ b/libmemcached/memcached.hpp @@ -13,8 +13,6 @@ */ #pragma once -#ifndef LIBMEMCACHEDPP_H -#define LIBMEMCACHEDPP_H #include #include @@ -37,8 +35,7 @@ class Memcache { public: - Memcache() - : + Memcache() : servers_list(), memc(), result() @@ -261,17 +258,12 @@ public: * this vector * @return true on success; false otherwise */ - bool get(const std::string &key, - std::vector &ret_val) throw (Error) + bool get(const std::string &key, std::vector &ret_val) { uint32_t flags= 0; memcached_return_t rc; size_t value_length= 0; - if (key.empty()) - { - throw(Error("the key supplied is empty!", false)); - } char *value= memcached_get(&memc, key.c_str(), key.length(), &value_length, &flags, &rc); if (value != NULL && ret_val.empty()) @@ -298,16 +290,12 @@ public: */ bool getByKey(const std::string &master_key, const std::string &key, - std::vector &ret_val) throw(Error) + std::vector &ret_val) { uint32_t flags= 0; memcached_return_t rc; size_t value_length= 0; - if (master_key.empty() || key.empty()) - { - throw(Error("the master key or key supplied is empty!", false)); - } char *value= memcached_get_by_key(&memc, master_key.c_str(), master_key.length(), key.c_str(), key.length(), @@ -379,12 +367,8 @@ public: bool set(const std::string &key, const std::vector &value, time_t expiration, - uint32_t flags) throw(Error) + uint32_t flags) { - if (key.empty() || value.empty()) - { - throw(Error("the key or value supplied is empty!", false)); - } memcached_return_t rc= memcached_set(&memc, key.c_str(), key.length(), &value[0], value.size(), @@ -407,14 +391,8 @@ public: const std::string &key, const std::vector &value, time_t expiration, - uint32_t flags) throw(Error) + uint32_t flags) { - if (master_key.empty() || - key.empty() || - value.empty()) - { - throw(Error("the key or value supplied is empty!", false)); - } memcached_return_t rc= memcached_set_by_key(&memc, master_key.c_str(), master_key.length(), key.c_str(), key.length(), @@ -437,12 +415,8 @@ public: bool setAll(std::vector &keys, std::vector< std::vector *> &values, time_t expiration, - uint32_t flags) throw(Error) + uint32_t flags) { - if (keys.size() != values.size()) - { - throw(Error("The number of keys and values do not match!", false)); - } bool retval= true; std::vector::iterator key_it= keys.begin(); std::vector< std::vector *>::iterator val_it= values.begin(); @@ -470,23 +444,18 @@ public: */ bool setAll(std::map > &key_value_map, time_t expiration, - uint32_t flags) throw(Error) + uint32_t flags) { - if (key_value_map.empty()) - { - throw(Error("The key/values are not properly set!", false)); - } bool retval= true; - std::map >::iterator it= - key_value_map.begin(); + std::map >::iterator it= key_value_map.begin(); + while (it != key_value_map.end()) { retval= set(it->first, it->second, expiration, flags); if (retval == false) { - std::string err_buff("There was an error setting the key "); - err_buff.append(it->first); - throw(Error(err_buff, false)); + // We should tell the user what the key that failed was + return false; } ++it; } @@ -503,12 +472,8 @@ public: * @param[out] value store the result of the increment here * @return true on success; false otherwise */ - bool increment(const std::string &key, uint32_t offset, uint64_t *value) throw(Error) + bool increment(const std::string &key, uint32_t offset, uint64_t *value) { - if (key.empty()) - { - throw(Error("the key supplied is empty!", false)); - } memcached_return_t rc= memcached_increment(&memc, key.c_str(), key.length(), offset, value); return (rc == MEMCACHED_SUCCESS); @@ -525,12 +490,7 @@ public: * @return true on success; false otherwise */ bool decrement(const std::string &key, uint32_t offset, uint64_t *value) - throw(Error) { - if (key.empty()) - { - throw(Error("the key supplied is empty!", false)); - } memcached_return_t rc= memcached_decrement(&memc, key.c_str(), key.length(), offset, value); @@ -547,12 +507,7 @@ public: * @return true on success; false otherwise */ bool add(const std::string &key, const std::vector &value) - throw(Error) { - if (key.empty() || value.empty()) - { - throw(Error("the key or value supplied is empty!", false)); - } memcached_return_t rc= memcached_add(&memc, key.c_str(), key.length(), &value[0], value.size(), 0, 0); return (rc == MEMCACHED_SUCCESS); @@ -570,14 +525,8 @@ public: */ bool addByKey(const std::string &master_key, const std::string &key, - const std::vector &value) throw(Error) + const std::vector &value) { - if (master_key.empty() || - key.empty() || - value.empty()) - { - throw(Error("the master key or key supplied is empty!", false)); - } memcached_return_t rc= memcached_add_by_key(&memc, master_key.c_str(), master_key.length(), @@ -597,13 +546,8 @@ public: * @param[in[ value value to replace object with * @return true on success; false otherwise */ - bool replace(const std::string &key, const std::vector &value) throw(Error) + bool replace(const std::string &key, const std::vector &value) { - if (key.empty() || - value.empty()) - { - throw(Error("the key or value supplied is empty!", false)); - } memcached_return_t rc= memcached_replace(&memc, key.c_str(), key.length(), &value[0], value.size(), 0, 0); @@ -624,12 +568,6 @@ public: const std::string &key, const std::vector &value) { - if (master_key.empty() || - key.empty() || - value.empty()) - { - throw(Error("the master key or key supplied is empty!", false)); - } memcached_return_t rc= memcached_replace_by_key(&memc, master_key.c_str(), master_key.length(), @@ -649,12 +587,7 @@ public: * @return true on success; false otherwise */ bool prepend(const std::string &key, const std::vector &value) - throw(Error) { - if (key.empty() || value.empty()) - { - throw(Error("the key or value supplied is empty!", false)); - } memcached_return_t rc= memcached_prepend(&memc, key.c_str(), key.length(), &value[0], value.size(), 0, 0); return (rc == MEMCACHED_SUCCESS); @@ -673,14 +606,7 @@ public: bool prependByKey(const std::string &master_key, const std::string &key, const std::vector &value) - throw(Error) { - if (master_key.empty() || - key.empty() || - value.empty()) - { - throw(Error("the master key or key supplied is empty!", false)); - } memcached_return_t rc= memcached_prepend_by_key(&memc, master_key.c_str(), master_key.length(), @@ -701,18 +627,13 @@ public: * @return true on success; false otherwise */ bool append(const std::string &key, const std::vector &value) - throw(Error) { - if (key.empty() || value.empty()) - { - throw(Error("the key or value supplied is empty!", false)); - } memcached_return_t rc= memcached_append(&memc, - key.c_str(), - key.length(), - &value[0], - value.size(), - 0, 0); + key.c_str(), + key.length(), + &value[0], + value.size(), + 0, 0); return (rc == MEMCACHED_SUCCESS); } @@ -729,22 +650,15 @@ public: bool appendByKey(const std::string &master_key, const std::string &key, const std::vector &value) - throw(Error) { - if (master_key.empty() || - key.empty() || - value.empty()) - { - throw(Error("the master key or key supplied is empty!", false)); - } memcached_return_t rc= memcached_append_by_key(&memc, - master_key.c_str(), - master_key.length(), - key.c_str(), - key.length(), - &value[0], - value.size(), - 0, 0); + master_key.c_str(), + master_key.length(), + key.c_str(), + key.length(), + &value[0], + value.size(), + 0, 0); return (rc == MEMCACHED_SUCCESS); } @@ -758,12 +672,8 @@ public: */ bool cas(const std::string &key, const std::vector &value, - uint64_t cas_arg) throw(Error) + uint64_t cas_arg) { - if (key.empty() || value.empty()) - { - throw(Error("the key or value supplied is empty!", false)); - } memcached_return_t rc= memcached_cas(&memc, key.c_str(), key.length(), &value[0], value.size(), 0, 0, cas_arg); @@ -783,14 +693,8 @@ public: bool casByKey(const std::string &master_key, const std::string &key, const std::vector &value, - uint64_t cas_arg) throw(Error) + uint64_t cas_arg) { - if (master_key.empty() || - key.empty() || - value.empty()) - { - throw(Error("the master key, key or value supplied is empty!", false)); - } memcached_return_t rc= memcached_cas_by_key(&memc, master_key.c_str(), master_key.length(), @@ -808,12 +712,8 @@ public: * @param[in] key key of object to delete * @return true on success; false otherwise */ - bool remove(const std::string &key) throw(Error) + bool remove(const std::string &key) { - if (key.empty()) - { - throw(Error("the key supplied is empty!", false)); - } memcached_return_t rc= memcached_delete(&memc, key.c_str(), key.length(), 0); return (rc == MEMCACHED_SUCCESS); } @@ -825,13 +725,8 @@ public: * @param[in] expiration time to delete the object after * @return true on success; false otherwise */ - bool remove(const std::string &key, - time_t expiration) throw(Error) + bool remove(const std::string &key, time_t expiration) { - if (key.empty()) - { - throw(Error("the key supplied is empty!", false)); - } memcached_return_t rc= memcached_delete(&memc, key.c_str(), key.length(), @@ -847,12 +742,8 @@ public: * @return true on success; false otherwise */ bool removeByKey(const std::string &master_key, - const std::string &key) throw(Error) + const std::string &key) { - if (master_key.empty() || key.empty()) - { - throw(Error("the master key or key supplied is empty!", false)); - } memcached_return_t rc= memcached_delete_by_key(&memc, master_key.c_str(), master_key.length(), @@ -872,12 +763,8 @@ public: */ bool removeByKey(const std::string &master_key, const std::string &key, - time_t expiration) throw(Error) + time_t expiration) { - if (master_key.empty() || key.empty()) - { - throw(Error("the master key or key supplied is empty!", false)); - } memcached_return_t rc= memcached_delete_by_key(&memc, master_key.c_str(), master_key.length(), @@ -900,27 +787,6 @@ public: return (rc == MEMCACHED_SUCCESS); } - /** - * Callback function for result sets. It passes the result - * sets to the list of functions provided. - * - * @param[in] callback list of callback functions - * @param[in] context pointer to memory reference that is - * supplied to the calling function - * @param[in] num_of_callbacks number of callback functions - * @return true on success; false otherwise - */ - bool fetchExecute(memcached_execute_fn *callback, - void *context, - uint32_t num_of_callbacks) - { - memcached_return_t rc= memcached_fetch_execute(&memc, - callback, - context, - num_of_callbacks); - return (rc == MEMCACHED_SUCCESS); - } - /** * Get the library version string. * @return std::string containing a copy of the library version string. @@ -996,5 +862,3 @@ private: }; } - -#endif /* LIBMEMCACHEDPP_H */ diff --git a/libmemcached/memcached/protocol_binary.h b/libmemcached/memcached/protocol_binary.h index 4509bbcb..7a253ae7 100644 --- a/libmemcached/memcached/protocol_binary.h +++ b/libmemcached/memcached/protocol_binary.h @@ -218,12 +218,13 @@ extern "C" /** * Definition of a request-packet containing no extras */ - typedef union { + union protocol_binary_request_no_extras { struct { protocol_binary_request_header header; } message; uint8_t bytes[sizeof(protocol_binary_request_header)]; - } protocol_binary_request_no_extras; + }; + typedef union protocol_binary_request_no_extras protocol_binary_request_no_extras; /** * Definition of a response-packet containing no extras diff --git a/libmemcached/options/context.h b/libmemcached/options/context.h index bbca66c8..226284d9 100644 --- a/libmemcached/options/context.h +++ b/libmemcached/options/context.h @@ -90,7 +90,7 @@ public: const char *set_hostname(const char *str, size_t size) { - size_t copy_length= std::min((size_t)NI_MAXHOST, size); + size_t copy_length= (size_t)NI_MAXHOST > size ? size : (size_t)NI_MAXHOST; memcpy(_hostname, str, copy_length); _hostname[copy_length]= 0; diff --git a/libmemcached/parse.c b/libmemcached/parse.c deleted file mode 100644 index 85860ef3..00000000 --- a/libmemcached/parse.c +++ /dev/null @@ -1,73 +0,0 @@ -/* - I debated about putting this in the client library since it does an - action I don't really believe belongs in the library. - - Frankly its too damn useful not to be here though. -*/ - -#include "common.h" - -memcached_server_list_st memcached_servers_parse(const char *server_strings) -{ - char *string; - const char *begin_ptr; - const char *end_ptr; - memcached_server_st *servers= NULL; - memcached_return_t rc; - - WATCHPOINT_ASSERT(server_strings); - - end_ptr= server_strings + strlen(server_strings); - - for (begin_ptr= server_strings, string= index(server_strings, ','); - begin_ptr != end_ptr; - string= index(begin_ptr, ',')) - { - char buffer[HUGE_STRING_LEN]; - char *ptr, *ptr2; - uint32_t weight= 0; - - if (string) - { - memcpy(buffer, begin_ptr, (size_t) (string - begin_ptr)); - buffer[(unsigned int)(string - begin_ptr)]= 0; - begin_ptr= string+1; - } - else - { - size_t length= strlen(begin_ptr); - memcpy(buffer, begin_ptr, length); - buffer[length]= 0; - begin_ptr= end_ptr; - } - - ptr= index(buffer, ':'); - - in_port_t port= 0; - if (ptr) - { - ptr[0]= 0; - - ptr++; - - port= (in_port_t) strtoul(ptr, (char **)NULL, 10); - - ptr2= index(ptr, ' '); - if (! ptr2) - ptr2= index(ptr, ':'); - - if (ptr2) - { - ptr2++; - weight = (uint32_t) strtoul(ptr2, (char **)NULL, 10); - } - } - - servers= memcached_server_list_append_with_weight(servers, buffer, port, weight, &rc); - - if (isspace(*begin_ptr)) - begin_ptr++; - } - - return servers; -} diff --git a/libmemcached/parse.cc b/libmemcached/parse.cc new file mode 100644 index 00000000..3284a4f6 --- /dev/null +++ b/libmemcached/parse.cc @@ -0,0 +1,110 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * Copyright (C) 2006-2009 Brian Aker All rights reserved. + * + * 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. + * + */ + +/* + I debated about putting this in the client library since it does an + action I don't really believe belongs in the library. + + Frankly its too damn useful not to be here though. +*/ + +#include + +memcached_server_list_st memcached_servers_parse(const char *server_strings) +{ + char *string; + const char *begin_ptr; + const char *end_ptr; + memcached_server_st *servers= NULL; + memcached_return_t rc; + + WATCHPOINT_ASSERT(server_strings); + + end_ptr= server_strings + strlen(server_strings); + + for (begin_ptr= server_strings, string= (char *)index(server_strings, ','); + begin_ptr != end_ptr; + string= (char *)index(begin_ptr, ',')) + { + char buffer[HUGE_STRING_LEN]; + char *ptr, *ptr2; + uint32_t weight= 0; + + if (string) + { + memcpy(buffer, begin_ptr, (size_t) (string - begin_ptr)); + buffer[(unsigned int)(string - begin_ptr)]= 0; + begin_ptr= string+1; + } + else + { + size_t length= strlen(begin_ptr); + memcpy(buffer, begin_ptr, length); + buffer[length]= 0; + begin_ptr= end_ptr; + } + + ptr= index(buffer, ':'); + + in_port_t port= 0; + if (ptr) + { + ptr[0]= 0; + + ptr++; + + port= (in_port_t) strtoul(ptr, (char **)NULL, 10); + + ptr2= index(ptr, ' '); + if (! ptr2) + ptr2= index(ptr, ':'); + + if (ptr2) + { + ptr2++; + weight = (uint32_t) strtoul(ptr2, (char **)NULL, 10); + } + } + + servers= memcached_server_list_append_with_weight(servers, buffer, port, weight, &rc); + + if (isspace(*begin_ptr)) + begin_ptr++; + } + + return servers; +} diff --git a/libmemcached/protocol/ascii_handler.c b/libmemcached/protocol/ascii_handler.c index 465b7396..5e7307ae 100644 --- a/libmemcached/protocol/ascii_handler.c +++ b/libmemcached/protocol/ascii_handler.c @@ -1,10 +1,48 @@ -/* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */ -#include "libmemcached/protocol/common.h" +/* 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. + * + */ + +#include "config.h" + +#include +#include #include -#include -#include #include +#include +#include /** * Try to parse a key from the string. diff --git a/libmemcached/protocol/ascii_handler.h b/libmemcached/protocol/ascii_handler.h index 02a1a82d..02f8831e 100644 --- a/libmemcached/protocol/ascii_handler.h +++ b/libmemcached/protocol/ascii_handler.h @@ -1,8 +1,40 @@ -/* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */ -#ifndef LIBMEMCACHED_PROTOCOL_ASCII_HANDLER_H -#define LIBMEMCACHED_PROTOCOL_ASCII_HANDLER_H +/* 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 LIBMEMCACHED_LOCAL memcached_protocol_event_t memcached_ascii_protocol_process_data(memcached_protocol_client_st *client, ssize_t *length, void **endptr); - -#endif diff --git a/libmemcached/protocol/binary_handler.c b/libmemcached/protocol/binary_handler.c index a9e4ce95..93fb3162 100644 --- a/libmemcached/protocol/binary_handler.c +++ b/libmemcached/protocol/binary_handler.c @@ -1,5 +1,41 @@ -/* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */ -#include "libmemcached/protocol/common.h" +/* 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. + * + */ + +#include +#include #include #include diff --git a/libmemcached/protocol/binary_handler.h b/libmemcached/protocol/binary_handler.h index a21165b2..d5a74e78 100644 --- a/libmemcached/protocol/binary_handler.h +++ b/libmemcached/protocol/binary_handler.h @@ -1,6 +1,40 @@ -/* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */ -#ifndef LIBMEMCACHED_PROTOCOL_BINARY_HANDLER_H -#define LIBMEMCACHED_PROTOCOL_BINARY_HANDLER_H +/* 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 LIBMEMCACHED_LOCAL bool memcached_binary_protocol_pedantic_check_request(const protocol_binary_request_header *request); @@ -11,5 +45,3 @@ bool memcached_binary_protocol_pedantic_check_response(const protocol_binary_req LIBMEMCACHED_LOCAL memcached_protocol_event_t memcached_binary_protocol_process_data(memcached_protocol_client_st *client, ssize_t *length, void **endptr); - -#endif diff --git a/libmemcached/protocol/common.h b/libmemcached/protocol/common.h index 185aef0b..808a6086 100644 --- a/libmemcached/protocol/common.h +++ b/libmemcached/protocol/common.h @@ -1,6 +1,40 @@ -/* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */ -#ifndef LIBMEMCACHED_PROTOCOL_COMMON_H -#define LIBMEMCACHED_PROTOCOL_COMMON_H +/* 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 "config.h" #if !defined(__cplusplus) @@ -8,12 +42,7 @@ #endif #include -/* Define this here, which will turn on the visibilty controls while we're - * building libmemcached. - */ -#define BUILDING_LIBMEMCACHED 1 - -#include +#include #include #include @@ -132,5 +161,3 @@ struct memcached_protocol_client_st { #include "ascii_handler.h" #include "binary_handler.h" - -#endif diff --git a/libmemcached/protocol/include.am b/libmemcached/protocol/include.am new file mode 100644 index 00000000..9c4c1bc2 --- /dev/null +++ b/libmemcached/protocol/include.am @@ -0,0 +1,26 @@ +# vim:ft=automake +# included from Top Level Makefile.am +# All paths should be given relative to the root + + +lib_LTLIBRARIES+= libmemcached/libmemcachedprotocol.la +libmemcached_libmemcachedprotocol_la_SOURCES= \ + libmemcached/byteorder.cc \ + libmemcached/protocol/ascii_handler.c \ + libmemcached/protocol/binary_handler.c \ + libmemcached/protocol/cache.c \ + libmemcached/protocol/pedantic.c \ + libmemcached/protocol/protocol_handler.c + +libmemcached_libmemcachedprotocol_la_CFLAGS= \ + ${AM_CFLAGS} \ + ${NO_CONVERSION} \ + ${PTHREAD_CFLAGS} \ + -DBUILDING_LIBMEMCACHED + +libmemcached_libmemcachedprotocol_la_CXXFLAGS= \ + ${AM_CXXFLAGS} \ + ${PTHREAD_CFLAGS} \ + -DBUILDING_LIBMEMCACHED + +libmemcached_libmemcachedprotocol_la_LDFLAGS= ${AM_LDFLAGS} ${PTHREAD_LIBS} -version-info ${MEMCACHED_PROTOCAL_LIBRARY_VERSION} diff --git a/libmemcached/purge.c b/libmemcached/purge.cc similarity index 100% rename from libmemcached/purge.c rename to libmemcached/purge.cc diff --git a/libmemcached/quit.c b/libmemcached/quit.cc similarity index 63% rename from libmemcached/quit.c rename to libmemcached/quit.cc index 6d72906c..2efe909b 100644 --- a/libmemcached/quit.c +++ b/libmemcached/quit.cc @@ -1,4 +1,41 @@ -#include "common.h" +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * Copyright (C) 2010 Brian Aker All rights reserved. + * + * 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. + * + */ + +#include /* This closes all connections (forces flush of input as well). @@ -22,7 +59,7 @@ void memcached_quit_server(memcached_server_st *ptr, bool io_death) if (ptr->root->flags.binary_protocol) { - protocol_binary_request_quit request = {.bytes= {0}}; + protocol_binary_request_quit request= {}; // = {.bytes= {0}}; request.message.header.request.magic = PROTOCOL_BINARY_REQ; request.message.header.request.opcode = PROTOCOL_BINARY_CMD_QUIT; request.message.header.request.datatype = PROTOCOL_BINARY_RAW_BYTES; diff --git a/libmemcached/quit.h b/libmemcached/quit.h index e640020a..0338eaf0 100644 --- a/libmemcached/quit.h +++ b/libmemcached/quit.h @@ -1,16 +1,41 @@ -/* LibMemcached - * Copyright (C) 2010 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) 2010 Brian Aker All rights reserved. * - * Summary: returns a human readable string for the error message + * 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_QUIT_H__ -#define __LIBMEMCACHED_QUIT_H__ +#pragma once #ifdef __cplusplus extern "C" { @@ -28,5 +53,3 @@ void send_quit(memcached_st *ptr); #ifdef __cplusplus } #endif - -#endif /* __LIBMEMCACHED_QUIT_H__ */ diff --git a/libmemcached/response.c b/libmemcached/response.cc similarity index 90% rename from libmemcached/response.c rename to libmemcached/response.cc index 49825fb1..572aef58 100644 --- a/libmemcached/response.c +++ b/libmemcached/response.cc @@ -1,15 +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: memcached_response() is used to determine the return result from an issued command. + * 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. + * + */ -#include "common.h" +#include static memcached_return_t textual_read_one_response(memcached_server_write_instance_st ptr, char *buffer, size_t buffer_length, diff --git a/libmemcached/response.h b/libmemcached/response.h index da6f2b42..51f09998 100644 --- a/libmemcached/response.h +++ b/libmemcached/response.h @@ -1,16 +1,41 @@ -/* LibMemcached - * Copyright (C) 2010 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) 2010 Brian Aker All rights reserved. * - * Summary: Change the behavior of the memcached connection. + * 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_RESPONSE_H__ -#define __LIBMEMCACHED_RESPONSE_H__ +#pragma once #ifdef __cplusplus extern "C" { @@ -30,5 +55,3 @@ memcached_return_t memcached_response(memcached_server_write_instance_st ptr, #ifdef __cplusplus } #endif - -#endif /* __LIBMEMCACHED_RESPONSE_H__ */ diff --git a/libmemcached/result.c b/libmemcached/result.cc similarity index 62% rename from libmemcached/result.c rename to libmemcached/result.cc index 6e58eebd..1d0b763d 100644 --- a/libmemcached/result.c +++ b/libmemcached/result.cc @@ -1,21 +1,48 @@ -/* 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. * */ + /* memcached_result_st are used to internally represent the return values from memcached. We use a structure so that long term as identifiers are added to memcached we will be able to absorb new attributes without having to addjust the entire API. */ -#include "common.h" +#include static inline void _result_init(memcached_result_st *self, memcached_st *memc) @@ -40,7 +67,7 @@ memcached_result_st *memcached_result_create(const memcached_st *memc, } else { - ptr= libmemcached_malloc(memc, sizeof(memcached_result_st)); + ptr= static_cast(libmemcached_malloc(memc, sizeof(memcached_result_st))); if (ptr == NULL) return NULL; diff --git a/libmemcached/return.h b/libmemcached/return.h index c7aa6003..048c0670 100644 --- a/libmemcached/return.h +++ b/libmemcached/return.h @@ -90,4 +90,5 @@ enum memcached_return_t { typedef enum memcached_return_t memcached_return_t; #endif +#define memcached_failed(A) (A) != MEMCACHED_SUCCESS ? true : false diff --git a/libmemcached/server.c b/libmemcached/server.cc similarity index 92% rename from libmemcached/server.c rename to libmemcached/server.cc index 4fe676b0..1eb50ee4 100644 --- a/libmemcached/server.c +++ b/libmemcached/server.cc @@ -218,11 +218,8 @@ memcached_server_instance_st memcached_server_by_key(const memcached_st *ptr, size_t key_length, memcached_return_t *error) { - uint32_t server_key; - memcached_server_instance_st instance; - memcached_return_t rc; - if ((rc= initialize_const_query(ptr)) != MEMCACHED_SUCCESS) + if (memcached_failed(rc= initialize_const_query(ptr))) { if (error) *error= rc; @@ -230,7 +227,7 @@ memcached_server_instance_st memcached_server_by_key(const memcached_st *ptr, return NULL; } - if ((rc= memcached_validate_key_length(key_length, ptr->flags.binary_protocol)) != MEMCACHED_SUCCESS) + if (memcached_failed(rc= memcached_validate_key_length(key_length, ptr->flags.binary_protocol))) { if (error) *error= rc; @@ -240,21 +237,20 @@ memcached_server_instance_st memcached_server_by_key(const memcached_st *ptr, if (ptr->flags.verify_key && (memcached_key_test((const char **)&key, &key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED)) { - *error= MEMCACHED_BAD_KEY_PROVIDED; + if (error) + *error= MEMCACHED_BAD_KEY_PROVIDED; return NULL; } - server_key= memcached_generate_hash(ptr, key, key_length); - instance= memcached_server_instance_by_position(ptr, server_key); - - return instance; + uint32_t server_key= memcached_generate_hash(ptr, key, key_length); + return memcached_server_instance_by_position(ptr, server_key); } void memcached_server_error_reset(memcached_server_st *self) { WATCHPOINT_ASSERT(self); - if (! self) + if (not self) return; self->cached_server_error[0]= 0; @@ -263,7 +259,7 @@ void memcached_server_error_reset(memcached_server_st *self) memcached_server_instance_st memcached_server_get_last_disconnect(const memcached_st *self) { WATCHPOINT_ASSERT(self); - if (! self) + if (not self) return 0; return self->last_disconnected_server; @@ -271,7 +267,7 @@ memcached_server_instance_st memcached_server_get_last_disconnect(const memcache void memcached_server_list_free(memcached_server_list_st self) { - if (self == NULL) + if (not self) return; for (uint32_t x= 0; x < memcached_server_list_count(self); x++) @@ -297,7 +293,7 @@ void memcached_server_list_free(memcached_server_list_st self) uint32_t memcached_servers_set_count(memcached_server_st *servers, uint32_t count) { WATCHPOINT_ASSERT(servers); - if (! servers) + if (not servers) return 0; return servers->number_of_hosts= count; @@ -306,7 +302,7 @@ uint32_t memcached_servers_set_count(memcached_server_st *servers, uint32_t coun uint32_t memcached_server_count(const memcached_st *self) { WATCHPOINT_ASSERT(self); - if (! self) + if (not self) return 0; return self->number_of_hosts; @@ -315,7 +311,7 @@ uint32_t memcached_server_count(const memcached_st *self) const char *memcached_server_name(memcached_server_instance_st self) { WATCHPOINT_ASSERT(self); - if (! self) + if (not self) return NULL; return self->hostname; @@ -324,7 +320,7 @@ const char *memcached_server_name(memcached_server_instance_st self) in_port_t memcached_server_port(memcached_server_instance_st self) { WATCHPOINT_ASSERT(self); - if (! self) + if (not self) return 0; return self->port; @@ -333,7 +329,7 @@ in_port_t memcached_server_port(memcached_server_instance_st self) uint32_t memcached_server_response_count(memcached_server_instance_st self) { WATCHPOINT_ASSERT(self); - if (! self) + if (not self) return 0; return self->cursor_active; @@ -341,8 +337,6 @@ uint32_t memcached_server_response_count(memcached_server_instance_st self) const char *memcached_server_error(memcached_server_instance_st ptr) { - return ptr - ? ptr->cached_server_error - : NULL; + return ptr ? ptr->cached_server_error : NULL; } diff --git a/libmemcached/server_list.c b/libmemcached/server_list.cc similarity index 100% rename from libmemcached/server_list.c rename to libmemcached/server_list.cc diff --git a/libmemcached/stats.c b/libmemcached/stats.cc similarity index 96% rename from libmemcached/stats.c rename to libmemcached/stats.cc index 45b530e4..08934ba6 100644 --- a/libmemcached/stats.c +++ b/libmemcached/stats.cc @@ -34,6 +34,14 @@ struct local_context memcached_stat_fn func; void *context; const char *args; + + local_context(memcached_stat_fn func_arg, + void *context_arg, + const char *args_arg) : + func(func_arg), + context(context_arg), + args(args_arg) + { } }; @@ -234,7 +242,7 @@ char *memcached_stat_get_value(const memcached_st *ptr, memcached_stat_st *memc_ return NULL; } - ret= libmemcached_malloc(ptr, (size_t) (length + 1)); + ret= static_cast(libmemcached_malloc(ptr, (size_t) (length + 1))); memcpy(ret, buffer, (size_t) length); ret[length]= '\0'; @@ -249,7 +257,7 @@ static memcached_return_t binary_stats_fetch(memcached_stat_st *memc_stat, memcached_return_t rc; char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; - protocol_binary_request_stats request= {.bytes= {0}}; + protocol_binary_request_stats request= {}; // = {.bytes= {0}}; request.message.header.request.magic= PROTOCOL_BINARY_REQ; request.message.header.request.opcode= PROTOCOL_BINARY_CMD_STAT; request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; @@ -267,8 +275,8 @@ static memcached_return_t binary_stats_fetch(memcached_stat_st *memc_stat, struct libmemcached_io_vector_st vector[]= { - { .length= sizeof(request.bytes), .buffer= request.bytes }, - { .length= len, .buffer= args } + { sizeof(request.bytes), request.bytes }, + { len, args } }; if (memcached_vdo(instance, vector, 2, true) != MEMCACHED_SUCCESS) @@ -423,7 +431,7 @@ memcached_stat_st *memcached_stat(memcached_st *self, char *args, memcached_retu return NULL; } - stats= libmemcached_calloc(self, memcached_server_count(self), sizeof(memcached_stat_st)); + stats= static_cast(libmemcached_calloc(self, memcached_server_count(self), sizeof(memcached_stat_st))); if (! stats) { @@ -516,9 +524,9 @@ char ** memcached_stat_get_keys(const memcached_st *ptr, (void)memc_stat; - list= libmemcached_malloc(ptr, length); + list= static_cast(libmemcached_malloc(ptr, length)); - if (! list) + if (not list) { *error= MEMCACHED_MEMORY_ALLOCATION_FAILURE; return NULL; @@ -576,7 +584,7 @@ memcached_return_t memcached_stat_execute(memcached_st *memc, const char *args, { memcached_version(memc); - struct local_context check= { .func= func, .context= context, .args= args }; + struct local_context check(func, context, args); return memcached_server_execute(memc, call_stat_fn, (void *)&check); } diff --git a/libmemcached/storage.c b/libmemcached/storage.cc similarity index 95% rename from libmemcached/storage.c rename to libmemcached/storage.cc index 135def30..006393c4 100644 --- a/libmemcached/storage.c +++ b/libmemcached/storage.cc @@ -9,16 +9,16 @@ * */ -#include "common.h" +#include -typedef enum { +enum memcached_storage_action_t { SET_OP, REPLACE_OP, ADD_OP, PREPEND_OP, APPEND_OP, - CAS_OP, -} memcached_storage_action_t; + CAS_OP +}; /* Inline this */ static inline const char *storage_op_string(memcached_storage_action_t verb) @@ -74,13 +74,12 @@ static inline memcached_return_t memcached_send(memcached_st *ptr, WATCHPOINT_ASSERT(!(value == NULL && value_length > 0)); memcached_return_t rc; - if ((rc= initialize_query(ptr)) != MEMCACHED_SUCCESS) + if (memcached_failed(rc= initialize_query(ptr))) { return rc; } - rc= memcached_validate_key_length(key_length, ptr->flags.binary_protocol); - unlikely (rc != MEMCACHED_SUCCESS) + if (memcached_failed(rc= memcached_validate_key_length(key_length, ptr->flags.binary_protocol))) return rc; if (ptr->flags.verify_key && (memcached_key_test((const char **)&key, &key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED)) @@ -133,10 +132,10 @@ static inline memcached_return_t memcached_send(memcached_st *ptr, memcpy(buffer_ptr, command, strlen(command)); /* Copy in the key prefix, switch to the buffer_ptr */ - buffer_ptr= memcpy((buffer_ptr + strlen(command)), memcached_array_string(ptr->prefix_key), memcached_array_size(ptr->prefix_key)); + buffer_ptr= (char *)memcpy((char *)(buffer_ptr + strlen(command)), (char *)memcached_array_string(ptr->prefix_key), memcached_array_size(ptr->prefix_key)); /* Copy in the key, adjust point if a key prefix was used. */ - buffer_ptr= memcpy(buffer_ptr + memcached_array_size(ptr->prefix_key), + buffer_ptr= (char *)memcpy(buffer_ptr + memcached_array_size(ptr->prefix_key), key, key_length); buffer_ptr+= key_length; buffer_ptr[0]= ' '; @@ -178,9 +177,9 @@ static inline memcached_return_t memcached_send(memcached_st *ptr, { struct libmemcached_io_vector_st vector[]= { - { .length= write_length, .buffer= buffer }, - { .length= value_length, .buffer= value }, - { .length= 2, .buffer= "\r\n" } + { write_length, buffer }, + { value_length, value }, + { 2, "\r\n" } }; if (ptr->flags.buffer_requests && verb == SET_OP) @@ -473,7 +472,7 @@ static memcached_return_t memcached_send_binary(memcached_st *ptr, memcached_storage_action_t verb) { bool flush; - protocol_binary_request_set request= {.bytes= {0}}; + protocol_binary_request_set request= {}; size_t send_length= sizeof(request.bytes); bool noreply= server->root->flags.no_reply; @@ -515,10 +514,10 @@ static memcached_return_t memcached_send_binary(memcached_st *ptr, struct libmemcached_io_vector_st vector[]= { - { .length= send_length, .buffer= request.bytes }, - { .length= memcached_array_size(ptr->prefix_key), .buffer= memcached_array_string(ptr->prefix_key) }, - { .length= key_length, .buffer= key }, - { .length= value_length, .buffer= value } + { send_length, request.bytes }, + { memcached_array_size(ptr->prefix_key), memcached_array_string(ptr->prefix_key) }, + { key_length, key }, + { value_length, value } }; /* write the header */ diff --git a/libmemcached/strerror.c b/libmemcached/strerror.cc similarity index 100% rename from libmemcached/strerror.c rename to libmemcached/strerror.cc diff --git a/libmemcached/string.c b/libmemcached/string.cc similarity index 66% rename from libmemcached/string.c rename to libmemcached/string.cc index b5badc5e..4f012795 100644 --- a/libmemcached/string.c +++ b/libmemcached/string.cc @@ -1,15 +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. * */ -#include "common.h" + +#include inline static memcached_return_t _string_check(memcached_string_st *string, size_t need) { @@ -29,7 +56,7 @@ inline static memcached_return_t _string_check(memcached_string_st *string, size if (new_size < need) return MEMCACHED_MEMORY_ALLOCATION_FAILURE; - new_value= libmemcached_realloc(string->root, string->string, new_size); + new_value= static_cast(libmemcached_realloc(string->root, string->string, new_size)); if (new_value == NULL) { @@ -66,7 +93,7 @@ memcached_string_st *memcached_string_create(const memcached_st *memc, memcached } else { - self= libmemcached_malloc(memc, sizeof(memcached_string_st)); + self= static_cast(libmemcached_malloc(memc, sizeof(memcached_string_st))); if (self == NULL) { @@ -75,7 +102,7 @@ memcached_string_st *memcached_string_create(const memcached_st *memc, memcached self->options.is_allocated= true; } - self->root= (memcached_st *)memc; + self->root= const_cast(memc); _init_string(self); @@ -145,7 +172,7 @@ char *memcached_string_c_copy(memcached_string_st *string) if (memcached_string_length(string) == 0) return NULL; - c_ptr= libmemcached_malloc(string->root, (memcached_string_length(string)+1) * sizeof(char)); + c_ptr= static_cast(libmemcached_malloc(string->root, (memcached_string_length(string)+1) * sizeof(char))); if (c_ptr == NULL) return NULL; diff --git a/libmemcached/string.h b/libmemcached/string.h index ca3dad14..8c57c8b0 100644 --- a/libmemcached/string.h +++ b/libmemcached/string.h @@ -1,17 +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: 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. * */ #pragma once -#ifndef __LIBMEMCACHED_STRING_H__ -#define __LIBMEMCACHED_STRING_H__ /** Strings are always under our control so we make some assumptions @@ -97,5 +121,3 @@ void memcached_string_set_length(memcached_string_st *self, size_t length); #define memcached_string_make_from_cstr(X) (X), ((X) ? strlen(X) : 0) #endif - -#endif /* __LIBMEMCACHED_STRING_H__ */ diff --git a/libmemcached/types.h b/libmemcached/types.h index 2ebb8c00..b3d8f479 100644 --- a/libmemcached/types.h +++ b/libmemcached/types.h @@ -9,6 +9,7 @@ * */ +#pragma once #ifndef __LIBMEMCACHED_TYPES_H__ #define __LIBMEMCACHED_TYPES_H__ diff --git a/libmemcached/util/include.am b/libmemcached/util/include.am new file mode 100644 index 00000000..2c452f52 --- /dev/null +++ b/libmemcached/util/include.am @@ -0,0 +1,32 @@ +# vim:ft=automake +# included from Top Level Makefile.am +# All paths should be given relative to the root + +if BUILD_LIBMEMCACHEDUTIL +nobase_include_HEADERS+= \ + libmemcached/memcached_util.h \ + libmemcached/util.h \ + libmemcached/util/ping.h \ + libmemcached/util/pool.h \ + libmemcached/util/version.h +lib_LTLIBRARIES+= libmemcached/libmemcachedutil.la +endif + +libmemcached_libmemcachedutil_la_SOURCES= \ + libmemcached/util/ping.cc \ + libmemcached/util/pool.cc \ + libmemcached/util/version.cc +libmemcached_libmemcachedutil_la_CFLAGS= \ + ${AM_CFLAGS} \ + ${NO_CONVERSION} \ + ${PTHREAD_CFLAGS} \ + -DBUILDING_LIBMEMCACHED +libmemcached_libmemcachedutil_la_CXXFLAGS= \ + ${AM_CXXFLAGS} \ + ${NO_CONVERSION} \ + ${PTHREAD_CFLAGS} \ + -DBUILDING_LIBMEMCACHED +libmemcached_libmemcachedutil_la_LIBADD= libmemcached/libmemcached.la +libmemcached_libmemcachedutil_la_LDFLAGS= ${AM_LDFLAGS} ${PTHREAD_LIBS} -version-info ${MEMCACHED_UTIL_LIBRARY_VERSION} +libmemcached_libmemcachedutil_la_DEPENDENCIES= libmemcached/libmemcached.la + diff --git a/libmemcached/util/version.cc b/libmemcached/util/version.cc index 761cbbf5..a8208298 100644 --- a/libmemcached/util/version.cc +++ b/libmemcached/util/version.cc @@ -1,17 +1,43 @@ -/* LibMemcached - * Copyright (C) 2010 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) 2010 Brian Aker All rights reserved. * - * Summary: connect to all hosts, and make sure they meet a minimum version + * 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. * */ -/* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */ -#include "libmemcached/common.h" -#include "libmemcached/memcached_util.h" + +#include +#include struct local_context { @@ -48,14 +74,12 @@ bool libmemcached_util_version_check(memcached_st *memc, uint8_t minor_version, uint8_t micro_version) { - memcached_server_fn callbacks[1]; - memcached_return_t rc= memcached_version(memc); - - if (rc != MEMCACHED_SUCCESS) + if (memcached_version(memc) != MEMCACHED_SUCCESS) return false; struct local_context check= { major_version, minor_version, micro_version, true }; + memcached_server_fn callbacks[1]; callbacks[0]= check_server_version; memcached_server_cursor(memc, callbacks, (void *)&check, 1); diff --git a/libmemcached/verbosity.c b/libmemcached/verbosity.c deleted file mode 100644 index d71fced7..00000000 --- a/libmemcached/verbosity.c +++ /dev/null @@ -1,60 +0,0 @@ -#include "common.h" - -struct context_st -{ - size_t length; - const char *buffer; -}; - -static memcached_return_t _set_verbosity(const memcached_st *ptr, - const memcached_server_st *server, - void *context) -{ - memcached_return_t rc; - memcached_st local_memc; - memcached_st *memc_ptr; - char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; - - struct context_st *execute= (struct context_st *)context; - (void)ptr; - - memc_ptr= memcached_create(&local_memc); - - rc= memcached_server_add(memc_ptr, memcached_server_name(server), memcached_server_port(server)); - - if (rc == MEMCACHED_SUCCESS) - { - memcached_server_write_instance_st instance= - memcached_server_instance_fetch(memc_ptr, 0); - - rc= memcached_do(instance, execute->buffer, execute->length, true); - - if (rc == MEMCACHED_SUCCESS) - { - rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); - } - } - - memcached_free(memc_ptr); - - return rc; -} - -memcached_return_t memcached_verbosity(memcached_st *ptr, uint32_t verbosity) -{ - int send_length; - memcached_server_fn callbacks[1]; - - char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; - - send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, - "verbosity %u\r\n", verbosity); - if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE || send_length < 0) - return MEMCACHED_WRITE_FAILURE; - - struct context_st context = { .length= (size_t)send_length, .buffer= buffer }; - - callbacks[0]= _set_verbosity; - - return memcached_server_cursor(ptr, callbacks, &context, 1); -} diff --git a/libmemcached/verbosity.cc b/libmemcached/verbosity.cc new file mode 100644 index 00000000..ec00b8de --- /dev/null +++ b/libmemcached/verbosity.cc @@ -0,0 +1,97 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * Copyright (C) 2010 Brian Aker All rights reserved. + * + * 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. + * + */ + +#include + +struct context_st +{ + size_t length; + const char *buffer; +}; + +static memcached_return_t _set_verbosity(const memcached_st *ptr, + const memcached_server_st *server, + void *context) +{ + memcached_return_t rc; + memcached_st local_memc; + memcached_st *memc_ptr; + char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; + + struct context_st *execute= (struct context_st *)context; + (void)ptr; + + memc_ptr= memcached_create(&local_memc); + + rc= memcached_server_add(memc_ptr, memcached_server_name(server), memcached_server_port(server)); + + if (rc == MEMCACHED_SUCCESS) + { + memcached_server_write_instance_st instance= + memcached_server_instance_fetch(memc_ptr, 0); + + rc= memcached_do(instance, execute->buffer, execute->length, true); + + if (rc == MEMCACHED_SUCCESS) + { + rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); + } + } + + memcached_free(memc_ptr); + + return rc; +} + +memcached_return_t memcached_verbosity(memcached_st *ptr, uint32_t verbosity) +{ + int send_length; + memcached_server_fn callbacks[1]; + + char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; + + send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, + "verbosity %u\r\n", verbosity); + if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE || send_length < 0) + return MEMCACHED_WRITE_FAILURE; + + struct context_st context = { (size_t)send_length, buffer }; + + callbacks[0]= _set_verbosity; + + return memcached_server_cursor(ptr, callbacks, &context, 1); +} diff --git a/libmemcached/verbosity.h b/libmemcached/verbosity.h index b28458e4..29946486 100644 --- a/libmemcached/verbosity.h +++ b/libmemcached/verbosity.h @@ -1,16 +1,41 @@ -/* LibMemcached - * Copyright (C) 2010 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) 2010 Brian Aker All rights reserved. * - * Summary: Change the verbository level of the memcached server + * 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_VERBOSITY_H__ -#define __LIBMEMCACHED_VERBOSITY_H__ +#pragma once #ifdef __cplusplus extern "C" { @@ -23,5 +48,3 @@ memcached_return_t memcached_verbosity(memcached_st *ptr, uint32_t verbosity); #ifdef __cplusplus } #endif - -#endif /* __LIBMEMCACHED_VERBOSITY_H__ */ diff --git a/libmemcached/version.c b/libmemcached/version.cc similarity index 73% rename from libmemcached/version.c rename to libmemcached/version.cc index 82de87d3..abb72005 100644 --- a/libmemcached/version.c +++ b/libmemcached/version.cc @@ -1,4 +1,40 @@ -#include "common.h" +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * Copyright (C) 2010 Brian Aker All rights reserved. + * + * 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. + * + */ +#include const char * memcached_lib_version(void) { @@ -100,7 +136,7 @@ static inline memcached_return_t memcached_version_textual(memcached_st *ptr) static inline memcached_return_t memcached_version_binary(memcached_st *ptr) { memcached_return_t rc; - protocol_binary_request_version request= { .bytes= {0}}; + protocol_binary_request_version request= {}; request.message.header.request.magic= PROTOCOL_BINARY_REQ; request.message.header.request.opcode= PROTOCOL_BINARY_CMD_VERSION; request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; diff --git a/libmemcached/version.h b/libmemcached/version.h index 7e6f607a..c443accb 100644 --- a/libmemcached/version.h +++ b/libmemcached/version.h @@ -1,16 +1,41 @@ -/* LibMemcached - * Copyright (C) 2010 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) 2010 Brian Aker All rights reserved. * - * Summary: Find version information + * 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_VERSION_H__ -#define __LIBMEMCACHED_VERSION_H__ +#pragma once #ifdef __cplusplus extern "C" { @@ -25,5 +50,3 @@ const char * memcached_lib_version(void); #ifdef __cplusplus } #endif - -#endif /* __LIBMEMCACHED_VERSION_H__ */ diff --git a/libmemcached/visibility.h b/libmemcached/visibility.h index 7d9af058..646806ac 100644 --- a/libmemcached/visibility.h +++ b/libmemcached/visibility.h @@ -16,8 +16,7 @@ * @brief Visibility control macros */ -#ifndef __LIBMEMCACHED_VISIBILITY_H__ -#define __LIBMEMCACHED_VISIBILITY_H__ +#pragma once /** * @@ -50,5 +49,3 @@ # define LIBMEMCACHED_LOCAL # endif /* defined(_MSC_VER) */ #endif /* defined(BUILDING_LIBMEMCACHED) */ - -#endif /* __LIBMEMCACHED_VISIBILITY_H__ */ diff --git a/libtest/test.c b/libtest/test.c index 9a79e4c5..afb2b965 100644 --- a/libtest/test.c +++ b/libtest/test.c @@ -24,8 +24,6 @@ #include #include -#include - #include #include @@ -370,9 +368,5 @@ cleanup: world_stats_print(&stats); -#ifdef LIBMEMCACHED_WITH_SASL_SUPPORT - sasl_done(); -#endif - return stats.failed == 0 ? 0 : 1; } diff --git a/libtest/test.h b/libtest/test.h index 58d24373..656be169 100644 --- a/libtest/test.h +++ b/libtest/test.h @@ -217,6 +217,17 @@ do \ } \ } while (0) +#define test_compare(A,B) \ +do \ +{ \ + if ((A) != (B)) \ + { \ + fprintf(stderr, "\n%s:%d: Expected %lu == %lu\n", __FILE__, __LINE__, (unsigned long)(A), (unsigned long)(B)); \ + create_core(); \ + return TEST_FAILURE; \ + } \ +} while (0) + #define test_false(A) \ do \ { \ @@ -248,6 +259,16 @@ do \ } \ } while (0) +#define test_memcmp(A,B,C) \ +do \ +{ \ + if (memcmp((A), (B), (C))) \ + { \ + fprintf(stderr, "\n%s:%d: %.*s -> %.*s\n", __FILE__, __LINE__, (int)(C), (char *)(A), (int)(C), (char *)(B)); \ + create_core(); \ + return TEST_FAILURE; \ + } \ +} while (0) #define STRINGIFY(x) #x #define TOSTRING(x) STRINGIFY(x) diff --git a/tests/atomsmasher.c b/tests/atomsmasher.c index afdf0830..8563e4ec 100644 --- a/tests/atomsmasher.c +++ b/tests/atomsmasher.c @@ -26,8 +26,8 @@ #include #include #include -#include "../clients/generator.h" -#include "../clients/execute.h" +#include +#include #include #include diff --git a/tests/hash_plus.cc b/tests/hash_plus.cc index 140d28fc..20cf79db 100644 --- a/tests/hash_plus.cc +++ b/tests/hash_plus.cc @@ -1,13 +1,16 @@ /* C++ to libhashkit */ + +#include + #include #include #include #include -#include +#include #include "hash_results.h" diff --git a/tests/include.am b/tests/include.am index 2a3e5cb8..44954b11 100644 --- a/tests/include.am +++ b/tests/include.am @@ -67,18 +67,23 @@ tests_testapp_SOURCES= \ tests_testapp_DEPENDENCIES= \ $(BUILT_SOURCES) \ + $(TESTS_LDADDS) \ clients/libgenexec.la \ - libmemcached/libmemcachedinternal.la \ - $(TESTS_LDADDS) + libhashkit/libhashkit.la \ + libmemcached/libmemcachedinternal.la -tests_testapp_LDADD= clients/libgenexec.la \ - libmemcached/libmemcachedinternal.la \ - $(TESTS_LDADDS) $(LIBSASL) +tests_testapp_LDADD= \ + $(LIBSASL) \ + $(TESTS_LDADDS) \ + clients/libgenexec.la \ + libhashkit/libhashkit.la \ + libmemcached/libmemcachedinternal.la tests_testplus_SOURCES= tests/plus.cpp tests_testplus_CXXFLAGS = $(AM_CXXFLAGS) $(NO_EFF_CXX) tests_testplus_DEPENDENCIES= $(TESTS_LDADDS) tests_testplus_LDADD= $(tests_testplus_DEPENDENCIES) $(LIBSASL) +check_PROGRAMS+= tests/testplus tests_atomsmasher_SOURCES= tests/atomsmasher.c tests_atomsmasher_DEPENDENCIES= \ @@ -101,12 +106,12 @@ tests_startservers_LDADD= $(tests_startservers_DEPENDENCIES) $(LIBSASL) tests_testhashkit_SOURCES = tests/hashkit_functions.c tests_testhashkit_DEPENDENCIES = libtest/libtest.la libhashkit/libhashkit.la -tests_testhashkit_LDADD = $(tests_testhashkit_DEPENDENCIES) $(LIBSASL) +tests_testhashkit_LDADD = $(tests_testhashkit_DEPENDENCIES) -tests_hash_plus_SOURCES = tests/hash_plus.cc -tests_hash_plus_CXXFLAGS = $(AM_CXXFLAGS) $(NO_EFF_CXX) -tests_hash_plus_DEPENDENCIES = $(tests_testhashkit_DEPENDENCIES) -tests_hash_plus_LDADD = $(tests_testhashkit_DEPENDENCIES) $(LIBSASL) +tests_hash_plus_SOURCES= tests/hash_plus.cc +tests_hash_plus_CXXFLAGS= $(AM_CXXFLAGS) $(NO_EFF_CXX) +tests_hash_plus_DEPENDENCIES= $(tests_testhashkit_DEPENDENCIES) +tests_hash_plus_LDADD= $(tests_testhashkit_DEPENDENCIES) check_PROGRAMS+= tests/hash_plus test: check diff --git a/tests/libmemcached_world.h b/tests/libmemcached_world.h index 5a5e15b5..4793569c 100644 --- a/tests/libmemcached_world.h +++ b/tests/libmemcached_world.h @@ -133,6 +133,10 @@ test_return_t world_destroy(libmemcached_test_container_st *container) server_shutdown(construct); +#ifdef LIBMEMCACHED_WITH_SASL_SUPPORT + sasl_done(); +#endif + return TEST_SUCCESS; } diff --git a/tests/mem_functions.c b/tests/mem_functions.c index 1ab8d6a3..0400ce5a 100644 --- a/tests/mem_functions.c +++ b/tests/mem_functions.c @@ -767,8 +767,10 @@ static test_return_t flush_test(memcached_st *memc) { memcached_return_t rc; + uint64_t query_id= memcached_query_id(memc); rc= memcached_flush(memc, 0); - test_true(rc == MEMCACHED_SUCCESS); + test_compare(rc, MEMCACHED_SUCCESS); + test_compare(query_id +1, memcached_query_id(memc)); return TEST_SUCCESS; } @@ -806,18 +808,23 @@ static test_return_t bad_key_test(memcached_st *memc) size_t max_keylen= 0xffff; // Just skip if we are in binary mode. + uint64_t query_id= memcached_query_id(memc); if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)) return TEST_SKIPPED; + test_compare(query_id, memcached_query_id(memc)); // We should not increase the query_id for memcached_behavior_get() memc_clone= memcached_clone(NULL, memc); test_true(memc_clone); + query_id= memcached_query_id(memc_clone); rc= memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, set); test_true(rc == MEMCACHED_SUCCESS); + test_compare(query_id, memcached_query_id(memc_clone)); // We should not increase the query_id for memcached_behavior_set() /* All keys are valid in the binary protocol (except for length) */ if (memcached_behavior_get(memc_clone, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) == 0) { + query_id= memcached_query_id(memc_clone); string= memcached_get(memc_clone, key, strlen(key), &string_length, &flags, &rc); test_true(rc == MEMCACHED_BAD_KEY_PROVIDED); @@ -825,7 +832,9 @@ static test_return_t bad_key_test(memcached_st *memc) test_true(!string); set= 0; + query_id= memcached_query_id(memc_clone); rc= memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, set); + test_compare(query_id, memcached_query_id(memc_clone)); // We should not increase the query_id for memcached_behavior_set() test_true(rc == MEMCACHED_SUCCESS); string= memcached_get(memc_clone, key, strlen(key), &string_length, &flags, &rc); @@ -837,14 +846,20 @@ static test_return_t bad_key_test(memcached_st *memc) const char *keys[] = { "GoodKey", "Bad Key", "NotMine" }; size_t key_lengths[] = { 7, 7, 7 }; set= 1; + query_id= memcached_query_id(memc_clone); rc= memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, set); test_true(rc == MEMCACHED_SUCCESS); + test_compare(query_id, memcached_query_id(memc_clone)); + query_id= memcached_query_id(memc_clone); rc= memcached_mget(memc_clone, keys, key_lengths, 3); test_true(rc == MEMCACHED_BAD_KEY_PROVIDED); + test_compare(query_id +1, memcached_query_id(memc_clone)); + query_id= memcached_query_id(memc_clone); rc= memcached_mget_by_key(memc_clone, "foo daddy", 9, keys, key_lengths, 1); test_true(rc == MEMCACHED_BAD_KEY_PROVIDED); + test_compare(query_id +1, memcached_query_id(memc_clone)); max_keylen= 250; @@ -970,8 +985,10 @@ static test_return_t get_test(memcached_st *memc) size_t string_length; uint32_t flags; + uint64_t query_id= memcached_query_id(memc); rc= memcached_delete(memc, key, strlen(key), (time_t)0); test_true(rc == MEMCACHED_BUFFERED || rc == MEMCACHED_NOTFOUND); + test_compare(query_id +1, memcached_query_id(memc)); string= memcached_get(memc, key, strlen(key), &string_length, &flags, &rc); @@ -992,18 +1009,22 @@ static test_return_t get_test2(memcached_st *memc) size_t string_length; uint32_t flags; + uint64_t query_id= memcached_query_id(memc); rc= memcached_set(memc, key, strlen(key), value, strlen(value), (time_t)0, (uint32_t)0); test_true(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); + test_compare(query_id +1, memcached_query_id(memc)); + query_id= memcached_query_id(memc); string= memcached_get(memc, key, strlen(key), &string_length, &flags, &rc); + test_compare(query_id +1, memcached_query_id(memc)); test_true(string); test_true(rc == MEMCACHED_SUCCESS); test_true(string_length == strlen(value)); - test_true(!memcmp(string, value, string_length)); + test_memcmp(string, value, string_length); free(string); @@ -1034,25 +1055,26 @@ static test_return_t set_test3(memcached_st *memc) memcached_return_t rc; char *value; size_t value_length= 8191; - unsigned int x; value = (char*)malloc(value_length); test_true(value); - for (x= 0; x < value_length; x++) + for (uint32_t x= 0; x < value_length; x++) value[x] = (char) (x % 127); /* The dump test relies on there being at least 32 items in memcached */ - for (x= 0; x < 32; x++) + for (uint32_t x= 0; x < 32; x++) { char key[16]; snprintf(key, sizeof(key), "foo%u", x); + uint64_t query_id= memcached_query_id(memc); rc= memcached_set(memc, key, strlen(key), value, value_length, (time_t)0, (uint32_t)0); test_true(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); + test_compare(query_id +1, memcached_query_id(memc)); } free(value); @@ -1720,8 +1742,10 @@ static test_return_t mget_execute(memcached_st *memc) key_length[x]= (size_t)snprintf(k, sizeof(k), "0200%lu", (unsigned long)x); keys[x]= strdup(k); test_true(keys[x] != NULL); + uint64_t query_id= memcached_query_id(memc); rc= memcached_add(memc, keys[x], key_length[x], blob, sizeof(blob), 0, 0); test_true(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); + test_compare(query_id +1, memcached_query_id(memc)); } /* Try to get all of them with a large multiget */ @@ -1733,8 +1757,10 @@ static test_return_t mget_execute(memcached_st *memc) if (rc == MEMCACHED_SUCCESS) { test_true(binary); + uint64_t query_id= memcached_query_id(memc); rc= memcached_fetch_execute(memc, callbacks, (void *)&counter, 1); test_true(rc == MEMCACHED_END); + test_compare(query_id, memcached_query_id(memc)); /* Verify that we got all of the items */ test_true(counter == max_keys); @@ -2257,7 +2283,7 @@ static test_return_t user_supplied_bug4(memcached_st *memc) /* We need to empty the server before continueing test */ rc= memcached_flush(memc, 0); - test_true(rc == MEMCACHED_NO_SERVERS); + test_compare(rc, MEMCACHED_NO_SERVERS); rc= memcached_mget(memc, keys, key_length, 3); test_true(rc == MEMCACHED_NO_SERVERS); @@ -2267,7 +2293,7 @@ static test_return_t user_supplied_bug4(memcached_st *memc) { test_true(return_value); } - test_true(!return_value); + test_false(return_value); test_true(return_value_length == 0); test_true(rc == MEMCACHED_NO_SERVERS); @@ -2289,7 +2315,7 @@ static test_return_t user_supplied_bug4(memcached_st *memc) test_true(return_value); test_true(rc == MEMCACHED_SUCCESS); test_true(return_key_length == return_value_length); - test_true(!memcmp(return_value, return_key, return_value_length)); + test_memcmp(return_value, return_key, return_value_length); free(return_value); x++; } @@ -6295,7 +6321,7 @@ collection_st collection[] ={ {0, 0, 0, 0} }; -#include "libmemcached_world.h" +#include "tests/libmemcached_world.h" void get_world(world_st *world) { diff --git a/tests/plus.cpp b/tests/plus.cpp index c0c6bb95..c4b67115 100644 --- a/tests/plus.cpp +++ b/tests/plus.cpp @@ -1,17 +1,16 @@ /* C++ interface test */ -#include "libmemcached/memcached.hpp" +#include -#include -#include -#include -#include +#include +#include +#include #include #include #include #include -#include +#include #include @@ -44,7 +43,7 @@ static void populate_vector(vector &vec, const string &str) static void copy_vec_to_string(vector &vec, string &str) { str.clear(); - if (! vec.empty()) + if (not vec.empty()) { str.assign(vec.begin(), vec.end()); } @@ -59,31 +58,18 @@ test_return_t basic_test(memcached_st *memc) populate_vector(value, value_set); - foo.set("mine", value, 0, 0); - foo.get("mine", test_value); + test_true(foo.set("mine", value, 0, 0)); + test_true(foo.get("mine", test_value)); - assert((memcmp(&test_value[0], &value[0], test_value.size()) == 0)); + test_memcmp(&test_value[0], &value[0], test_value.size()); + test_false(foo.set("", value, 0, 0)); - /* - * Simple test of the exceptions here...this should throw an exception - * saying that the key is empty. - */ - try - { - foo.set("", value, 0, 0); - } - catch (Error &err) - { - return TEST_SUCCESS; - } - - return TEST_FAILURE; + return TEST_SUCCESS; } -test_return_t increment_test(memcached_st *memc) +test_return_t increment_test(memcached_st *original) { - Memcache mcach(memc); - bool rc; + Memcache mcach(original); const string key("blah"); const string inc_value("1"); std::vector inc_val; @@ -94,40 +80,31 @@ test_return_t increment_test(memcached_st *memc) populate_vector(inc_val, inc_value); - rc= mcach.set(key, inc_val, 0, 0); - if (rc == false) - { - return TEST_FAILURE; - } - mcach.get(key, ret_value); - if (ret_value.empty()) - { - return TEST_FAILURE; - } + test_true(mcach.set(key, inc_val, 0, 0)); + + test_true(mcach.get(key, ret_value)); + test_false(ret_value.empty()); copy_vec_to_string(ret_value, ret_string); int_inc_value= uint64_t(atol(inc_value.c_str())); int_ret_value= uint64_t(atol(ret_string.c_str())); - assert(int_ret_value == int_inc_value); + test_compare(int_inc_value, int_ret_value); - rc= mcach.increment(key, 1, &int_ret_value); - assert(rc == true); - assert(int_ret_value == 2); + test_true(mcach.increment(key, 1, &int_ret_value)); + test_compare(2, int_ret_value); - rc= mcach.increment(key, 1, &int_ret_value); - assert(rc == true); - assert(int_ret_value == 3); + test_true(mcach.increment(key, 1, &int_ret_value)); + test_compare(3, int_ret_value); - rc= mcach.increment(key, 5, &int_ret_value); - assert(rc == true); - assert(int_ret_value == 8); + test_true(mcach.increment(key, 5, &int_ret_value)); + test_compare(8, int_ret_value); return TEST_SUCCESS; } -test_return_t basic_master_key_test(memcached_st *memc) +test_return_t basic_master_key_test(memcached_st *original) { - Memcache foo(memc); + Memcache foo(original); const string value_set("Data for server A"); vector value; vector test_value; @@ -140,12 +117,12 @@ test_return_t basic_master_key_test(memcached_st *memc) foo.setByKey(master_key_a, key, value, 0, 0); foo.getByKey(master_key_a, key, test_value); - assert((memcmp(&value[0], &test_value[0], value.size()) == 0)); + test_true((memcmp(&value[0], &test_value[0], value.size()) == 0)); test_value.clear(); foo.getByKey(master_key_b, key, test_value); - assert((memcmp(&value[0], &test_value[0], value.size()) == 0)); + test_true((memcmp(&value[0], &test_value[0], value.size()) == 0)); return TEST_SUCCESS; } @@ -162,53 +139,9 @@ memcached_return_t callback_counter(const memcached_st *, return MEMCACHED_SUCCESS; } -test_return_t mget_result_function(memcached_st *memc) -{ - Memcache mc(memc); - bool rc; - string key1("fudge"); - string key2("son"); - string key3("food"); - vector keys; - vector< vector *> values; - vector val1; - vector val2; - vector val3; - populate_vector(val1, key1); - populate_vector(val2, key2); - populate_vector(val3, key3); - keys.reserve(3); - keys.push_back(key1); - keys.push_back(key2); - keys.push_back(key3); - values.reserve(3); - values.push_back(&val1); - values.push_back(&val2); - values.push_back(&val3); - unsigned int counter; - memcached_execute_fn callbacks[1]; - - /* We need to empty the server before we continue the test */ - rc= mc.flush(0); - rc= mc.setAll(keys, values, 50, 9); - assert(rc == true); - - rc= mc.mget(keys); - assert(rc == true); - - callbacks[0]= &callback_counter; - counter= 0; - rc= mc.fetchExecute(callbacks, static_cast(&counter), 1); - - assert(counter == 3); - - return TEST_SUCCESS; -} - -test_return_t mget_test(memcached_st *memc) +test_return_t mget_test(memcached_st *original) { - Memcache mc(memc); - bool rc; + Memcache memc(original); memcached_return_t mc_rc; vector keys; vector< vector *> values; @@ -231,43 +164,37 @@ test_return_t mget_test(memcached_st *memc) vector return_value; /* We need to empty the server before we continue the test */ - rc= mc.flush(0); - assert(rc == true); + test_true(memc.flush(0)); - rc= mc.mget(keys); - assert(rc == true); + test_true(memc.mget(keys)); - while ((mc_rc= mc.fetch(return_key, return_value)) != MEMCACHED_END) + while ((mc_rc= memc.fetch(return_key, return_value)) != MEMCACHED_END) { - assert(return_value.size() != 0); + test_true(return_value.size()); return_value.clear(); } - assert(mc_rc == MEMCACHED_END); + test_compare(mc_rc, MEMCACHED_END); - rc= mc.setAll(keys, values, 50, 9); - assert(rc == true); + test_true(memc.setAll(keys, values, 50, 9)); - rc= mc.mget(keys); - assert(rc == true); + test_true(memc.mget(keys)); - while ((mc_rc= mc.fetch(return_key, return_value)) != MEMCACHED_END) + while ((mc_rc= memc.fetch(return_key, return_value)) != MEMCACHED_END) { - assert(return_key.length() == return_value.size()); - assert(!memcmp(&return_value[0], return_key.c_str(), return_value.size())); + test_compare(return_key.length(), return_value.size()); + test_memcmp(&return_value[0], return_key.c_str(), return_value.size()); } return TEST_SUCCESS; } -test_return_t basic_behavior(memcached_st *memc) +test_return_t basic_behavior(memcached_st *original) { - Memcache mc(memc); - bool rc; - uint64_t value = 1; - rc = mc.setBehavior(MEMCACHED_BEHAVIOR_VERIFY_KEY, value); - assert(rc); - uint64_t behavior = mc.getBehavior(MEMCACHED_BEHAVIOR_VERIFY_KEY); - assert(behavior == value); + Memcache memc(original); + uint64_t value= 1; + test_true(memc.setBehavior(MEMCACHED_BEHAVIOR_VERIFY_KEY, value)); + uint64_t behavior= memc.getBehavior(MEMCACHED_BEHAVIOR_VERIFY_KEY); + test_compare(behavior, value); return TEST_SUCCESS; } @@ -281,8 +208,6 @@ test_st tests[] ={ reinterpret_cast(increment_test) }, { "mget", 1, reinterpret_cast(mget_test) }, - { "mget_result_function", 1, - reinterpret_cast(mget_result_function) }, { "basic_behavior", 0, reinterpret_cast(basic_behavior) }, {0, 0, 0} diff --git a/tests/string.cc b/tests/string.cc index 35d6eb41..aa8a7d6f 100644 --- a/tests/string.cc +++ b/tests/string.cc @@ -35,9 +35,11 @@ * */ -#include "libmemcached/common.h" -#include "libmemcached/error.h" -#include "tests/string.h" +#define BUILDING_LIBMEMCACHED + +#include +#include +#include test_return_t string_static_null(memcached_st *memc) { -- 2.30.2