+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().
+# vim:ft=automake
+
ACLOCAL_AMFLAGS = -I m4
# includes append to these:
OPT_USERNAME,
OPT_PASSWD,
OPT_STAT_ARGS,
+ OPT_SERVER_VERSION,
OPT_QUIET,
OPT_FILE= 'f'
};
#include <unistd.h>
#include <libmemcached-1.0/memcached.h>
-#include <libmemcached/close_socket.hpp>
+#include <libmemcached/socket.hpp>
#include <libmemcached/memcached/protocol_binary.h>
#include <libmemcached/byteorder.h>
#include <clients/utilities.h>
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;
{(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},
};
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);
}
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);
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);
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 */
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;
};
#!/bin/sh
+# Copyright (C) 2011 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:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. 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.
+# 3. The name of the author 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.
+
autoreconf --install --force --verbose -Wall
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])
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"],
dnl Specialty checks
AX_PTHREAD
+AX_CXX_CINTTYPES
CONFIG_EXTRA
DETECT_BYTEORDER
ENABLE_UTILLIB
AX_COMPILER_VENDOR
AC_CXX_HEADER_STDCXX_98
-AX_TLS
AC_FUNC_ALLOCA
AC_FUNC_ERROR_AT_LINE
AM_CFLAGS="$AM_CFLAGS $NO_WERROR"
AM_CXXFLAGS="$AM_CXXFLAGS $NO_WERROR"
])
-DETECT_EAGAIN
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
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
#include <event.h>
#include <libmemcachedprotocol-0.0/handler.h>
-#include <libmemcached/close_socket.hpp>
+#include <libmemcached/socket.hpp>
#include <example/byteorder.h>
#include "example/storage.h"
#include "example/memcached_light.h"
+++ /dev/null
-/* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */
-#include <stdlib.h>
-#include <inttypes.h>
-#include <time.h>
-#include <stdbool.h>
-#include <string.h>
-#include <unistd.h>
-#include <assert.h>
-#include <embedded_innodb-1.0/innodb.h>
-
-#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);
-}
#pragma once
#include <inttypes.h>
+
+#ifdef __cplusplus
+#include <cstddef>
+#include <cstdlib>
+#else
+#include <stddef.h>
#include <stdlib.h>
+#endif
+
#include <sys/types.h>
+++ /dev/null
-/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
- *
- * LibMemcached
- *
- * 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
-
-
-/* To hide the platform differences between MS Windows and Unix, I am
- * going to use the Microsoft way and #define the Microsoft-specific
- * functions to the unix way. Microsoft use a separate subsystem for sockets,
- * but Unix normally just use a filedescriptor on the same functions. It is
- * a lot easier to map back to the unix way with macros than going the other
- * way without side effect ;-)
- */
-#ifdef WIN32
-#include "win32/wrappers.h"
-#define get_socket_errno() WSAGetLastError()
-#else
-#define INVALID_SOCKET -1
-#define SOCKET_ERROR -1
-#define closesocket(a) close(a)
-#define get_socket_errno() errno
-#endif
-
-#ifdef __cplusplus
-static inline void memcached_close_socket(int& socket_fd)
-{
- closesocket(socket_fd);
- socket_fd= INVALID_SOCKET;
-}
-#endif
-
-#ifndef HAVE_MSG_NOSIGNAL
-#define MSG_NOSIGNAL 0
-#endif
-
-#ifndef HAVE_MSG_DONTWAIT
-#define MSG_DONTWAIT 0
-#endif
-
-#ifndef HAVE_MSG_MORE
-#define MSG_MORE 0
-#endif
-
-
#include <libmemcached/io.hpp>
#include <libmemcached/udp.hpp>
#include <libmemcached/do.hpp>
-#include <libmemcached/close_socket.hpp>
+#include <libmemcached/socket.hpp>
#include <libmemcached/connect.hpp>
#include <libmemcached/allocators.hpp>
#include <libmemcached/hash.hpp>
timeout_error_occured= true;
break;
+ case EAGAIN:
+#if EWOULDBLOCK != EAGAIN
case EWOULDBLOCK:
+#endif
case EINPROGRESS: // nonblocking mode - first return
case EALREADY: // nonblocking mode - subsequent returns
{
libmemcached/assert.hpp \
libmemcached/backtrace.hpp \
libmemcached/byteorder.h \
- libmemcached/close_socket.hpp \
libmemcached/common.h \
libmemcached/connect.hpp \
libmemcached/continuum.hpp \
libmemcached/response.h \
libmemcached/server.hpp \
libmemcached/server_instance.h \
+ libmemcached/socket.hpp \
libmemcached/string.hpp \
libmemcached/udp.hpp \
libmemcached/virtual_bucket.h \
case EINTR:
continue;
+#if EWOULDBLOCK != EAGAIN
case EWOULDBLOCK:
-#ifdef USE_EAGAIN
- case EAGAIN:
#endif
+ case EAGAIN:
#ifdef TARGET_OS_LINUX
case ERESTART:
#endif
{
case ENOBUFS:
continue;
+
+#if EWOULDBLOCK != EAGAIN
case EWOULDBLOCK:
-#ifdef USE_EAGAIN
- case EAGAIN:
#endif
+ case EAGAIN:
{
/*
* We may be blocked on write because the input buffer
continue;
case ETIMEDOUT: // OSX
+#if EWOULDBLOCK != EAGAIN
case EWOULDBLOCK:
-#ifdef USE_EAGAIN
- case EAGAIN:
#endif
+ case EAGAIN:
#ifdef TARGET_OS_LINUX
case ERESTART:
#endif
continue;
case ETIMEDOUT: // OSX
+#if EWOULDBLOCK != EAGAIN
case EWOULDBLOCK:
-#ifdef USE_EAGAIN
- case EAGAIN:
#endif
+ case EAGAIN:
#ifdef TARGET_OS_LINUX
case ERESTART:
#endif
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);
{
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;
+ }
}
}
}
#include <libmemcached/common.h>
#include <libmemcached/string.hpp>
-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)
{
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);
/* 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)
{
/* 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);
}
{
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))
{
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))
{
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;
}
}
// 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
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')
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;
}
}
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"));
}
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;
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);
}
/*
* 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:
{
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;
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;
// 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);
}
}
}
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;
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;
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:
{
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;
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;
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);
}
}
}
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;
}
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;
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;
}
}
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);
}
/*
* 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;
memcached_result_free(junked_result_ptr);
}
- return _read_one_response(ptr, buffer, buffer_length, result);
+ return _read_one_response(instance, buffer, buffer_length, result);
}
--- /dev/null
+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ *
+ * LibMemcached
+ *
+ * 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
+
+
+/* To hide the platform differences between MS Windows and Unix, I am
+ * going to use the Microsoft way and #define the Microsoft-specific
+ * functions to the unix way. Microsoft use a separate subsystem for sockets,
+ * but Unix normally just use a filedescriptor on the same functions. It is
+ * a lot easier to map back to the unix way with macros than going the other
+ * way without side effect ;-)
+ */
+#ifdef WIN32
+#include "win32/wrappers.h"
+#define get_socket_errno() WSAGetLastError()
+#else
+#define INVALID_SOCKET -1
+#define SOCKET_ERROR -1
+#define closesocket(a) close(a)
+#define get_socket_errno() errno
+#endif
+
+#ifdef __cplusplus
+static inline void memcached_close_socket(int& socket_fd)
+{
+ closesocket(socket_fd);
+ socket_fd= INVALID_SOCKET;
+}
+#endif
+
+#ifndef HAVE_MSG_NOSIGNAL
+#define MSG_NOSIGNAL 0
+#endif
+
+#ifndef HAVE_MSG_DONTWAIT
+#define MSG_DONTWAIT 0
+#endif
+
+#ifndef HAVE_MSG_MORE
+#define MSG_MORE 0
+#endif
+
+
{
{ 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);
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)
{ 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);
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)
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);
}
*/
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+#include "config.h"
+
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#pragma once
#include "config.h"
-#if !defined(__cplusplus)
-# include <stdbool.h>
-#endif
#include <assert.h>
#include <libmemcachedprotocol-0.0/handler.h>
#include <libmemcachedprotocol/cache.h>
#include <libmemcached/byteorder.h>
-#include <libmemcached/close_socket.hpp>
+#include <libmemcached/socket.hpp>
/*
* I don't really need the following two functions as function pointers
memcached_return_t rc= MEMCACHED_SUCCESS;
if (has_socket())
{
- local_pid= libmemcached_util_getpid(socket().c_str(), 0, &rc);
+ if (socket().empty())
+ {
+ return -1;
+ }
+
+ local_pid= libmemcached_util_getpid(socket().c_str(), port(), &rc);
}
else
{
# 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])
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]))
])
#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 <typeinfo>
+ 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 <typeinfo>
#include <cxxabi.h>
#include <cstdlib>
#include <string>
-template<typename TYPE>
-class A {};
-],[A<int> instance;
+template<typename TYPE> class A {};
+ ],[
+A<int> 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<int>";
-],
- 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
+ ])
--- /dev/null
+# ===========================================================================
+# 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 <bkoz@redhat.com>
+#
+# 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 <cassert>
+#include <cctype>
+#include <cerrno>
+#include <cfloat>
+#include <ciso646>
+#include <climits>
+#include <clocale>
+#include <cmath>
+#include <csetjmp>
+#include <csignal>
+#include <cstdarg>
+#include <cstddef>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <ctime>
+
+#include <algorithm>
+#include <bitset>
+#include <complex>
+#include <deque>
+#include <exception>
+#include <fstream>
+#include <functional>
+#include <iomanip>
+#include <ios>
+#include <iosfwd>
+#include <iostream>
+#include <istream>
+#include <iterator>
+#include <limits>
+#include <list>
+#include <locale>
+#include <map>
+#include <memory>
+#include <new>
+#include <numeric>
+#include <ostream>
+#include <queue>
+#include <set>
+#include <sstream>
+#include <stack>
+#include <stdexcept>
+#include <streambuf>
+#include <string>
+#include <typeinfo>
+#include <utility>
+#include <valarray>
+#include <vector>
+ ], [
+ 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
+])
# 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], [
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
+++ /dev/null
-# ===========================================================================
-# http://www.gnu.org/software/autoconf-archive/ax_tls.html
-# ===========================================================================
-#
-# SYNOPSIS
-#
-# AX_TLS([action-if-found], [action-if-not-found])
-#
-# DESCRIPTION
-#
-# Provides a test for the compiler support of thread local storage (TLS)
-# extensions. Defines TLS if it is found. Currently knows about GCC/ICC
-# and MSVC. I think SunPro uses the same as GCC, and Borland apparently
-# supports either.
-#
-# LICENSE
-#
-# Copyright (c) 2008 Alan Woodland <ajw05@aber.ac.uk>
-# Copyright (c) 2010 Diego Elio Petteno` <flameeyes@gmail.com>
-#
-# 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 <http://www.gnu.org/licenses/>.
-#
-# 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 10
-
-AC_DEFUN([AX_TLS], [
- AC_MSG_CHECKING(for thread local storage (TLS) class)
- AC_CACHE_VAL(ac_cv_tls, [
- ax_tls_keywords="__thread __declspec(thread) none"
- for ax_tls_keyword in $ax_tls_keywords; do
- AS_CASE([$ax_tls_keyword],
- [none], [ac_cv_tls=none ; break],
- [AC_TRY_COMPILE(
- [#include <stdlib.h>
- static void
- foo(void) {
- static ] $ax_tls_keyword [ int bar;
- exit(1);
- }],
- [],
- [ac_cv_tls=$ax_tls_keyword ; break],
- ac_cv_tls=none
- )])
- done
- ])
- AC_MSG_RESULT($ac_cv_tls)
-
- AS_IF([test "$ac_cv_tls" != "none"],
- AC_DEFINE_UNQUOTED([TLS], $ac_cv_tls, [If the compiler supports a TLS storage class define it to that here])
- m4_ifnblank([$1], [$1]),
- m4_ifnblank([$2], [$2])
- )
-])
AC_DEFUN([CONFIG_EXTRA], [
+AH_TOP([
+#pragma once
+
+/* _SYS_FEATURE_TESTS_H is Solaris, _FEATURES_H is GCC */
+#if defined( _SYS_FEATURE_TESTS_H) || defined(_FEATURES_H)
+#error "You should include config.h as your first include file"
+#endif
+
+])
+
AH_BOTTOM([
#if defined(__cplusplus)
])
-AH_BOTTOM([
-#ifdef WIN32
-#define _WIN32_WINNT 0x0501
-#endif
-
-/* To hide the platform differences between MS Windows and Unix, I am
- * going to use the Microsoft way and #define the Microsoft-specific
- * functions to the unix way. Microsoft use a separate subsystem for sockets,
- * but Unix normally just use a filedescriptor on the same functions. It is
- * a lot easier to map back to the unix way with macros than going the other
- * way without side effect ;-)
- */
-#ifdef WIN32
-#include "win32/wrappers.h"
-#define get_socket_errno() WSAGetLastError()
-#else
-#define INVALID_SOCKET -1
-#define SOCKET_ERROR -1
-#define closesocket(a) close(a)
-#define get_socket_errno() errno
-#endif
-
-#ifndef HAVE_MSG_NOSIGNAL
-#define MSG_NOSIGNAL 0
-#endif
-
-#ifndef HAVE_MSG_DONTWAIT
-#define MSG_DONTWAIT 0
-#endif
-
-#ifndef HAVE_MSG_MORE
-#define MSG_MORE 0
-#endif
-
-])
])dnl CONFIG_EXTRA
+++ /dev/null
-#
-# Some platforms define EWOULDBLOCK == EAGAIN, causing our switch for error
-# codes to be illegal (POSIX.1-2001 allows both return codes from recv, so
-# we need to test both if they differ...)
-#
-AC_DEFUN([DETECT_EAGAIN],
-[
- AC_CACHE_CHECK([if EWOULDBLOCK == EAGAIN],[av_cv_eagain_ewouldblock],
- [AC_TRY_COMPILE([
-#include <errno.h>
- ], [
-int error = EAGAIN;
-switch (error)
-{
- case EAGAIN:
- case EWOULDBLOCK:
- error = 1;
- break;
- default:
- error = 0;
-}
- ],
- [ av_cv_eagain_ewouldblock=no ],
- [ av_cv_eagain_ewouldblock=yes ])
- ])
- AS_IF([test "x$av_cv_eagain_ewouldblock" = "xno"],[
- AC_DEFINE([USE_EAGAIN], [1], [Define to true if you need to test for eagain])])
-])
--- /dev/null
+# vim:ft=m4
+# ===========================================================================
+# http://tangent.org/
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_CXX_CINTTYPES
+#
+# DESCRIPTION
+#
+# Example:
+#
+# LICENSE
+#
+# Copyright (c) 2012 Brian Aker` <brian@tangent.org>
+#
+# 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 <http://www.gnu.org/licenses/>.
+#
+# 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 <cinttypes>], [ uint32_t foo= UINT32_C(1) ])],
+ [ac_cv_cxx_cinttypes="<cinttypes>"],
+ [
+# Look for tr1/cinttypes
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <tr1/cinttypes>], [ uint32_t foo= UINT32_C(1) ])],
+ [ac_cv_cxx_cinttypes="<tr1/cinttypes>"],
+ [
+# Look for boost/cinttypes.hpp
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <boost/cinttypes.hpp>], [ uint32_t foo= UINT32_C(1) ])],
+ [ac_cv_cxx_cinttypes="<boost/cinttypes.hpp>"])
+ ])
+ ])
+# ])
+ 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="<inttypes.h>"
+ 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 <cinttypes>])
+ ])
--- /dev/null
+# ===========================================================================
+# http://tangent.org/
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_CXX_CSTDINT
+#
+# DESCRIPTION
+#
+# Example:
+#
+# LICENSE
+#
+# Copyright (c) 2012 Brian Aker` <brian@tangent.org>
+#
+# 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 <http://www.gnu.org/licenses/>.
+#
+# 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_CSTDINT],
+ [
+ AC_REQUIRE([AC_PROG_CXX])
+ AC_REQUIRE([AC_PROG_CXXCPP])
+
+ AC_MSG_CHECKING(the location of cstdint)
+ AC_LANG_PUSH([C++])
+ save_CXXFLAGS="${CXXFLAGS}"
+ CXXFLAGS="${CXX_STANDARD} ${CXXFLAGS}"
+ ac_cv_cxx_cstdint=""
+
+ AC_LANG_PUSH([C++])
+# AC_CACHE_CHECK([for location of cstdint], [ac_cv_cxx_cstdint],
+# [
+# Look for cstdint
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <cstdint>], [ uint32_t t ])],
+ [ac_cv_cxx_cstdint="<cstdint>"],
+ [
+# Look for tr1/cstdint
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <tr1/cstdint>], [ uint32_t t ])],
+ [ac_cv_cxx_cstdint="<tr1/cstdint>"],
+ [
+# Look for boost/cstdint.hpp
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <boost/cstdint.hpp>], [ uint32_t t ])],
+ [ac_cv_cxx_cstdint="<boost/cstdint.hpp>"])
+
+ ])
+ ])
+# ])
+
+ AC_LANG_POP()
+
+ CXXFLAGS="${save_CXXFLAGS}"
+ if test -n "$ac_cv_cxx_cstdint"; then
+ AC_MSG_RESULT([$ac_cv_cxx_cstdint])
+ else
+ ac_cv_cxx_cstdint="<stdint.h>"
+ AC_MSG_WARN([Could not find a cstdint header.])
+ AC_MSG_RESULT([$ac_cv_cxx_cstdint])
+ fi
+
+ AC_DEFINE_UNQUOTED(CSTDINT_H,$ac_cv_cxx_cstdint, [the location of <cstdint>])
+
+ ])
-# 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.
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
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 ;;
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])])
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
+++ /dev/null
-# 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="<inttypes.h>"
- 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 <cinttypes>])
-])
+++ /dev/null
-# 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="<stdint.h>"
- 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 <cstdint>])
-])
+++ /dev/null
-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 <embedded_innodb-1.0/innodb.h>
- ],[
- 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}]))
-])
+++ /dev/null
-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 <sys/types.h>
- #include <sys/time.h>
- #include <stdlib.h>
- #include <event.h>
- ],[
- 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])
-])
+++ /dev/null
-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 <embedded_innodb-1.0/innodb.h>
- ],[
- 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 <embedded_innodb-1.0/innodb.h>
- ]],[[
- /* 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}]))
-])
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)
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 <<EOF
-PANDORA_VC_REVNO=${PANDORA_VC_REVNO}
-PANDORA_VC_REVID=${PANDORA_VC_REVID}
-PANDORA_VC_BRANCH=${PANDORA_VC_BRANCH}
-PANDORA_VC_TAG=${PANDORA_VC_TAG}
-PANDORA_VC_LATEST_TAG=${PANDORA_VC_LATEST_TAG}
-PANDORA_RELEASE_DATE=${PANDORA_RELEASE_DATE}
-PANDORA_RELEASE_NODOTS_DATE=${PANDORA_RELEASE_NODOTS_DATE}
-EOF
- if ! diff config/pandora_vc_revinfo.tmp config/pandora_vc_revinfo >/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])
-])
# pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*-
+# serial 1 (pkg-config-0.24)
#
# Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
#
AC_DEFUN([PKG_PROG_PKG_CONFIG],
[m4_pattern_forbid([^_?PKG_[A-Z_]+$])
m4_pattern_allow([^PKG_CONFIG(_PATH)?$])
-AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])dnl
+AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])
+AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path])
+AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path])
+
if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
fi
AC_MSG_RESULT([no])
PKG_CONFIG=""
fi
-
fi[]dnl
])# PKG_PROG_PKG_CONFIG
# Check to see whether a particular set of modules exists. Similar
# to PKG_CHECK_MODULES(), but does not set variables or print errors.
#
-#
-# Similar to PKG_CHECK_MODULES, make sure that the first instance of
-# this or PKG_CHECK_MODULES is called, or make sure to call
-# PKG_CHECK_EXISTS manually
+# Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG])
+# only at the first occurence in configure.ac, so if the first place
+# it's called might be skipped (such as if it is within an "if", you
+# have to call PKG_CHECK_EXISTS manually
# --------------------------------------------------------------
AC_DEFUN([PKG_CHECK_EXISTS],
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
if test -n "$PKG_CONFIG" && \
AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then
- m4_ifval([$2], [$2], [:])
+ m4_default([$2], [:])
m4_ifvaln([$3], [else
$3])dnl
fi])
-
# _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES])
# ---------------------------------------------
m4_define([_PKG_CONFIG],
-[if test -n "$PKG_CONFIG"; then
- if test -n "$$1"; then
- pkg_cv_[]$1="$$1"
- else
- PKG_CHECK_EXISTS([$3],
- [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`],
- [pkg_failed=yes])
- fi
-else
- pkg_failed=untried
+[if test -n "$$1"; then
+ pkg_cv_[]$1="$$1"
+ elif test -n "$PKG_CONFIG"; then
+ PKG_CHECK_EXISTS([$3],
+ [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`],
+ [pkg_failed=yes])
+ else
+ pkg_failed=untried
fi[]dnl
])# _PKG_CONFIG
See the pkg-config man page for more details.])
if test $pkg_failed = yes; then
+ AC_MSG_RESULT([no])
_PKG_SHORT_ERRORS_SUPPORTED
if test $_pkg_short_errors_supported = yes; then
- $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --errors-to-stdout --print-errors "$2"`
+ $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "$2" 2>&1`
else
- $1[]_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "$2"`
+ $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors "$2" 2>&1`
fi
# Put the nasty error message in config.log where it belongs
echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
- ifelse([$4], , [AC_MSG_ERROR(dnl
+ m4_default([$4], [AC_MSG_ERROR(
[Package requirements ($2) were not met:
$$1_PKG_ERRORS
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
-_PKG_TEXT
-])],
- [AC_MSG_RESULT([no])
- $4])
+_PKG_TEXT])
+ ])
elif test $pkg_failed = untried; then
- ifelse([$4], , [AC_MSG_FAILURE(dnl
+ AC_MSG_RESULT([no])
+ m4_default([$4], [AC_MSG_FAILURE(
[The pkg-config script could not be found or is too old. Make sure it
is in your PATH or set the PKG_CONFIG environment variable to the full
path to pkg-config.
_PKG_TEXT
-To get pkg-config, see <http://pkg-config.freedesktop.org/>.])],
- [$4])
+To get pkg-config, see <http://pkg-config.freedesktop.org/>.])
+ ])
else
$1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
$1[]_LIBS=$pkg_cv_[]$1[]_LIBS
AC_MSG_RESULT([yes])
- ifelse([$3], , :, [$3])
+ $3
fi[]dnl
])# PKG_CHECK_MODULES
+dnl Copyright (C) 2012 Data Differential LLC
dnl Copyright (C) 2011 Trond Norbye
dnl This file is free software; Trond Norbye
dnl gives unlimited permission to copy and/or distribute it,
AC_LANG_PUSH([C])
save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -I${srcdir}"
- AC_TRY_LINK([
-#include <sys/socket.h>
- ], [
-int flags= MSG_NOSIGNAL;
- ],
- [ ac_cv_msg_nosignal=yes ],
- [ ac_cv_msg_nosignal=no ])
- CFLAGS="$save_CFLAGS"
- AC_LANG_POP
+
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <netdb.h>], [ int flags= MSG_NOSIGNAL ])], [ac_cv_msg_nosignal="yes"])
+ AC_LANG_POP
])
AC_CACHE_CHECK([for MSG_DONTWAIT], [ac_cv_msg_dontwait], [
AC_LANG_PUSH([C])
save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -I${srcdir}"
- AC_TRY_LINK([
-#include <sys/socket.h>
- ], [
-int flags= MSG_DONTWAIT;
- ],
- [ ac_cv_msg_dontwait=yes ],
- [ ac_cv_msg_dontwait=no ])
- CFLAGS="$save_CFLAGS"
- AC_LANG_POP
+
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <netdb.h>], [ int flags= MSG_DONTWAIT ])], [ac_cv_msg_dontwait="yes"])
+ AC_LANG_POP
])
AC_CACHE_CHECK([for MSG_MORE], [ac_cv_msg_more], [
AC_LANG_PUSH([C])
save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -I${srcdir}"
- AC_TRY_LINK([
-#include <sys/socket.h>
- ], [
-int flags= MSG_MORE;
- ],
- [ ac_cv_msg_more=yes ],
- [ ac_cv_msg_more=no ])
- CFLAGS="$save_CFLAGS"
- AC_LANG_POP
+
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <netdb.h>], [ int flags= MSG_MORE ])], [ac_cv_msg_more="yes"])
+ AC_LANG_POP
])
- AS_IF([test "x$ac_cv_msg_nosignal" = "xyes"],[
- AC_DEFINE(HAVE_MSG_NOSIGNAL, 1, [Define to 1 if you have a MSG_NOSIGNAL])])
- AS_IF([test "x$ac_cv_msg_dontwait" = "xyes"],[
- AC_DEFINE(HAVE_MSG_DONTWAIT, 1, [Define to 1 if you have a MSG_DONTWAIT])])
- AS_IF([test "x$ac_cv_msg_more" = "xyes"],[
- AC_DEFINE(HAVE_MSG_MORE, 1, [Define to 1 if you have a HAVE_MSG_MORE])])
+ AS_IF([test "x$ac_cv_msg_nosignal" = "xyes"],[ AC_DEFINE(HAVE_MSG_NOSIGNAL, 1, [Define to 1 if you have a MSG_NOSIGNAL])])
+ AS_IF([test "x$ac_cv_msg_dontwait" = "xyes"],[ AC_DEFINE(HAVE_MSG_DONTWAIT, 1, [Define to 1 if you have a MSG_DONTWAIT])])
+ AS_IF([test "x$ac_cv_msg_more" = "xyes"],[ AC_DEFINE(HAVE_MSG_MORE, 1, [Define to 1 if you have a MSG_MORE])])
])
dnl ---------------------------------------------------------------------------
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;
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}
};