From: Brian Aker Date: Mon, 30 Jan 2012 09:47:54 +0000 (-0800) Subject: Merge build trunk. X-Git-Tag: 1.0.7~18^2 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=dd3626ef6e3fd2a4f7d88a23cd9a91fc2ab5e32d;hp=f19d17ca4cd851c81c005b68c82b17c3c21b6846;p=awesomized%2Flibmemcached Merge build trunk. --- diff --git a/ChangeLog b/ChangeLog index f3ab6d6c..7a60fb07 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +1.0.5 + +* Version is now parsed directly in the parser, which makes buffered +operations now work with it.. + +* memstat has been extended so that it can be used to find the version of the +server. + + 1.0.4 Thu Jan 26 22:33:54 PST 2012 * Fix for memcached_dump(). * Additional testing for memcached_stat_execute(). diff --git a/Makefile.am b/Makefile.am index b9e758b0..f033421a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,3 +1,5 @@ +# vim:ft=automake + ACLOCAL_AMFLAGS = -I m4 # includes append to these: diff --git a/clients/client_options.h b/clients/client_options.h index c3420b49..16ce4bed 100644 --- a/clients/client_options.h +++ b/clients/client_options.h @@ -39,6 +39,7 @@ enum memcached_options { OPT_USERNAME, OPT_PASSWD, OPT_STAT_ARGS, + OPT_SERVER_VERSION, OPT_QUIET, OPT_FILE= 'f' }; diff --git a/clients/memstat.cc b/clients/memstat.cc index 8036ea18..88221cf3 100644 --- a/clients/memstat.cc +++ b/clients/memstat.cc @@ -39,9 +39,10 @@ static void run_analyzer(memcached_st *memc, memcached_stat_st *memc_stat); static void print_analysis_report(memcached_st *memc, memcached_analysis_st *report); -static int opt_verbose= 0; -static int opt_displayflag= 0; -static int opt_analyze= 0; +static bool opt_binary= false; +static bool opt_verbose= false; +static bool opt_server_version= false; +static bool opt_analyze= false; static char *opt_servers= NULL; static char *stat_args= NULL; static char *analyze_mode= NULL; @@ -52,10 +53,11 @@ static struct option long_options[]= {(OPTIONSTRING)"version", no_argument, NULL, OPT_VERSION}, {(OPTIONSTRING)"help", no_argument, NULL, OPT_HELP}, {(OPTIONSTRING)"quiet", no_argument, NULL, OPT_QUIET}, - {(OPTIONSTRING)"verbose", no_argument, &opt_verbose, OPT_VERBOSE}, - {(OPTIONSTRING)"debug", no_argument, &opt_verbose, OPT_DEBUG}, + {(OPTIONSTRING)"verbose", no_argument, NULL, OPT_VERBOSE}, + {(OPTIONSTRING)"binary", no_argument, NULL, OPT_BINARY}, + {(OPTIONSTRING)"debug", no_argument, NULL, OPT_DEBUG}, + {(OPTIONSTRING)"server-version", no_argument, NULL, OPT_SERVER_VERSION}, {(OPTIONSTRING)"servers", required_argument, NULL, OPT_SERVERS}, - {(OPTIONSTRING)"flag", no_argument, &opt_displayflag, OPT_FLAG}, {(OPTIONSTRING)"analyze", optional_argument, NULL, OPT_ANALYZE}, {0, 0, 0, 0}, }; @@ -81,6 +83,18 @@ static memcached_return_t stat_printer(memcached_server_instance_st instance, return MEMCACHED_SUCCESS; } +static memcached_return_t server_print_callback(const memcached_st *, + const memcached_server_st *instance, + void *) +{ + std::cerr << memcached_server_name(instance) << ":" << memcached_server_port(instance) << + " " << int(instance->major_version) << + "." << int(instance->minor_version) << + "." << int(instance->micro_version) << std::endl; + + return MEMCACHED_SUCCESS; +} + int main(int argc, char *argv[]) { options_parse(argc, argv); @@ -101,6 +115,7 @@ int main(int argc, char *argv[]) } memcached_st *memc= memcached_create(NULL); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, opt_binary); memcached_server_st *servers= memcached_servers_parse(opt_servers); free(opt_servers); @@ -108,21 +123,33 @@ int main(int argc, char *argv[]) memcached_return_t rc= memcached_server_push(memc, servers); memcached_server_list_free(servers); - if (rc != MEMCACHED_SUCCESS && rc != MEMCACHED_SOME_ERRORS) + if (rc != MEMCACHED_SUCCESS and rc != MEMCACHED_SOME_ERRORS) { printf("Failure to communicate with servers (%s)\n", memcached_strerror(memc, rc)); - exit(1); + exit(EXIT_FAILURE); } - if (opt_analyze) + if (opt_server_version) { - memcached_stat_st *memc_stat; + if (memcached_failed(memcached_version(memc))) + { + std::cerr << "Unable to obtain server version"; + exit(EXIT_FAILURE); + } - memc_stat= memcached_stat(memc, NULL, &rc); + memcached_server_fn callbacks[1]; + callbacks[0]= server_print_callback; + memcached_server_cursor(memc, callbacks, NULL, 1); + } + else if (opt_analyze) + { + memcached_stat_st *memc_stat= memcached_stat(memc, NULL, &rc); - if (! memc_stat) - exit(-1); + if (memc_stat == NULL) + { + exit(EXIT_FAILURE); + } run_analyzer(memc, memc_stat); @@ -326,11 +353,19 @@ static void options_parse(int argc, char *argv[]) break; case OPT_VERBOSE: /* --verbose or -v */ - opt_verbose = OPT_VERBOSE; + opt_verbose= true; break; case OPT_DEBUG: /* --debug or -d */ - opt_verbose = OPT_DEBUG; + opt_verbose= true; + break; + + case OPT_BINARY: + opt_binary= true; + break; + + case OPT_SERVER_VERSION: + opt_server_version= true; break; case OPT_VERSION: /* --version or -V */ diff --git a/clients/utilities.cc b/clients/utilities.cc index d0b3dba8..bae94076 100644 --- a/clients/utilities.cc +++ b/clients/utilities.cc @@ -103,6 +103,7 @@ static const char *lookup_help(memcached_options option) case OPT_PASSWD: return "Password to use for SASL authentication"; case OPT_FILE: return "Path to file in which to save result"; case OPT_STAT_ARGS: return "Argument for statistics"; + case OPT_SERVER_VERSION: return "Memcached daemon software version"; default: break; }; diff --git a/configure.ac b/configure.ac index a7f4a306..c13d23cb 100644 --- a/configure.ac +++ b/configure.ac @@ -58,6 +58,11 @@ LT_LANG([C++]) LT_LANG([C]) gl_VISIBILITY +AX_CXX_HEADER_STDCXX_98 + if test "$ax_cv_cxx_stdcxx_98" = no; then + AC_MSG_ERROR([Your system lacks a new enough C++ compiler]) + fi + m4_include([m4/memcached.m4]) m4_include([m4/memcached_sasl.m4]) m4_include([m4/gearmand.m4]) @@ -72,8 +77,6 @@ AM_CONDITIONAL(BUILDING_GEARMAN, false) AC_SEARCH_LIBS(getopt_long, gnugetopt) AC_SEARCH_LIBS(gethostbyname, nsl) -PANDORA_HAVE_LIBEVENT - case "$target_os" in *linux*) AS_IF([test "x$GCC" = "xyes"], @@ -85,7 +88,7 @@ case "$target_os" in dnl Specialty checks AX_PTHREAD -AX_CXX_CSTDINT +AX_CXX_CINTTYPES CONFIG_EXTRA DETECT_BYTEORDER ENABLE_UTILLIB @@ -205,6 +208,15 @@ AS_IF(test "x$ac_cv_header_winsock2_h" = "xyes", ]) SOCKET_SEND_FLAGS +AX_CHECK_LIBRARY([LIBEVENT], [event.h], [event], + [ + LIBEVENT_LDFLAGS="-levent" + ], + [ + AC_MSG_WARN([Unable to find libevent]) + ]) +AM_CONDITIONAL(HAVE_LIBEVENT, test "x${ax_cv_have_LIBEVENT}" = "xyes") + AC_CONFIG_FILES([ Makefile docs/conf.py diff --git a/example/include.am b/example/include.am index 9a1c11b0..625c4680 100644 --- a/example/include.am +++ b/example/include.am @@ -18,10 +18,6 @@ example_memcached_light_SOURCES= \ example/memcached_light.c example_memcached_light_LDADD= libmemcached/libmemcachedprotocol.la \ - $(LIBINNODB) $(LTLIBEVENT) + $(LIBEVENT_LDFLAGS) -if HAVE_LIBINNODB -example_memcached_light_SOURCES+= example/storage_innodb.c -else example_memcached_light_SOURCES+= example/storage.c -endif diff --git a/example/storage_innodb.c b/example/storage_innodb.c deleted file mode 100644 index e3113f17..00000000 --- a/example/storage_innodb.c +++ /dev/null @@ -1,535 +0,0 @@ -/* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */ -#include -#include -#include -#include -#include -#include -#include -#include - -#include "storage.h" - -const char *tablename= "memcached/items"; - -#define key_col_idx 0 -#define data_col_idx 1 -#define flags_col_idx 2 -#define cas_col_idx 3 -#define exp_col_idx 4 - -static uint64_t cas; - -/** - * To avoid cluttering down all the code with error checking I use the - * following macro. It will execute the statement and verify that the - * result of the operation is DB_SUCCESS. If any other error code is - * returned it will print an "assert-like" output and jump to the - * label error_exit. There I release resources before returning out of - * the function. - * - * @param a the expression to execute - * - */ -#define checked(expression) \ -do { \ - ib_err_t checked_err= expression; \ - if (checked_err != DB_SUCCESS) \ - { \ - fprintf(stderr, "ERROR: %s at %u: Failed: <%s>\n\t%s\n", \ - __FILE__, __LINE__, #expression, \ - ib_strerror(checked_err)); \ - goto error_exit; \ - } \ -} while (0); - -/** - * Create the database schema. - * @return true if the database schema was created without any problems - * false otherwise. - */ -static bool create_schema(void) -{ - ib_tbl_sch_t schema= NULL; - ib_idx_sch_t dbindex= NULL; - - if (ib_database_create("memcached") != IB_TRUE) - { - fprintf(stderr, "Failed to create database\n"); - return false; - } - - ib_trx_t transaction= ib_trx_begin(IB_TRX_SERIALIZABLE); - ib_id_t table_id; - - checked(ib_table_schema_create(tablename, &schema, IB_TBL_COMPACT, 0)); - checked(ib_table_schema_add_col(schema, "key", IB_BLOB, - IB_COL_NOT_NULL, 0, 32767)); - checked(ib_table_schema_add_col(schema, "data", IB_BLOB, - IB_COL_NONE, 0, 1024*1024)); - checked(ib_table_schema_add_col(schema, "flags", IB_INT, - IB_COL_UNSIGNED, 0, 4)); - checked(ib_table_schema_add_col(schema, "cas", IB_INT, - IB_COL_UNSIGNED, 0, 8)); - checked(ib_table_schema_add_col(schema, "exp", IB_INT, - IB_COL_UNSIGNED, 0, 4)); - checked(ib_table_schema_add_index(schema, "PRIMARY_KEY", &dbindex)); - checked(ib_index_schema_add_col(dbindex, "key", 0)); - checked(ib_index_schema_set_clustered(dbindex)); - checked(ib_schema_lock_exclusive(transaction)); - checked(ib_table_create(transaction, schema, &table_id)); - checked(ib_trx_commit(transaction)); - ib_table_schema_delete(schema); - - return true; - - error_exit: - /* @todo release resources! */ - { - ib_err_t error= ib_trx_rollback(transaction); - if (error != DB_SUCCESS) - fprintf(stderr, "Failed to roll back the transaction:\n\t%s\n", - ib_strerror(error)); - } - return false; -} - -/** - * Store an item into the database. Update the CAS id on the item before - * storing it in the database. - * - * @param trx the transaction to use - * @param item the item to store - * @return true if we can go ahead and commit the transaction, false otherwise - */ -static bool do_put_item(ib_trx_t trx, struct item* item) -{ - update_cas(item); - - ib_crsr_t cursor= NULL; - ib_tpl_t tuple= NULL; - bool retval= false; - - checked(ib_cursor_open_table(tablename, trx, &cursor)); - checked(ib_cursor_lock(cursor, IB_LOCK_X)); - tuple= ib_clust_read_tuple_create(cursor); - - checked(ib_col_set_value(tuple, key_col_idx, item->key, item->nkey)); - checked(ib_col_set_value(tuple, data_col_idx, item->data, item->size)); - checked(ib_tuple_write_u32(tuple, flags_col_idx, item->flags)); - checked(ib_tuple_write_u64(tuple, cas_col_idx, item->cas)); - checked(ib_tuple_write_u32(tuple, exp_col_idx, (ib_u32_t)item->exp)); - checked(ib_cursor_insert_row(cursor, tuple)); - - retval= true; - /* Release resources: */ - /* FALLTHROUGH */ - - error_exit: - if (tuple != NULL) - ib_tuple_delete(tuple); - - ib_err_t currsor_error; - if (cursor != NULL) - currsor_error= ib_cursor_close(cursor); - - return retval; -} - -/** - * Try to locate an item in the database. Return a cursor and the tuple to - * the item if I found it in the database. - * - * @param trx the transaction to use - * @param key the key of the item to look up - * @param nkey the size of the key - * @param cursor where to store the cursor (OUT) - * @param tuple where to store the tuple (OUT) - * @return true if I found the object, false otherwise - */ -static bool do_locate_item(ib_trx_t trx, - const void* key, - size_t nkey, - ib_crsr_t *cursor) -{ - int res; - ib_tpl_t tuple= NULL; - - *cursor= NULL; - - checked(ib_cursor_open_table(tablename, trx, cursor)); - tuple= ib_clust_search_tuple_create(*cursor); - if (tuple == NULL) - { - fprintf(stderr, "Failed to allocate tuple object\n"); - goto error_exit; - } - - checked(ib_col_set_value(tuple, key_col_idx, key, nkey)); - ib_err_t err= ib_cursor_moveto(*cursor, tuple, IB_CUR_GE, &res); - - if (err == DB_SUCCESS && res == 0) - { - ib_tuple_delete(tuple); - return true; - } - else if (err != DB_SUCCESS && - err != DB_RECORD_NOT_FOUND && - err != DB_END_OF_INDEX) - { - fprintf(stderr, "ERROR: ib_cursor_moveto(): %s\n", ib_strerror(err)); - } - /* FALLTHROUGH */ - error_exit: - if (tuple != NULL) - ib_tuple_delete(tuple); - - ib_err_t cursor_error; - if (*cursor != NULL) - cursor_error= ib_cursor_close(*cursor); - - *cursor= NULL; - - return false; -} - -/** - * Try to get an item from the database - * - * @param trx the transaction to use - * @param key the key to get - * @param nkey the lenght of the key - * @return a pointer to the item if I found it in the database - */ -static struct item* do_get_item(ib_trx_t trx, const void* key, size_t nkey) -{ - ib_crsr_t cursor= NULL; - ib_tpl_t tuple= NULL; - struct item* retval= NULL; - - if (do_locate_item(trx, key, nkey, &cursor)) - { - tuple= ib_clust_read_tuple_create(cursor); - if (tuple == NULL) - { - fprintf(stderr, "Failed to create read tuple\n"); - goto error_exit; - } - checked(ib_cursor_read_row(cursor, tuple)); - ib_col_meta_t meta; - ib_ulint_t datalen= ib_col_get_meta(tuple, data_col_idx, &meta); - ib_ulint_t flaglen= ib_col_get_meta(tuple, flags_col_idx, &meta); - ib_ulint_t caslen= ib_col_get_meta(tuple, cas_col_idx, &meta); - ib_ulint_t explen= ib_col_get_meta(tuple, exp_col_idx, &meta); - const void *dataptr= ib_col_get_value(tuple, data_col_idx); - - retval= create_item(key, nkey, dataptr, datalen, 0, 0); - if (retval == NULL) - { - fprintf(stderr, "Failed to allocate memory\n"); - goto error_exit; - } - - if (flaglen != 0) - { - ib_u32_t val; - checked(ib_tuple_read_u32(tuple, flags_col_idx, &val)); - retval->flags= (uint32_t)val; - } - if (caslen != 0) - { - ib_u64_t val; - checked(ib_tuple_read_u64(tuple, cas_col_idx, &val)); - retval->cas= (uint64_t)val; - } - if (explen != 0) - { - ib_u32_t val; - checked(ib_tuple_read_u32(tuple, exp_col_idx, &val)); - retval->exp= (time_t)val; - } - } - - /* Release resources */ - /* FALLTHROUGH */ - - error_exit: - if (tuple != NULL) - ib_tuple_delete(tuple); - - ib_err_t cursor_error; - if (cursor != NULL) - cursor_error= ib_cursor_close(cursor); - - return retval; -} - -/** - * Delete an item from the cache - * @param trx the transaction to use - * @param key the key of the item to delete - * @param nkey the length of the key - * @return true if we should go ahead and commit the transaction - * or false if we should roll back (if the key didn't exists) - */ -static bool do_delete_item(ib_trx_t trx, const void* key, size_t nkey) { - ib_crsr_t cursor= NULL; - bool retval= false; - - if (do_locate_item(trx, key, nkey, &cursor)) - { - checked(ib_cursor_lock(cursor, IB_LOCK_X)); - checked(ib_cursor_delete_row(cursor)); - retval= true; - } - /* Release resources */ - /* FALLTHROUGH */ - - error_exit: - if (cursor != NULL) - { - ib_err_t cursor_error; - cursor_error= ib_cursor_close(cursor); - } - - return retval; -} - - -/**************************************************************************** - * External interface - ***************************************************************************/ - -/** - * Initialize the database storage - * @return true if the database was initialized successfully, false otherwise - */ -bool initialize_storage(void) -{ - ib_err_t error; - ib_id_t tid; - - checked(ib_init()); - checked(ib_cfg_set_text("data_home_dir", "/tmp/memcached_light")); - checked(ib_cfg_set_text("log_group_home_dir", "/tmp/memcached_light")); - checked(ib_cfg_set_bool_on("file_per_table")); - checked(ib_startup("barracuda")); - - /* check to see if the table exists or if we should create the schema */ - error= ib_table_get_id(tablename, &tid); - if (error == DB_TABLE_NOT_FOUND) - { - if (!create_schema()) - { - return false; - } - } - else if (error != DB_SUCCESS) - { - fprintf(stderr, "Failed to get table id: %s\n", ib_strerror(error)); - return false; - } - - return true; - - error_exit: - - return false; -} - -/** - * Shut down this storage engine - */ -void shutdown_storage(void) -{ - checked(ib_shutdown(IB_SHUTDOWN_NORMAL)); - error_exit: - ; -} - -/** - * Store an item in the databse - * - * @param item the item to store - */ -void put_item(struct item* item) -{ - ib_trx_t transaction= ib_trx_begin(IB_TRX_SERIALIZABLE); - if (do_put_item(transaction, item)) - { - ib_err_t error= ib_trx_commit(transaction); - if (error != DB_SUCCESS) - { - fprintf(stderr, "Failed to store key:\n\t%s\n", - ib_strerror(error)); - } - } - else - { - ib_err_t error= ib_trx_rollback(transaction); - if (error != DB_SUCCESS) - fprintf(stderr, "Failed to roll back the transaction:\n\t%s\n", - ib_strerror(error)); - } -} - -/** - * Get an item from the engine - * @param key the key to grab - * @param nkey number of bytes in the key - * @return pointer to the item if found - */ -struct item* get_item(const void* key, size_t nkey) -{ - ib_trx_t transaction= ib_trx_begin(IB_TRX_SERIALIZABLE); - struct item* ret= do_get_item(transaction, key, nkey); - ib_err_t error= ib_trx_rollback(transaction); - - if (error != DB_SUCCESS) - fprintf(stderr, "Failed to roll back the transaction:\n\t%s\n", - ib_strerror(error)); - - return ret; -} - -/** - * Create an item structure and initialize it with the content - * - * @param key the key for the item - * @param nkey the number of bytes in the key - * @param data pointer to the value for the item (may be NULL) - * @param size the size of the data - * @param flags the flags to store with the data - * @param exp the expiry time for the item - * @return pointer to an initialized item object or NULL if allocation failed - */ -struct item* create_item(const void* key, size_t nkey, const void* data, - size_t size, uint32_t flags, time_t exp) -{ - struct item* ret= calloc(1, sizeof(*ret)); - if (ret != NULL) - { - ret->key= malloc(nkey); - if (size > 0) - { - ret->data= malloc(size); - } - - if (ret->key == NULL || (size > 0 && ret->data == NULL)) - { - free(ret->key); - free(ret->data); - free(ret); - return NULL; - } - - memcpy(ret->key, key, nkey); - if (data != NULL) - { - memcpy(ret->data, data, size); - } - - ret->nkey= nkey; - ret->size= size; - ret->flags= flags; - ret->exp= exp; - } - - return ret; -} - -/** - * Delete an item from the cache - * @param key the key of the item to delete - * @param nkey the length of the key - * @return true if the item was deleted from the cache - */ -bool delete_item(const void* key, size_t nkey) { - ib_trx_t transaction= ib_trx_begin(IB_TRX_REPEATABLE_READ); - - bool ret= do_delete_item(transaction, key, nkey); - - if (ret) - { - /* object found. commit transaction */ - ib_err_t error= ib_trx_commit(transaction); - if (error != DB_SUCCESS) - { - fprintf(stderr, "Failed to delete key:\n\t%s\n", - ib_strerror(error)); - ret= false; - } - } - else - { - ib_err_t error= ib_trx_rollback(transaction); - if (error != DB_SUCCESS) - fprintf(stderr, "Failed to roll back the transaction:\n\t%s\n", - ib_strerror(error)); - } - - return ret; -} - -/** - * Flush the entire cache - * @param when when the cache should be flushed (0 == immediately) - */ -void flush(uint32_t when __attribute__((unused))) -{ - /* @TODO implement support for when != 0 */ - ib_trx_t transaction= ib_trx_begin(IB_TRX_REPEATABLE_READ); - ib_crsr_t cursor= NULL; - ib_err_t err= DB_SUCCESS; - - checked(ib_cursor_open_table(tablename, transaction, &cursor)); - checked(ib_cursor_first(cursor)); - checked(ib_cursor_lock(cursor, IB_LOCK_X)); - - do - { - checked(ib_cursor_delete_row(cursor)); - } while ((err= ib_cursor_next(cursor)) == DB_SUCCESS); - - if (err != DB_END_OF_INDEX) - { - fprintf(stderr, "Failed to flush the cache: %s\n", ib_strerror(err)); - goto error_exit; - } - ib_err_t cursor_error; - cursor_error= ib_cursor_close(cursor); - cursor= NULL; - checked(ib_trx_commit(transaction)); - return; - - error_exit: - if (cursor != NULL) - { - cursor_error= ib_cursor_close(cursor); - } - - ib_err_t error= ib_trx_rollback(transaction); - if (error != DB_SUCCESS) - fprintf(stderr, "Failed to roll back the transaction:\n\t%s\n", - ib_strerror(error)); -} - -/** - * Update the cas ID in the item structure - * @param item the item to update - */ -void update_cas(struct item* item) -{ - item->cas= ++cas; -} - -/** - * Release all the resources allocated by the item - * @param item the item to release - */ -void release_item(struct item* item) -{ - free(item->key); - free(item->data); - free(item); -} diff --git a/libmemcached/io.cc b/libmemcached/io.cc index fbfb8555..50fa77ae 100644 --- a/libmemcached/io.cc +++ b/libmemcached/io.cc @@ -677,7 +677,7 @@ memcached_server_write_instance_st memcached_io_get_readable_server(memcached_st struct pollfd fds[MAX_SERVERS_TO_POLL]; unsigned int host_index= 0; - for (uint32_t x= 0; x < memcached_server_count(memc) && host_index < MAX_SERVERS_TO_POLL; ++x) + for (uint32_t x= 0; x < memcached_server_count(memc) and host_index < MAX_SERVERS_TO_POLL; ++x) { memcached_server_write_instance_st instance= memcached_server_instance_fetch(memc, x); @@ -728,11 +728,12 @@ memcached_server_write_instance_st memcached_io_get_readable_server(memcached_st { for (uint32_t y= 0; y < memcached_server_count(memc); ++y) { - memcached_server_write_instance_st instance= - memcached_server_instance_fetch(memc, y); + memcached_server_write_instance_st instance= memcached_server_instance_fetch(memc, y); if (instance->fd == fds[x].fd) + { return instance; + } } } } diff --git a/libmemcached/response.cc b/libmemcached/response.cc index 437c4cc9..69ac26a4 100644 --- a/libmemcached/response.cc +++ b/libmemcached/response.cc @@ -38,7 +38,7 @@ #include #include -static memcached_return_t textual_value_fetch(memcached_server_write_instance_st ptr, +static memcached_return_t textual_value_fetch(memcached_server_write_instance_st instance, char *buffer, memcached_result_st *result) { @@ -46,7 +46,7 @@ static memcached_return_t textual_value_fetch(memcached_server_write_instance_st ssize_t read_length= 0; size_t value_length; - WATCHPOINT_ASSERT(ptr->root); + WATCHPOINT_ASSERT(instance->root); char *end_ptr= buffer + MEMCACHED_DEFAULT_COMMAND_SIZE; memcached_result_reset(result); @@ -57,13 +57,10 @@ static memcached_return_t textual_value_fetch(memcached_server_write_instance_st /* We load the key */ { - char *key; - size_t prefix_length; - - key= result->item_key; + char *key= result->item_key; result->key_length= 0; - for (prefix_length= memcached_array_size(ptr->root->_namespace); !(iscntrl(*string_ptr) || isspace(*string_ptr)) ; string_ptr++) + for (size_t prefix_length= memcached_array_size(instance->root->_namespace); !(iscntrl(*string_ptr) || isspace(*string_ptr)) ; string_ptr++) { if (prefix_length == 0) { @@ -133,7 +130,7 @@ static memcached_return_t textual_value_fetch(memcached_server_write_instance_st /* We add two bytes so that we can walk the \r\n */ if (memcached_failed(memcached_string_check(&result->value, value_length +2))) { - return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT); + return memcached_set_error(*instance, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT); } { @@ -146,11 +143,11 @@ static memcached_return_t textual_value_fetch(memcached_server_write_instance_st some people lazy about using the return length. */ size_t to_read= (value_length) + 2; - memcached_return_t rrc= memcached_io_read(ptr, value_ptr, to_read, read_length); + memcached_return_t rrc= memcached_io_read(instance, value_ptr, to_read, read_length); if (memcached_failed(rrc) and rrc == MEMCACHED_IN_PROGRESS) { - memcached_quit_server(ptr, true); - return memcached_set_error(*ptr, MEMCACHED_IN_PROGRESS, MEMCACHED_AT); + memcached_quit_server(instance, true); + return memcached_set_error(*instance, MEMCACHED_IN_PROGRESS, MEMCACHED_AT); } else if (memcached_failed(rrc)) { @@ -175,17 +172,17 @@ static memcached_return_t textual_value_fetch(memcached_server_write_instance_st return MEMCACHED_SUCCESS; read_error: - memcached_io_reset(ptr); + memcached_io_reset(instance); return MEMCACHED_PARTIAL_READ; } -static memcached_return_t textual_read_one_response(memcached_server_write_instance_st ptr, +static memcached_return_t textual_read_one_response(memcached_server_write_instance_st instance, char *buffer, const size_t buffer_length, memcached_result_st *result) { size_t total_read; - memcached_return_t rc= memcached_io_readline(ptr, buffer, buffer_length, total_read); + memcached_return_t rc= memcached_io_readline(instance, buffer, buffer_length, total_read); if (memcached_failed(rc)) { @@ -201,12 +198,46 @@ static memcached_return_t textual_read_one_response(memcached_server_write_insta if (buffer[1] == 'A' and buffer[2] == 'L' and buffer[3] == 'U' and buffer[4] == 'E') /* VALUE */ { /* We add back in one because we will need to search for END */ - memcached_server_response_increment(ptr); - return textual_value_fetch(ptr, buffer, result); + memcached_server_response_increment(instance); + return textual_value_fetch(instance, buffer, result); } // VERSION else if (buffer[1] == 'E' and buffer[2] == 'R' and buffer[3] == 'S' and buffer[4] == 'I' and buffer[5] == 'O' and buffer[6] == 'N') /* VERSION */ { + /* Find the space, and then move one past it to copy version */ + char *response_ptr= index(buffer, ' '); + response_ptr++; + + long int version= strtol(response_ptr, (char **)NULL, 10); + if (version == LONG_MIN or version == LONG_MAX or errno == EINVAL or version > UINT8_MAX or version == 0) + { + instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX; + return memcached_set_error(*instance, MEMCACHED_PROTOCOL_ERROR, MEMCACHED_AT, memcached_literal_param("strtol() failed to parse major version")); + } + instance->major_version= uint8_t(version); + + response_ptr= index(response_ptr, '.'); + response_ptr++; + + version= strtol(response_ptr, (char **)NULL, 10); + if (version == LONG_MIN or version == LONG_MAX or errno == EINVAL or version > UINT8_MAX) + { + instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX; + return memcached_set_error(*instance, MEMCACHED_PROTOCOL_ERROR, MEMCACHED_AT, memcached_literal_param("strtol() failed to parse minor version")); + } + instance->minor_version= uint8_t(version); + + response_ptr= index(response_ptr, '.'); + response_ptr++; + + version= strtol(response_ptr, (char **)NULL, 10); + if (version == LONG_MIN or version == LONG_MAX or errno == EINVAL or version > UINT8_MAX) + { + instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX; + return memcached_set_error(*instance, MEMCACHED_PROTOCOL_ERROR, MEMCACHED_AT, memcached_literal_param("strtol() failed to parse micro version")); + } + instance->micro_version= uint8_t(version); + return MEMCACHED_SUCCESS; } } @@ -227,7 +258,7 @@ static memcached_return_t textual_read_one_response(memcached_server_write_insta // STAT if (buffer[1] == 'T' and buffer[2] == 'A' and buffer[3] == 'T') /* STORED STATS */ { - memcached_server_response_increment(ptr); + memcached_server_response_increment(instance); return MEMCACHED_STAT; } // SERVER_ERROR @@ -262,7 +293,7 @@ static memcached_return_t textual_read_one_response(memcached_server_write_insta char *endptr= startptr; while (*endptr != '\r' && *endptr != '\n') endptr++; - return memcached_set_error(*ptr, MEMCACHED_SERVER_ERROR, MEMCACHED_AT, startptr, size_t(endptr - startptr)); + return memcached_set_error(*instance, MEMCACHED_SERVER_ERROR, MEMCACHED_AT, startptr, size_t(endptr - startptr)); } // STORED else if (buffer[1] == 'T' and buffer[2] == 'O' and buffer[3] == 'R') // and buffer[4] == 'E' and buffer[5] == 'D') @@ -346,7 +377,7 @@ static memcached_return_t textual_read_one_response(memcached_server_write_insta if (buffer[1] == 'T' and buffer[2] == 'E' and buffer[3] == 'M') { /* We add back in one because we will need to search for END */ - memcached_server_response_increment(ptr); + memcached_server_response_increment(instance); return MEMCACHED_ITEM; } } @@ -380,13 +411,13 @@ static memcached_return_t textual_read_one_response(memcached_server_write_insta if (auto_return_value == ULLONG_MAX and errno == ERANGE) { result->numeric_value= UINT64_MAX; - return memcached_set_error(*ptr, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT, + return memcached_set_error(*instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT, memcached_literal_param("Numeric response was out of range")); } else if (errno == EINVAL) { result->numeric_value= UINT64_MAX; - return memcached_set_error(*ptr, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT, + return memcached_set_error(*instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT, memcached_literal_param("Numeric response was out of range")); } @@ -405,22 +436,22 @@ static memcached_return_t textual_read_one_response(memcached_server_write_insta if (total_read >= sizeof("STORSTORED") -1) { fprintf(stderr, "%s:%d '%s', %.*s\n", __FILE__, __LINE__, - buffer, MEMCACHED_MAX_BUFFER, ptr->read_buffer); + buffer, MEMCACHED_MAX_BUFFER, instance->read_buffer); assert(memcmp(buffer,"STORSTORED", sizeof("STORSTORED") -1)); } #endif - return memcached_set_error(*ptr, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT, + return memcached_set_error(*instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT, buffer, total_read); } -static memcached_return_t binary_read_one_response(memcached_server_write_instance_st ptr, +static memcached_return_t binary_read_one_response(memcached_server_write_instance_st instance, char *buffer, const size_t buffer_length, memcached_result_st *result) { memcached_return_t rc; protocol_binary_response_header header; - if ((rc= memcached_safe_read(ptr, &header.bytes, sizeof(header.bytes))) != MEMCACHED_SUCCESS) + if ((rc= memcached_safe_read(instance, &header.bytes, sizeof(header.bytes))) != MEMCACHED_SUCCESS) { WATCHPOINT_ERROR(rc); return rc; @@ -428,7 +459,7 @@ static memcached_return_t binary_read_one_response(memcached_server_write_instan if (header.response.magic != PROTOCOL_BINARY_RES) { - return memcached_set_error(*ptr, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT); + return memcached_set_error(*instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT); } /* @@ -450,7 +481,7 @@ static memcached_return_t binary_read_one_response(memcached_server_write_instan * We didn't increment the response counter for the GETKQ packet * (only the final NOOP), so we need to increment the counter again. */ - memcached_server_response_increment(ptr); + memcached_server_response_increment(instance); /* FALLTHROUGH */ case PROTOCOL_BINARY_CMD_GETK: { @@ -458,7 +489,7 @@ static memcached_return_t binary_read_one_response(memcached_server_write_instan memcached_result_reset(result); result->item_cas= header.response.cas; - if ((rc= memcached_safe_read(ptr, &result->item_flags, sizeof (result->item_flags))) != MEMCACHED_SUCCESS) + if ((rc= memcached_safe_read(instance, &result->item_flags, sizeof (result->item_flags))) != MEMCACHED_SUCCESS) { WATCHPOINT_ERROR(rc); return MEMCACHED_UNKNOWN_READ_FAILURE; @@ -468,7 +499,7 @@ static memcached_return_t binary_read_one_response(memcached_server_write_instan bodylen -= header.response.extlen; result->key_length= keylen; - if (memcached_failed(rc= memcached_safe_read(ptr, result->item_key, keylen))) + if (memcached_failed(rc= memcached_safe_read(instance, result->item_key, keylen))) { WATCHPOINT_ERROR(rc); return MEMCACHED_UNKNOWN_READ_FAILURE; @@ -477,15 +508,15 @@ static memcached_return_t binary_read_one_response(memcached_server_write_instan // Only bother with doing this if key_length > 0 if (result->key_length) { - if (memcached_array_size(ptr->root->_namespace) and memcached_array_size(ptr->root->_namespace) >= result->key_length) + if (memcached_array_size(instance->root->_namespace) and memcached_array_size(instance->root->_namespace) >= result->key_length) { - return memcached_set_error(*ptr, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT); + return memcached_set_error(*instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT); } - if (memcached_array_size(ptr->root->_namespace)) + if (memcached_array_size(instance->root->_namespace)) { - result->key_length-= memcached_array_size(ptr->root->_namespace); - memmove(result->item_key, result->item_key +memcached_array_size(ptr->root->_namespace), result->key_length); + result->key_length-= memcached_array_size(instance->root->_namespace); + memmove(result->item_key, result->item_key +memcached_array_size(instance->root->_namespace), result->key_length); } } @@ -496,7 +527,7 @@ static memcached_return_t binary_read_one_response(memcached_server_write_instan } char *vptr= memcached_string_value_mutable(&result->value); - if (memcached_failed(rc= memcached_safe_read(ptr, vptr, bodylen))) + if (memcached_failed(rc= memcached_safe_read(instance, vptr, bodylen))) { WATCHPOINT_ERROR(rc); return MEMCACHED_UNKNOWN_READ_FAILURE; @@ -512,11 +543,11 @@ static memcached_return_t binary_read_one_response(memcached_server_write_instan if (bodylen != sizeof(uint64_t)) { result->numeric_value= UINT64_MAX; - return memcached_set_error(*ptr, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT); + return memcached_set_error(*instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT); } uint64_t val; - if ((rc= memcached_safe_read(ptr, &val, sizeof(val))) != MEMCACHED_SUCCESS) + if ((rc= memcached_safe_read(instance, &val, sizeof(val))) != MEMCACHED_SUCCESS) { result->numeric_value= UINT64_MAX; return MEMCACHED_UNKNOWN_READ_FAILURE; @@ -529,19 +560,41 @@ static memcached_return_t binary_read_one_response(memcached_server_write_instan case PROTOCOL_BINARY_CMD_SASL_LIST_MECHS: case PROTOCOL_BINARY_CMD_VERSION: { - memset(buffer, 0, buffer_length); - if (bodylen >= buffer_length) + char version_buffer[32]; // @todo document this number + memset(version_buffer, 0, sizeof(version_buffer)); + + if (memcached_safe_read(instance, version_buffer, bodylen) != MEMCACHED_SUCCESS) { - /* not enough space in buffer.. should not happen... */ return MEMCACHED_UNKNOWN_READ_FAILURE; } - else if ((rc= memcached_safe_read(ptr, buffer, bodylen)) != MEMCACHED_SUCCESS) + + char *p; + long int version= strtol(version_buffer, &p, 10); + if (version == LONG_MIN or version == LONG_MAX or errno == EINVAL or version > UINT8_MAX or version == 0) { - WATCHPOINT_ERROR(rc); - return MEMCACHED_UNKNOWN_READ_FAILURE; + instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX; + return memcached_set_error(*instance, MEMCACHED_PROTOCOL_ERROR, MEMCACHED_AT, memcached_literal_param("strtol() failed to parse major version")); + } + instance->major_version= uint8_t(version); + + version= strtol(p +1, &p, 10); + if (version == LONG_MIN or version == LONG_MAX or errno == EINVAL or version > UINT8_MAX) + { + instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX; + return memcached_set_error(*instance, MEMCACHED_PROTOCOL_ERROR, MEMCACHED_AT, memcached_literal_param("strtol() failed to parse micro version")); + } + instance->minor_version= uint8_t(version); + + version= strtol(p + 1, NULL, 10); + if (errno == ERANGE) + { + instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX; + return memcached_set_error(*instance, MEMCACHED_PROTOCOL_ERROR, MEMCACHED_AT, memcached_literal_param("strtol() failed to parse micro version")); } + instance->micro_version= uint8_t(version); } break; + case PROTOCOL_BINARY_CMD_FLUSH: case PROTOCOL_BINARY_CMD_QUIT: case PROTOCOL_BINARY_CMD_SET: @@ -577,8 +630,8 @@ static memcached_return_t binary_read_one_response(memcached_server_write_instan { size_t keylen= header.response.keylen; memset(buffer, 0, buffer_length); - if ((rc= memcached_safe_read(ptr, buffer, keylen)) != MEMCACHED_SUCCESS || - (rc= memcached_safe_read(ptr, buffer + keylen + 1, bodylen - keylen)) != MEMCACHED_SUCCESS) + if ((rc= memcached_safe_read(instance, buffer, keylen)) != MEMCACHED_SUCCESS || + (rc= memcached_safe_read(instance, buffer + keylen + 1, bodylen - keylen)) != MEMCACHED_SUCCESS) { WATCHPOINT_ERROR(rc); return MEMCACHED_UNKNOWN_READ_FAILURE; @@ -598,7 +651,7 @@ static memcached_return_t binary_read_one_response(memcached_server_write_instan return MEMCACHED_MEMORY_ALLOCATION_FAILURE; char *vptr= memcached_string_value_mutable(&result->value); - if ((rc= memcached_safe_read(ptr, vptr, bodylen)) != MEMCACHED_SUCCESS) + if ((rc= memcached_safe_read(instance, vptr, bodylen)) != MEMCACHED_SUCCESS) { WATCHPOINT_ERROR(rc); return MEMCACHED_UNKNOWN_READ_FAILURE; @@ -610,7 +663,7 @@ static memcached_return_t binary_read_one_response(memcached_server_write_instan default: { /* Command not implemented yet! */ - return memcached_set_error(*ptr, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT); + return memcached_set_error(*instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT); } } } @@ -621,10 +674,10 @@ static memcached_return_t binary_read_one_response(memcached_server_write_instan while (bodylen > 0) { size_t nr= (bodylen > SMALL_STRING_LEN) ? SMALL_STRING_LEN : bodylen; - if ((rc= memcached_safe_read(ptr, hole, nr)) != MEMCACHED_SUCCESS) + if ((rc= memcached_safe_read(instance, hole, nr)) != MEMCACHED_SUCCESS) { WATCHPOINT_ERROR(rc); - return memcached_set_error(*ptr, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT); + return memcached_set_error(*instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT); } bodylen-= (uint32_t) nr; } @@ -640,7 +693,7 @@ static memcached_return_t binary_read_one_response(memcached_server_write_instan case PROTOCOL_BINARY_CMD_REPLACEQ: case PROTOCOL_BINARY_CMD_APPENDQ: case PROTOCOL_BINARY_CMD_PREPENDQ: - return binary_read_one_response(ptr, buffer, buffer_length, result); + return binary_read_one_response(instance, buffer, buffer_length, result); default: break; @@ -683,7 +736,7 @@ static memcached_return_t binary_read_one_response(memcached_server_write_instan case PROTOCOL_BINARY_RESPONSE_EINVAL: case PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND: default: - return memcached_set_error(*ptr, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT); + return memcached_set_error(*instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT); break; } } @@ -691,72 +744,72 @@ static memcached_return_t binary_read_one_response(memcached_server_write_instan return rc; } -static memcached_return_t _read_one_response(memcached_server_write_instance_st ptr, +static memcached_return_t _read_one_response(memcached_server_write_instance_st instance, char *buffer, const size_t buffer_length, memcached_result_st *result) { - memcached_server_response_decrement(ptr); + memcached_server_response_decrement(instance); if (result == NULL) { - memcached_st *root= (memcached_st *)ptr->root; + memcached_st *root= (memcached_st *)instance->root; result = &root->result; } memcached_return_t rc; - if (memcached_is_binary(ptr->root)) + if (memcached_is_binary(instance->root)) { - rc= binary_read_one_response(ptr, buffer, buffer_length, result); + rc= binary_read_one_response(instance, buffer, buffer_length, result); } else { - rc= textual_read_one_response(ptr, buffer, buffer_length, result); + rc= textual_read_one_response(instance, buffer, buffer_length, result); assert(rc != MEMCACHED_PROTOCOL_ERROR); } if (memcached_fatal(rc)) { - memcached_io_reset(ptr); + memcached_io_reset(instance); } return rc; } -memcached_return_t memcached_read_one_response(memcached_server_write_instance_st ptr, +memcached_return_t memcached_read_one_response(memcached_server_write_instance_st instance, memcached_result_st *result) { char buffer[SMALL_STRING_LEN]; - if (memcached_is_udp(ptr->root)) + if (memcached_is_udp(instance->root)) { - return memcached_set_error(*ptr, MEMCACHED_NOT_SUPPORTED, MEMCACHED_AT); + return memcached_set_error(*instance, MEMCACHED_NOT_SUPPORTED, MEMCACHED_AT); } - return _read_one_response(ptr, buffer, sizeof(buffer), result); + return _read_one_response(instance, buffer, sizeof(buffer), result); } -memcached_return_t memcached_response(memcached_server_write_instance_st ptr, +memcached_return_t memcached_response(memcached_server_write_instance_st instance, memcached_result_st *result) { char buffer[1024]; - return memcached_response(ptr, buffer, sizeof(buffer), result); + return memcached_response(instance, buffer, sizeof(buffer), result); } -memcached_return_t memcached_response(memcached_server_write_instance_st ptr, +memcached_return_t memcached_response(memcached_server_write_instance_st instance, char *buffer, size_t buffer_length, memcached_result_st *result) { - if (memcached_is_udp(ptr->root)) + if (memcached_is_udp(instance->root)) { - return memcached_set_error(*ptr, MEMCACHED_NOT_SUPPORTED, MEMCACHED_AT); + return memcached_set_error(*instance, MEMCACHED_NOT_SUPPORTED, MEMCACHED_AT); } /* We may have old commands in the buffer not set, first purge */ - if ((ptr->root->flags.no_block) and (memcached_is_processing_input(ptr->root) == false)) + if ((instance->root->flags.no_block) and (memcached_is_processing_input(instance->root) == false)) { - (void)memcached_io_write(ptr); + (void)memcached_io_write(instance); } /* @@ -764,34 +817,19 @@ memcached_return_t memcached_response(memcached_server_write_instance_st ptr, * returned the last one. Purge all pending messages to ensure backwards * compatibility. */ - if (memcached_is_binary(ptr->root) == false and memcached_server_response_count(ptr) > 1) + if (memcached_is_binary(instance->root) == false and memcached_server_response_count(instance) > 1) { memcached_result_st junked_result; - memcached_result_st *junked_result_ptr= memcached_result_create(ptr->root, &junked_result); + memcached_result_st *junked_result_ptr= memcached_result_create(instance->root, &junked_result); assert(junked_result_ptr); - while (memcached_server_response_count(ptr) > 1) + while (memcached_server_response_count(instance) > 1) { - memcached_return_t rc= _read_one_response(ptr, buffer, buffer_length, junked_result_ptr); + memcached_return_t rc= _read_one_response(instance, buffer, buffer_length, junked_result_ptr); // @TODO should we return an error on another but a bad read case? - if ( - rc != MEMCACHED_DATA_EXISTS and - rc != MEMCACHED_DELETED and - rc != MEMCACHED_E2BIG and - rc != MEMCACHED_END and - rc != MEMCACHED_ERROR and - rc != MEMCACHED_ITEM and - rc != MEMCACHED_NOTFOUND and - rc != MEMCACHED_NOTSTORED and - rc != MEMCACHED_SERVER_ERROR and - rc != MEMCACHED_SERVER_MEMORY_ALLOCATION_FAILURE and - rc != MEMCACHED_STAT and - rc != MEMCACHED_STORED and - rc != MEMCACHED_SUCCESS and - rc != MEMCACHED_VALUE - ) + if (memcached_fatal(rc)) { memcached_result_free(junked_result_ptr); return rc; @@ -800,5 +838,5 @@ memcached_return_t memcached_response(memcached_server_write_instance_st ptr, memcached_result_free(junked_result_ptr); } - return _read_one_response(ptr, buffer, buffer_length, result); + return _read_one_response(instance, buffer, buffer_length, result); } diff --git a/libmemcached/version.cc b/libmemcached/version.cc index b889bf4f..9ba09b0d 100644 --- a/libmemcached/version.cc +++ b/libmemcached/version.cc @@ -47,8 +47,9 @@ static inline memcached_return_t memcached_version_textual(memcached_st *ptr) { { memcached_literal_param("version\r\n") }, }; - memcached_return_t rc= MEMCACHED_SUCCESS; + uint32_t success= 0; + bool errors_happened= false; for (uint32_t x= 0; x < memcached_server_count(ptr); x++) { memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x); @@ -59,67 +60,32 @@ static inline memcached_return_t memcached_version_textual(memcached_st *ptr) continue; } - memcached_return_t rrc= memcached_vdo(instance, vector, 1, true); - if (memcached_failed(rrc)) + memcached_return_t rrc; + if (memcached_failed(rrc= memcached_vdo(instance, vector, 1, true))) { + errors_happened= true; (void)memcached_set_error(*instance, rrc, MEMCACHED_AT); - instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX; - rc= MEMCACHED_SOME_ERRORS; - continue; - } - - char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; - rrc= memcached_response(instance, buffer, sizeof(buffer), NULL); - if (memcached_failed(rrc)) - { - memcached_set_error(*instance, rrc, MEMCACHED_AT); - instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX; - rc= MEMCACHED_SOME_ERRORS; - continue; - } - - /* Find the space, and then move one past it to copy version */ - char *response_ptr= index(buffer, ' '); - response_ptr++; - - long int version= strtol(response_ptr, (char **)NULL, 10); - if (version == LONG_MIN or version == LONG_MAX or errno == EINVAL or version > UINT8_MAX or version == 0) - { - memcached_set_error(*instance, MEMCACHED_PROTOCOL_ERROR, MEMCACHED_AT, memcached_literal_param("strtol() failed to parse major version")); - instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX; - rc= MEMCACHED_SOME_ERRORS; continue; } - instance->major_version= uint8_t(version); - - response_ptr= index(response_ptr, '.'); - response_ptr++; - - version= strtol(response_ptr, (char **)NULL, 10); - if (version == LONG_MIN or version == LONG_MAX or errno == EINVAL or version > UINT8_MAX) - { - memcached_set_error(*instance, MEMCACHED_PROTOCOL_ERROR, MEMCACHED_AT, memcached_literal_param("strtol() failed to parse minor version")); - instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX; - rc= MEMCACHED_SOME_ERRORS; - continue; - } - instance->minor_version= uint8_t(version); - - response_ptr= index(response_ptr, '.'); - response_ptr++; + success++; + } - version= strtol(response_ptr, (char **)NULL, 10); - if (version == LONG_MIN or version == LONG_MAX or errno == EINVAL or version > UINT8_MAX) + if (success) + { + // Collect the returned items + memcached_server_write_instance_st instance; + while ((instance= memcached_io_get_readable_server(ptr))) { - memcached_set_error(*instance, MEMCACHED_PROTOCOL_ERROR, MEMCACHED_AT, memcached_literal_param("strtol() failed to parse micro version")); - instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX; - rc= MEMCACHED_SOME_ERRORS; - continue; + memcached_return_t rrc= memcached_response(instance, NULL); + if (memcached_failed(rrc)) + { + memcached_io_reset(instance); + errors_happened= true; + } } - instance->micro_version= uint8_t(version); } - return rc; + return errors_happened ? MEMCACHED_SOME_ERRORS : MEMCACHED_SUCCESS; } static inline memcached_return_t memcached_version_binary(memcached_st *ptr) @@ -134,7 +100,8 @@ static inline memcached_return_t memcached_version_binary(memcached_st *ptr) { request.bytes, sizeof(request.bytes) } }; - memcached_return_t rc= MEMCACHED_SUCCESS; + uint32_t success= 0; + bool errors_happened= false; for (uint32_t x= 0; x < memcached_server_count(ptr); x++) { memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x); @@ -148,66 +115,30 @@ static inline memcached_return_t memcached_version_binary(memcached_st *ptr) if (memcached_failed(rrc)) { memcached_io_reset(instance); - rc= MEMCACHED_SOME_ERRORS; + errors_happened= true; continue; } + + success++; } - for (uint32_t x= 0; x < memcached_server_count(ptr); x++) + if (success) { - memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x); - - if (instance->major_version != UINT8_MAX) - { - continue; - } - - if (memcached_server_response_count(instance) > 0) + // Collect the returned items + memcached_server_write_instance_st instance; + while ((instance= memcached_io_get_readable_server(ptr))) { char buffer[32]; - char *p; - memcached_return_t rrc= memcached_response(instance, buffer, sizeof(buffer), NULL); if (memcached_failed(rrc)) { memcached_io_reset(instance); - rc= MEMCACHED_SOME_ERRORS; - continue; + errors_happened= true; } - - long int version= strtol(buffer, &p, 10); - if (version == LONG_MIN or version == LONG_MAX or errno == EINVAL or version > UINT8_MAX or version == 0) - { - memcached_set_error(*instance, MEMCACHED_PROTOCOL_ERROR, MEMCACHED_AT, memcached_literal_param("strtol() failed to parse major version")); - instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX; - rc= MEMCACHED_SOME_ERRORS; - continue; - } - instance->major_version= uint8_t(version); - - version= strtol(p +1, &p, 10); - if (version == LONG_MIN or version == LONG_MAX or errno == EINVAL or version > UINT8_MAX) - { - memcached_set_error(*instance, MEMCACHED_PROTOCOL_ERROR, MEMCACHED_AT, memcached_literal_param("strtol() failed to parse micro version")); - instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX; - rc= MEMCACHED_SOME_ERRORS; - continue; - } - instance->minor_version= uint8_t(version); - - version= strtol(p + 1, NULL, 10); - if (errno == ERANGE) - { - memcached_set_error(*instance, MEMCACHED_PROTOCOL_ERROR, MEMCACHED_AT, memcached_literal_param("strtol() failed to parse micro version")); - instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX; - rc= MEMCACHED_SOME_ERRORS; - continue; - } - instance->micro_version= uint8_t(version); } } - return rc; + return errors_happened ? MEMCACHED_SOME_ERRORS : MEMCACHED_SUCCESS; } memcached_return_t memcached_version(memcached_st *ptr) @@ -225,12 +156,8 @@ memcached_return_t memcached_version(memcached_st *ptr) if (memcached_is_binary(ptr)) { - rc= memcached_version_binary(ptr); - } - else - { - rc= memcached_version_textual(ptr); + return memcached_version_binary(ptr); } - return rc; + return memcached_version_textual(ptr); } diff --git a/m4/ax_check_library.m4 b/m4/ax_check_library.m4 index 9b9d9db3..24af93c0 100644 --- a/m4/ax_check_library.m4 +++ b/m4/ax_check_library.m4 @@ -60,7 +60,7 @@ # modified version of the Autoconf Macro, you may extend this special # exception to the GPL to apply to your modified version as well. -#serial 3 +#serial 4 AC_DEFUN([AX_CHECK_LIBRARY], [ AC_ARG_VAR($1[_CPPFLAGS], [C preprocessor flags for ]$1[ headers]) @@ -90,6 +90,6 @@ AC_DEFUN([AX_CHECK_LIBRARY], [ AS_IF([test "$]AS_TR_SH([ax_cv_have_]$1)[" = "yes"], AC_DEFINE([HAVE_]$1, [1], [Define to 1 if ]$1[ is found]) - m4_ifval(m4_normalize([$4]), [$4]), - m4_ifval(m4_normalize([$5]), [$5])) + m4_ifnblank([$4], [$4]), + m4_ifnblank([$5], [$5])) ]) diff --git a/m4/ax_cxx_gcc_abi_demangle.m4 b/m4/ax_cxx_gcc_abi_demangle.m4 index 11e8728c..2da0057e 100644 --- a/m4/ax_cxx_gcc_abi_demangle.m4 +++ b/m4/ax_cxx_gcc_abi_demangle.m4 @@ -25,34 +25,35 @@ #serial 9 -AC_DEFUN([AX_CXX_GCC_ABI_DEMANGLE], -[AC_CACHE_CHECK(whether the compiler supports GCC C++ ABI name demangling, -ax_cv_cxx_gcc_abi_demangle, -[AC_LANG_SAVE - AC_LANG_CPLUSPLUS - AC_TRY_COMPILE([#include + AC_DEFUN([AX_CXX_GCC_ABI_DEMANGLE], + [AC_CACHE_CHECK([whether the compiler supports GCC C++ ABI name demangling], + [ax_cv_cxx_gcc_abi_demangle], + [AC_LANG_PUSH([C++]) + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [ +#include #include #include #include -template -class A {}; -],[A instance; +template class A {}; + ],[ +A instance; int status = 0; char* c_name = 0; c_name = abi::__cxa_demangle(typeid(instance).name(), 0, 0, &status); - std::string name(c_name); ::free(c_name); - return name == "A"; -], - ax_cv_cxx_gcc_abi_demangle=yes, ax_cv_cxx_gcc_abi_demangle=no) - AC_LANG_RESTORE -]) -if test "$ax_cv_cxx_gcc_abi_demangle" = yes; then - AC_DEFINE(HAVE_GCC_ABI_DEMANGLE,1, - [define if the compiler supports GCC C++ ABI name demangling]) -fi -]) + ])], + [ax_cv_cxx_gcc_abi_demangle=yes], + [ax_cv_cxx_gcc_abi_demangle=no]) + AC_LANG_POP() + ]) + + if test "$ax_cv_cxx_gcc_abi_demangle" = yes; then + AC_DEFINE(HAVE_GCC_ABI_DEMANGLE, [1], [define if the compiler supports GCC C++ ABI name demangling]) + fi + ]) diff --git a/m4/ax_cxx_header_stdcxx_98.m4 b/m4/ax_cxx_header_stdcxx_98.m4 new file mode 100644 index 00000000..82e04c58 --- /dev/null +++ b/m4/ax_cxx_header_stdcxx_98.m4 @@ -0,0 +1,91 @@ +# =========================================================================== +# http://www.gnu.org/software/autoconf-archive/ax_cxx_header_stdcxx_98.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_CXX_HEADER_STDCXX_98 +# +# DESCRIPTION +# +# Check for complete library coverage of the C++1998/2003 standard. +# +# LICENSE +# +# Copyright (c) 2008 Benjamin Kosnik +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 7 + +AU_ALIAS([AC_CXX_HEADER_STDCXX_98], [AX_CXX_HEADER_STDCXX_98]) +AC_DEFUN([AX_CXX_HEADER_STDCXX_98], [ + AC_CACHE_CHECK([for ISO C++ 98 include files], [ax_cv_cxx_stdcxx_98], [ + AC_LANG_PUSH([C++]) + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + ], [ + int x + ]), [ax_cv_cxx_stdcxx_98=yes ], [ax_cv_cxx_stdcxx_98=no ] + ]) + + AC_LANG_POP + + ]) + + if test "$ax_cv_cxx_stdcxx_98" = yes; then + AC_DEFINE(STDCXX_98_HEADERS,,[Define if ISO C++ 1998 header files are present. ]) + fi +]) diff --git a/m4/ax_pthread.m4 b/m4/ax_pthread.m4 index a6bf596c..e20a388c 100644 --- a/m4/ax_pthread.m4 +++ b/m4/ax_pthread.m4 @@ -82,7 +82,7 @@ # modified version of the Autoconf Macro, you may extend this special # exception to the GPL to apply to your modified version as well. -#serial 16 +#serial 17 AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD]) AC_DEFUN([AX_PTHREAD], [ @@ -256,7 +256,14 @@ if test "x$ax_pthread_ok" = xyes; then flag=no case "${host_cpu}-${host_os}" in *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";; - *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";; + *-osf* | *-hpux*) flag="-D_REENTRANT";; + *solaris*) + if test "$GCC" = "yes"; then + flag="-D_REENTRANT" + else + flag="-mt -D_REENTRANT" + fi + ;; esac AC_MSG_RESULT(${flag}) if test "x$flag" != xno; then diff --git a/m4/have_cinttypes.m4 b/m4/have_cinttypes.m4 new file mode 100644 index 00000000..b28c74ed --- /dev/null +++ b/m4/have_cinttypes.m4 @@ -0,0 +1,87 @@ +# vim:ft=m4 +# =========================================================================== +# http://tangent.org/ +# =========================================================================== +# +# SYNOPSIS +# +# AX_CXX_CINTTYPES +# +# DESCRIPTION +# +# Example: +# +# LICENSE +# +# Copyright (c) 2012 Brian Aker` +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation, either version 3 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . +# +# As a special exception, the respective Autoconf Macro's copyright owner +# gives unlimited permission to copy, distribute and modify the configure +# scripts that are the output of Autoconf when processing the Macro. You +# need not follow the terms of the GNU General Public License when using +# or distributing such scripts, even though portions of the text of the +# Macro appear in them. The GNU General Public License (GPL) does govern +# all other use of the material that constitutes the Autoconf Macro. +# +# This special exception to the GPL applies to versions of the Autoconf +# Macro released by the Autoconf Archive. When you make and distribute a +# modified version of the Autoconf Macro, you may extend this special +# exception to the GPL to apply to your modified version as well. + +#serial 1 + + +AC_DEFUN([AX_CXX_CINTTYPES], + [ + AC_REQUIRE([AC_PROG_CXX]) + AC_REQUIRE([AC_PROG_CXXCPP]) + AC_REQUIRE([AX_CXX_CSTDINT]) + AC_MSG_CHECKING(the location of cinttypes) + save_CXXFLAGS="${CXXFLAGS}" + CXXFLAGS="${CXX_STANDARD} ${CXXFLAGS}" + ac_cv_cxx_cinttypes="" + + AC_LANG_PUSH([C++]) +# AC_CACHE_CHECK([for location of cinttypes], [ac_cv_cxx_cinttypes], +# [ +# Look for cinttypes + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include ], [ uint32_t foo= UINT32_C(1) ])], + [ac_cv_cxx_cinttypes=""], + [ +# Look for tr1/cinttypes + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include ], [ uint32_t foo= UINT32_C(1) ])], + [ac_cv_cxx_cinttypes=""], + [ +# Look for boost/cinttypes.hpp + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include ], [ uint32_t foo= UINT32_C(1) ])], + [ac_cv_cxx_cinttypes=""]) + ]) + ]) +# ]) + AC_LANG_POP() + + CXXFLAGS="${save_CXXFLAGS}" + if test -n "$ac_cv_cxx_cinttypes"; then + AC_MSG_RESULT([$ac_cv_cxx_cinttypes]) + else + ac_cv_cxx_cinttypes="" + AC_MSG_WARN([Could not find a cinttypes header.]) + AC_MSG_RESULT([$ac_cv_cxx_cinttypes]) + fi + + AC_DEFINE([__STDC_LIMIT_MACROS],[1],[Use STDC Limit Macros in C++]) + AC_DEFINE_UNQUOTED(CINTTYPES_H,$ac_cv_cxx_cinttypes, [the location of ]) + ]) diff --git a/m4/lib-prefix.m4 b/m4/lib-prefix.m4 index bab0cb7f..1601ceae 100644 --- a/m4/lib-prefix.m4 +++ b/m4/lib-prefix.m4 @@ -1,5 +1,5 @@ -# lib-prefix.m4 serial 6 (gettext-0.18) -dnl Copyright (C) 2001-2005, 2008 Free Software Foundation, Inc. +# lib-prefix.m4 serial 7 (gettext-0.18) +dnl Copyright (C) 2001-2005, 2008-2010 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -184,10 +184,10 @@ AC_DEFUN([AC_LIB_PREPARE_MULTILIB], dnl But we want to recognize the sparcv9 or amd64 subdirectory also if the dnl symlink is missing, so we set acl_libdirstem2 too. AC_CACHE_CHECK([for 64-bit host], [gl_cv_solaris_64bit], - [AC_RUN_IFELSE([ - AC_LANG_PROGRAM([], [[ - return sizeof(void*) == 8 ? 0 : 1; - ]]) + [AC_EGREP_CPP([sixtyfour bits], [ +#ifdef _LP64 +sixtyfour bits +#endif ], [gl_cv_solaris_64bit=yes], [gl_cv_solaris_64bit=no]) ]) if test $gl_cv_solaris_64bit = yes; then @@ -206,6 +206,9 @@ AC_DEFUN([AC_LIB_PREPARE_MULTILIB], if test -d "$searchdir"; then case "$searchdir" in */lib64/ | */lib64 ) acl_libdirstem=lib64 ;; + */../ | */.. ) + # Better ignore directories of this form. They are misleading. + ;; *) searchdir=`cd "$searchdir" && pwd` case "$searchdir" in */lib64 ) acl_libdirstem=lib64 ;; diff --git a/m4/pandora_canonical.m4 b/m4/pandora_canonical.m4 index b7da1ac3..1460c9df 100644 --- a/m4/pandora_canonical.m4 +++ b/m4/pandora_canonical.m4 @@ -61,7 +61,7 @@ AC_DEFUN([PANDORA_CANONICAL_TARGET],[ AS_IF([test "x${ac_cv_env_CXXFLAGS_set}" = "x"], [CXXFLAGS=""]) - AM_INIT_AUTOMAKE(-Wall -Werror -Wno-portability subdir-objects foreign tar-ustar) + AM_INIT_AUTOMAKE([-Wall -Werror -Wno-portability subdir-objects foreign tar-ustar]) m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) @@ -120,8 +120,6 @@ AC_DEFUN([PANDORA_CANONICAL_TARGET],[ AC_MSG_ERROR([No working C++ Compiler has been found. ${PACKAGE} requires a C++ compiler that can handle C++98]) ]) ]) - PANDORA_CXX_CSTDINT - PANDORA_CXX_CINTTYPES m4_if(m4_substr(m4_esyscmd(test -d gnulib && echo 0),0,1),0,[ gl_INIT diff --git a/m4/pandora_cinttypes.m4 b/m4/pandora_cinttypes.m4 deleted file mode 100644 index e4a8b478..00000000 --- a/m4/pandora_cinttypes.m4 +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright (C) 2008 Sun Microsystems, Inc. -# This file is free software; Sun Microsystems, Inc. -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# We check two things: where the include file is for cinttypes. We -# include AC_TRY_COMPILE for all the combinations we've seen in the -# wild. We define one of HAVE_CINTTYPES or HAVE_TR1_CINTTYPES or -# HAVE_BOOST_CINTTYPES depending -# on location. - -AC_DEFUN([PANDORA_CXX_CINTTYPES], - [AC_REQUIRE([PANDORA_CXX_CSTDINT]) - AC_MSG_CHECKING(the location of cinttypes) - AC_LANG_PUSH(C++) - save_CXXFLAGS="${CXXFLAGS}" - CXXFLAGS="${CXX_STANDARD} ${CXXFLAGS}" - ac_cv_cxx_cinttypes="" - for location in tr1/cinttypes boost/cinttypes cinttypes; do - if test -z "$ac_cv_cxx_cinttypes"; then - AC_TRY_COMPILE([#include $ac_cv_cxx_cstdint; - #include <$location>], - [uint32_t foo= UINT32_C(1)], - [ac_cv_cxx_cinttypes="<$location>";]) - fi - done - AC_LANG_POP() - CXXFLAGS="${save_CXXFLAGS}" - if test -n "$ac_cv_cxx_cinttypes"; then - AC_MSG_RESULT([$ac_cv_cxx_cinttypes]) - else - ac_cv_cxx_cinttypes="" - AC_MSG_RESULT() - AC_MSG_WARN([Could not find a cinttypes header.]) - fi - AC_DEFINE([__STDC_LIMIT_MACROS],[1],[Use STDC Limit Macros in C++]) - AC_DEFINE_UNQUOTED(CINTTYPES_H,$ac_cv_cxx_cinttypes, - [the location of ]) -]) diff --git a/m4/pandora_cstdint.m4 b/m4/pandora_cstdint.m4 deleted file mode 100644 index 9c848438..00000000 --- a/m4/pandora_cstdint.m4 +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright (C) 2008 Sun Microsystems, Inc. -# This file is free software; Sun Microsystems, Inc. -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# We check two things: where the include file is for cstdint. We -# include AC_TRY_COMPILE for all the combinations we've seen in the -# wild. We define one of HAVE_CSTDINT or HAVE_TR1_CSTDINT or -# HAVE_BOOST_CSTDINT depending -# on location. - -AC_DEFUN([PANDORA_CXX_CSTDINT], - [AC_MSG_CHECKING(the location of cstdint) - AC_LANG_PUSH(C++) - save_CXXFLAGS="${CXXFLAGS}" - CXXFLAGS="${CXX_STANDARD} ${CXXFLAGS}" - ac_cv_cxx_cstdint="" - for location in tr1/cstdint boost/cstdint cstdint; do - if test -z "$ac_cv_cxx_cstdint"; then - AC_TRY_COMPILE([#include <$location>], - [uint32_t t], - [ac_cv_cxx_cstdint="<$location>";]) - fi - done - AC_LANG_POP() - CXXFLAGS="${save_CXXFLAGS}" - if test -n "$ac_cv_cxx_cstdint"; then - AC_MSG_RESULT([$ac_cv_cxx_cstdint]) - else - AC_DEFINE([__STDC_CONSTANT_MACROS],[1],[Use STDC Constant Macros in C++]) - AC_DEFINE([__STDC_FORMAT_MACROS],[1],[Use STDC Format Macros in C++]) - ac_cv_cxx_cstdint="" - AC_MSG_RESULT() - AC_MSG_WARN([Could not find a cstdint header.]) - fi - AC_DEFINE_UNQUOTED(CSTDINT_H,$ac_cv_cxx_cstdint, - [the location of ]) -]) diff --git a/m4/pandora_have_innodb.m4 b/m4/pandora_have_innodb.m4 deleted file mode 100644 index db50aedd..00000000 --- a/m4/pandora_have_innodb.m4 +++ /dev/null @@ -1,41 +0,0 @@ -dnl Copyright (C) 2009 Sun Microsystems -dnl This file is free software; Sun Microsystems -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -AC_DEFUN([_PANDORA_SEARCH_LIBINNODB],[ - AC_REQUIRE([AC_LIB_PREFIX]) - - dnl -------------------------------------------------------------------- - dnl Check for libinnodb - dnl -------------------------------------------------------------------- - - AC_ARG_ENABLE([libinnodb], - [AS_HELP_STRING([--disable-libinnodb], - [Build with libinnodb support @<:@default=on@:>@])], - [ac_enable_libinnodb="$enableval"], - [ac_enable_libinnodb="yes"]) - - AS_IF([test "x$ac_enable_libinnodb" = "xyes"],[ - AC_LIB_HAVE_LINKFLAGS(innodb,,[ - #include - ],[ - ib_u64_t - ib_api_version(void); - ]) - ],[ - ac_cv_libinnodb="no" - ]) - - AM_CONDITIONAL(HAVE_LIBINNODB, [test "x${ac_cv_libinnodb}" = "xyes"]) -]) - -AC_DEFUN([PANDORA_HAVE_LIBINNODB],[ - AC_REQUIRE([_PANDORA_SEARCH_LIBINNODB]) -]) - -AC_DEFUN([PANDORA_REQUIRE_LIBINNODB],[ - AC_REQUIRE([PANDORA_HAVE_LIBINNODB]) - AS_IF([test "x${ac_cv_libinnodb}" = "xno"], - AC_MSG_ERROR([libinnodb is required for ${PACKAGE}])) -]) diff --git a/m4/pandora_have_libevent.m4 b/m4/pandora_have_libevent.m4 deleted file mode 100644 index c7a6c645..00000000 --- a/m4/pandora_have_libevent.m4 +++ /dev/null @@ -1,66 +0,0 @@ -dnl Copyright (C) 2009 Sun Microsystems, Inc. -dnl This file is free software; Sun Microsystems, Inc. -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -#-------------------------------------------------------------------- -# Check for libevent -#-------------------------------------------------------------------- - - -AC_DEFUN([_PANDORA_SEARCH_LIBEVENT],[ - AC_REQUIRE([AC_LIB_PREFIX]) - - AC_LIB_HAVE_LINKFLAGS(event,, - [ - #include - #include - #include - #include - ],[ - struct bufferevent bev; - bufferevent_settimeout(&bev, 1, 1); - event_init(); - event_loop(EVLOOP_ONCE); - ]) - - AM_CONDITIONAL(HAVE_LIBEVENT, [test "x${ac_cv_libevent}" = "xyes"]) - - AS_IF([test "x${ac_cv_libevent}" = "xyes"],[ - save_LIBS="${LIBS}" - LIBS="${LIBS} ${LTLIBEVENT}" - AC_CHECK_FUNCS(event_base_new) - AC_CHECK_FUNCS(event_base_free) - AC_CHECK_FUNCS(event_base_get_method) - LIBS="$save_LIBS" - ]) -]) - -AC_DEFUN([_PANDORA_HAVE_LIBEVENT],[ - - AC_ARG_ENABLE([libevent], - [AS_HELP_STRING([--disable-libevent], - [Build with libevent support @<:@default=on@:>@])], - [ac_enable_libevent="$enableval"], - [ac_enable_libevent="yes"]) - - _PANDORA_SEARCH_LIBEVENT -]) - - -AC_DEFUN([PANDORA_HAVE_LIBEVENT],[ - AC_REQUIRE([_PANDORA_HAVE_LIBEVENT]) -]) - -AC_DEFUN([_PANDORA_REQUIRE_LIBEVENT],[ - ac_enable_libevent="yes" - _PANDORA_SEARCH_LIBEVENT - - AS_IF([test x$ac_cv_libevent = xno],[ - AC_MSG_ERROR([libevent is required for ${PACKAGE}. On Debian this can be found in libevent-dev. On RedHat this can be found in libevent-devel.]) - ]) -]) - -AC_DEFUN([PANDORA_REQUIRE_LIBEVENT],[ - AC_REQUIRE([_PANDORA_REQUIRE_LIBEVENT]) -]) diff --git a/m4/pandora_have_libinnodb.m4 b/m4/pandora_have_libinnodb.m4 deleted file mode 100644 index b49374a2..00000000 --- a/m4/pandora_have_libinnodb.m4 +++ /dev/null @@ -1,64 +0,0 @@ -dnl Copyright (C) 2009 Sun Microsystems -dnl This file is free software; Sun Microsystems -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -AC_DEFUN([_PANDORA_SEARCH_LIBINNODB],[ - AC_REQUIRE([AC_LIB_PREFIX]) - - dnl -------------------------------------------------------------------- - dnl Check for libinnodb - dnl -------------------------------------------------------------------- - - AC_ARG_ENABLE([libinnodb], - [AS_HELP_STRING([--disable-libinnodb], - [Build with libinnodb support @<:@default=on@:>@])], - [ac_enable_libinnodb="$enableval"], - [ac_enable_libinnodb="yes"]) - - AS_IF([test "x$ac_enable_libinnodb" = "xyes"],[ - AC_LIB_HAVE_LINKFLAGS(innodb,,[ - #include - ],[ - ib_u64_t - ib_api_version(void); - ]) - ],[ - ac_cv_libinnodb="no" - ]) - - - AC_CACHE_CHECK([if libinnodb is recent enough], - [ac_cv_recent_innodb_h],[ - save_LIBS=${LIBS} - LIBS="${LIBS} ${LTLIBINNODB}" - AC_LINK_IFELSE( - [AC_LANG_PROGRAM([[ - #include - ]],[[ - /* Make sure we have the two-arg version */ - ib_table_drop(NULL, "nothing"); - ]])],[ - ac_cv_recent_innodb_h=yes - ],[ - ac_cv_recent_innodb_h=no - ]) - LIBS="${save_LIBS}" - ]) - AS_IF([test "x${ac_cv_recent_innodb_h}" = "xno"],[ - AC_MSG_WARN([${PACKAGE} requires at least version 1.0.6 of Embedded InnoDB]) - ac_cv_libinnodb=no - ]) - - AM_CONDITIONAL(HAVE_LIBINNODB, [test "x${ac_cv_libinnodb}" = "xyes"]) -]) - -AC_DEFUN([PANDORA_HAVE_LIBINNODB],[ - AC_REQUIRE([_PANDORA_SEARCH_LIBINNODB]) -]) - -AC_DEFUN([PANDORA_REQUIRE_LIBINNODB],[ - AC_REQUIRE([PANDORA_HAVE_LIBINNODB]) - AS_IF([test "x${ac_cv_libinnodb}" = "xno"], - AC_MSG_ERROR([libinnodb is required for ${PACKAGE}])) -]) diff --git a/m4/pandora_platform.m4 b/m4/pandora_platform.m4 index 4d51d2b5..bd570f61 100644 --- a/m4/pandora_platform.m4 +++ b/m4/pandora_platform.m4 @@ -88,8 +88,9 @@ AC_DEFUN([PANDORA_PLATFORM],[ AM_CFLAGS="${AM_CFLAGS} -I\${top_srcdir}/win32/mingw -I\${top_builddir}/win32/mingw -I\${top_srcdir}/win32 -I\${top_builddir}/win32" ;; esac - AM_CONDITIONAL(TARGET_LINUX, [test "x${TARGET_LINUX}" = "xtrue"]) AM_CONDITIONAL(BUILD_WIN32, [test "x${TARGET_WINDOWS}" = "xtrue"]) + AM_CONDITIONAL(TARGET_OSX, [test "x${TARGET_OSX}" = "xtrue"]) + AM_CONDITIONAL(TARGET_LINUX, [test "x${TARGET_LINUX}" = "xtrue"]) AC_SUBST(PANDORA_OPTIMIZE_BITFIELD) diff --git a/m4/pandora_vc_build.m4 b/m4/pandora_vc_build.m4 index a1fb60b3..1adb2809 100644 --- a/m4/pandora_vc_build.m4 +++ b/m4/pandora_vc_build.m4 @@ -34,135 +34,3 @@ AC_DEFUN([PANDORA_TEST_VC_DIR],[ pandora_building_from_git=no fi ]) - -AC_DEFUN([PANDORA_BUILDING_FROM_VC],[ - m4_syscmd(PANDORA_TEST_VC_DIR - m4_if(PCT_NO_VC_CHANGELOG,yes,[ - vc_changelog=no - ],[ - vc_changelog=yes - ]) - - [ - - PANDORA_RELEASE_DATE=`date +%Y.%m` - PANDORA_RELEASE_NODOTS_DATE=`date +%Y%m` - - # Set some defaults - PANDORA_VC_REVNO="0" - PANDORA_VC_REVID="unknown" - PANDORA_VC_BRANCH="bzr-export" - - if test "${pandora_building_from_bzr}" = "yes"; then - echo "# Grabbing changelog and version information from bzr" - PANDORA_BZR_REVNO=`bzr revno` - if test "x$PANDORA_BZR_REVNO" != "x${PANDORA_VC_REVNO}" ; then - PANDORA_VC_REVNO="${PANDORA_BZR_REVNO}" - PANDORA_VC_REVID=`bzr log -r-1 --show-ids | grep revision-id | cut -f2 -d' ' | head -1` - PANDORA_VC_BRANCH=`bzr nick` - PANDORA_VC_TAG=`bzr tags -r-1 | cut -f1 -d' ' | head -1` - PANDORA_VC_LATEST_TAG=`bzr tags --sort=time | grep -v '\?'| cut -f1 -d' ' | tail -1` - if test "x${vc_changelog}" = "xyes"; then - bzr log --gnu > ChangeLog - fi - fi - elif test "${pandora_building_from_git}" = "yes"; then - echo "# Grabbing changelog and version information from git" - PANDORA_GIT_REVID=`git --no-pager log --max-count=1 | cut -f2 -d' ' | head -1` - if test "x$PANDORA_GIT_REVID" != "x${PANDORA_VC_REVNO}" ; then - PANDORA_VC_REVID="${PANDORA_GIT_REVID}" - PANDORA_VC_BRANCH=`git branch | grep -Ei "\* (.*)" | cut -f2 -d' '` - fi - fi - - if ! test -d config ; then - mkdir -p config - fi - - if test "${pandora_building_from_bzr}" = "yes" -o ! -f config/pandora_vc_revinfo ; then - cat > config/pandora_vc_revinfo.tmp </dev/null 2>&1 ; then - mv config/pandora_vc_revinfo.tmp config/pandora_vc_revinfo - fi - rm -f config/pandora_vc_revinfo.tmp - fi - ]) -]) - -AC_DEFUN([_PANDORA_READ_FROM_FILE],[ - $1=`grep $1 $2 | cut -f2 -d=` -]) - -AC_DEFUN([PANDORA_VC_VERSION],[ - AC_REQUIRE([PANDORA_BUILDING_FROM_VC]) - - PANDORA_TEST_VC_DIR - - AS_IF([test -f ${srcdir}/config/pandora_vc_revinfo],[ - _PANDORA_READ_FROM_FILE([PANDORA_VC_REVNO],${srcdir}/config/pandora_vc_revinfo) - _PANDORA_READ_FROM_FILE([PANDORA_VC_REVID],${srcdir}/config/pandora_vc_revinfo) - _PANDORA_READ_FROM_FILE([PANDORA_VC_BRANCH], - ${srcdir}/config/pandora_vc_revinfo) - _PANDORA_READ_FROM_FILE([PANDORA_VC_TAG], - ${srcdir}/config/pandora_vc_revinfo) - _PANDORA_READ_FROM_FILE([PANDORA_VC_LATEST_TAG], - ${srcdir}/config/pandora_vc_revinfo) - _PANDORA_READ_FROM_FILE([PANDORA_RELEASE_DATE], - ${srcdir}/config/pandora_vc_revinfo) - _PANDORA_READ_FROM_FILE([PANDORA_RELEASE_NODOTS_DATE], - ${srcdir}/config/pandora_vc_revinfo) - ]) - AS_IF([test "x${PANDORA_VC_BRANCH}" != x"${PACKAGE}"],[ - PANDORA_RELEASE_COMMENT="${PANDORA_VC_BRANCH}" - ],[ - PANDORA_RELEASE_COMMENT="trunk" - ]) - - AS_IF([test "x${PANDORA_VC_TAG}" != "x"],[ - PANDORA_RELEASE_VERSION="${PANDORA_VC_TAG}" - ],[ - AS_IF([test "x${PANDORA_VC_LATEST_TAG}" != "x"],[ - PANDORA_RELEASE_VERSION="${PANDORA_VC_LATEST_TAG}.${PANDORA_VC_REVNO}" - ],[ - PANDORA_RELEASE_VERSION="${PANDORA_RELEASE_DATE}.${PANDORA_VC_REVNO}" - ]) - ]) - changequote(<<, >>)dnl - PANDORA_RELEASE_ID=`echo ${PANDORA_RELEASE_VERSION} | sed 's/[^0-9]//g'` - changequote([, ])dnl - - - VERSION="${PANDORA_RELEASE_VERSION}" - AC_DEFINE_UNQUOTED([PANDORA_RELEASE_VERSION],["${PANDORA_RELEASE_VERSION}"], - [The real version of the software]) - AC_SUBST(PANDORA_VC_REVNO) - AC_SUBST(PANDORA_VC_REVID) - AC_SUBST(PANDORA_VC_BRANCH) - AC_SUBST(PANDORA_RELEASE_DATE) - AC_SUBST(PANDORA_RELEASE_NODOTS_DATE) - AC_SUBST(PANDORA_RELEASE_COMMENT) - AC_SUBST(PANDORA_RELEASE_VERSION) - AC_SUBST(PANDORA_RELEASE_ID) -]) - -AC_DEFUN([PANDORA_VC_INFO_HEADER],[ - AC_REQUIRE([PANDORA_VC_VERSION]) - m4_define([PANDORA_VC_PREFIX],m4_toupper(m4_normalize(AC_PACKAGE_NAME))[_]) - - AC_DEFINE_UNQUOTED(PANDORA_VC_PREFIX[VC_REVNO], [$PANDORA_VC_REVNO], [Version control revision number]) - AC_DEFINE_UNQUOTED(PANDORA_VC_PREFIX[VC_REVID], ["$PANDORA_VC_REVID"], [Version control revision ID]) - AC_DEFINE_UNQUOTED(PANDORA_VC_PREFIX[VC_BRANCH], ["$PANDORA_VC_BRANCH"], [Version control branch name]) - AC_DEFINE_UNQUOTED(PANDORA_VC_PREFIX[RELEASE_DATE], ["$PANDORA_RELEASE_DATE"], [Release date of version control checkout]) - AC_DEFINE_UNQUOTED(PANDORA_VC_PREFIX[RELEASE_NODOTS_DATE], [$PANDORA_RELEASE_NODOTS_DATE], [Numeric formatted release date of checkout]) - AC_DEFINE_UNQUOTED(PANDORA_VC_PREFIX[RELEASE_COMMENT], ["$PANDORA_RELEASE_COMMENT"], [Set to trunk if the branch is the main $PACKAGE branch]) - AC_DEFINE_UNQUOTED(PANDORA_VC_PREFIX[RELEASE_VERSION], ["$PANDORA_RELEASE_VERSION"], [Release date and revision number of checkout]) - AC_DEFINE_UNQUOTED(PANDORA_VC_PREFIX[RELEASE_ID], [$PANDORA_RELEASE_ID], [Numeric formatted release date and revision number of checkout]) -]) diff --git a/m4/socket_send_flags.m4 b/m4/socket_send_flags.m4 index 8b569eef..1eefa1bd 100644 --- a/m4/socket_send_flags.m4 +++ b/m4/socket_send_flags.m4 @@ -14,7 +14,7 @@ AC_DEFUN([SOCKET_SEND_FLAGS], save_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS -I${srcdir}" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include ], [ int flags= MSG_NOSIGNAL ])], [ac_cv_msg_nosignal="yes"]) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include ], [ int flags= MSG_NOSIGNAL ])], [ac_cv_msg_nosignal="yes"]) AC_LANG_POP ]) @@ -23,7 +23,7 @@ AC_DEFUN([SOCKET_SEND_FLAGS], save_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS -I${srcdir}" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include ], [ int flags= MSG_DONTWAIT ])], [ac_cv_msg_dontwait="yes"]) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include ], [ int flags= MSG_DONTWAIT ])], [ac_cv_msg_dontwait="yes"]) AC_LANG_POP ]) diff --git a/tests/memstat.cc b/tests/memstat.cc index ec7dd4f8..33a14e33 100644 --- a/tests/memstat.cc +++ b/tests/memstat.cc @@ -70,21 +70,31 @@ static test_return_t help_test(void *) return TEST_SUCCESS; } -static test_return_t ascii_test(void *) +static test_return_t binary_TEST(void *) { char buffer[1024]; - snprintf(buffer, sizeof(buffer), "-p %d", int(default_port())); - const char *args[]= { "--quiet", buffer, " -a ", 0 }; + snprintf(buffer, sizeof(buffer), "--servers=localhost:%d", int(default_port())); + const char *args[]= { "--quiet", buffer, " --binary ", 0 }; test_true(exec_cmdline(executable, args)); return TEST_SUCCESS; } -static test_return_t binary_test(void *) +static test_return_t server_version_TEST(void *) { char buffer[1024]; - snprintf(buffer, sizeof(buffer), "-p %d", int(default_port())); - const char *args[]= { "--quiet", buffer, " -b ", 0 }; + snprintf(buffer, sizeof(buffer), "--servers=localhost:%d", int(default_port())); + const char *args[]= { "--quiet", buffer, " --server-version", 0 }; + + test_true(exec_cmdline(executable, args)); + return TEST_SUCCESS; +} + +static test_return_t binary_server_version_TEST(void *) +{ + char buffer[1024]; + snprintf(buffer, sizeof(buffer), "--servers=localhost:%d", int(default_port())); + const char *args[]= { "--quiet", buffer, " --binary --server-version", 0 }; test_true(exec_cmdline(executable, args)); return TEST_SUCCESS; @@ -93,8 +103,9 @@ static test_return_t binary_test(void *) test_st memstat_tests[] ={ {"--quiet", 0, quiet_test}, {"--help", 0, help_test}, - {"-a, ascii", 0, ascii_test}, - {"-b, binary", 0, binary_test}, + {"--binary", 0, binary_TEST}, + {"--server-version", 0, server_version_TEST}, + {"--binary --server-version", 0, binary_server_version_TEST}, {0, 0, 0} };