Merge trunk.
authorBrian Aker <brian@tangent.org>
Wed, 17 Aug 2011 21:05:28 +0000 (14:05 -0700)
committerBrian Aker <brian@tangent.org>
Wed, 17 Aug 2011 21:05:28 +0000 (14:05 -0700)
clients/memcapable.cc
clients/memcat.cc
clients/memcp.cc
clients/memparse.cc
libmemcached/common.h
libmemcached/sasl.cc
libmemcached/server.h
libtest/unittest.cc
tests/mem_functions.cc

index 9dff427eb3c2c9c88e8c5463569aa895ca8d65d6..1bb7a88a675abbc20cedacccc366331ff57d94d2 100644 (file)
 #include "poll/poll.h"
 #endif
 
-#include <assert.h>
+#include <cassert>
+#include <cerrno>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
 #include <ctype.h>
-#include <errno.h>
 #include <fcntl.h>
 #include <inttypes.h>
 #include <pthread.h>
 #include <signal.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
 #include <sys/types.h>
 #include <unistd.h>
 
index 66ee3253b37b616700133ab17eea6c8a37374d7b..3e073650345750b35b3325855f1b4fe63af77fca 100644 (file)
@@ -9,14 +9,13 @@
  *
  */
 
-#include "config.h"
+#include <config.h>
 
+#include <cstdio>
+#include <cstring>
+#include <getopt.h>
 #include <iostream>
-#include <stdio.h>
-#include <inttypes.h>
-#include <string.h>
 #include <unistd.h>
-#include <getopt.h>
 #include <libmemcached/memcached.h>
 
 #include "utilities.h"
index 7b7454760e7e8a4cd36db8a675e91f08930fbc13..228362513905beabef0108285301d6c48f3d741f 100644 (file)
 
 #include "config.h"
 
-#include <iostream>
-#include <stdio.h>
-#include <stdlib.h>
-#include <inttypes.h>
-#include <unistd.h>
+#include <cerrno>
+#include <climits>
+#include <cstdio>
+#include <cstdlib>
+#include <cstdlib>
+#include <cstring>
+#include <fcntl.h>
 #include <getopt.h>
-#include <sys/types.h>
+#include <iostream>
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
 #include <sys/stat.h>
 #include <sys/types.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <strings.h>
-#include <string.h>
 #include <sys/types.h>
-#include <stdlib.h>
-#include <limits.h>
+#include <sys/types.h>
+#include <unistd.h>
 
 
 #include <libmemcached/memcached.h>
index f9a2dcf2f5b97cfd1464fc55d386ad904bd94dda..c2557dfd325ad8c52bb311e767f9ddf17284f929 100644 (file)
@@ -38,6 +38,7 @@
 #include <config.h>
 
 #include <cstdio>
+#include <cstring>
 #include <iostream>
 
 #include <libmemcached/memcached.h>
index 5af6916c1be1982fe156f1880b930b7e9dd25bb8..f45eaffd4474894390f8d1142eb2796cdcefb61d 100644 (file)
 #include <sys/types.h>
 #include <unistd.h>
 
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+
 #include <libmemcached/memcached.h>
 #include <libmemcached/watchpoint.h>
 #include <libmemcached/is.h>
index f1de41eaec4fe30f86416da7714f625e169c0ba6..3aefb701f9bfd93cb0fa343f3cf7feeff5752f4c 100644 (file)
@@ -98,12 +98,15 @@ static memcached_return_t resolve_names(memcached_server_st& server, char *laddr
   return MEMCACHED_SUCCESS;
 }
 
+extern "C" {
+
 static void sasl_shutdown_function()
 {
   sasl_done();
 }
 
-static int sasl_startup_state= SASL_OK;
+static volatile int sasl_startup_state= SASL_OK;
+pthread_mutex_t sasl_startup_state_LOCK= PTHREAD_MUTEX_INITIALIZER;
 static pthread_once_t sasl_startup_once= PTHREAD_ONCE_INIT;
 static void sasl_startup_function(void)
 {
@@ -115,6 +118,8 @@ static void sasl_startup_function(void)
   }
 }
 
+} // extern "C"
+
 memcached_return_t memcached_sasl_authenticate_connection(memcached_server_st *server)
 {
   if (LIBMEMCACHED_WITH_SASL_SUPPORT == 0)
@@ -182,12 +187,14 @@ memcached_return_t memcached_sasl_authenticate_connection(memcached_server_st *s
     return memcached_set_errno(*server, pthread_error, MEMCACHED_AT);
   }
 
+  (void)pthread_mutex_lock(&sasl_startup_state_LOCK);
   if (sasl_startup_state != SASL_OK)
   {
     const char *sasl_error_msg= sasl_errstring(sasl_startup_state, NULL, NULL);
     return memcached_set_error(*server, MEMCACHED_AUTH_PROBLEM, MEMCACHED_AT, 
                                memcached_string_make_from_cstr(sasl_error_msg));
   }
+  (void)pthread_mutex_unlock(&sasl_startup_state_LOCK);
 
   sasl_conn_t *conn;
   int ret;
index dc1121531d422736a033d481b228dce8ff08dbac..40328ab6e6cbda2d2209b505a9f6e9bf007cb6c8 100644 (file)
 
 #pragma once
 
+#ifndef WIN32
+#include <netdb.h>
+#endif
+
 enum memcached_server_state_t {
   MEMCACHED_SERVER_STATE_NEW, // fd == -1, no address lookup has been done
   MEMCACHED_SERVER_STATE_ADDRINFO, // ADDRRESS information has been gathered
index 93192a255b17d7ba82dbd560458dc4d96f404436..cee9b52ec1f5e24ea20e54343a301fcb86c69d13 100644 (file)
@@ -64,7 +64,9 @@ static test_return_t GDB_COMMAND_test(void *)
 static test_return_t test_success_equals_one_test(void *)
 {
   test_skip(HAVE_LIBMEMCACHED, true);
+#if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED 
   test_zero(MEMCACHED_SUCCESS);
+#endif
   return TEST_SUCCESS;
 }
 
@@ -206,7 +208,9 @@ static test_return_t _compare_test_return_t_test(void *)
 static test_return_t _compare_memcached_return_t_test(void *)
 {
   test_skip(HAVE_LIBMEMCACHED, true);
+#if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED 
   test_compare(MEMCACHED_SUCCESS, MEMCACHED_SUCCESS);
+#endif
 
   return TEST_SUCCESS;
 }
@@ -214,6 +218,9 @@ static test_return_t _compare_memcached_return_t_test(void *)
 static test_return_t _compare_gearman_return_t_test(void *)
 {
   test_skip(HAVE_LIBGEARMAN, true);
+#if defined(HAVE_LIBGEARMAN) && HAVE_LIBGEARMAN
+    test_compare(GEARMAN_SUCCESS, GEARMAN_SUCCESS);
+#endif
 
   return TEST_SUCCESS;
 }
index ab850f5097a64f67c74077ef4096bf47d948b5b2..d691cbc57dd5f6186c686d3bb211c776d152bb33 100644 (file)
@@ -1497,6 +1497,34 @@ static test_return_t decrement_with_initial_by_key_test(memcached_st *memc)
 
   return TEST_SUCCESS;
 }
+static test_return_t binary_increment_with_prefix_test(memcached_st *orig_memc)
+{
+  memcached_st *memc= memcached_clone(NULL, orig_memc);
+
+  test_skip(TEST_SUCCESS, pre_binary(memc));
+
+  test_compare(MEMCACHED_SUCCESS, memcached_callback_set(memc, MEMCACHED_CALLBACK_PREFIX_KEY, (void *)"namespace:"));
+
+  memcached_return_t rc;
+  rc= memcached_set(memc,
+                    test_literal_param("number"),
+                    test_literal_param("0"),
+                    (time_t)0, (uint32_t)0);
+  test_true(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
+
+  uint64_t new_number;
+  test_compare(MEMCACHED_SUCCESS, memcached_increment(memc, 
+                                                      test_literal_param("number"), 
+                                                      1, &new_number));
+  test_compare(uint64_t(1), new_number);
+
+  test_compare(MEMCACHED_SUCCESS, memcached_increment(memc,
+                                                      test_literal_param("number"),
+                                                      1, &new_number));
+  test_compare(uint64_t(2), new_number);
+
+  return TEST_SUCCESS;
+}
 
 static test_return_t quit_test(memcached_st *memc)
 {
@@ -5853,6 +5881,7 @@ test_st tests[] ={
   {"increment_with_initial_by_key", true, (test_callback_fn*)increment_with_initial_by_key_test },
   {"decrement_by_key", false, (test_callback_fn*)decrement_by_key_test },
   {"decrement_with_initial_by_key", true, (test_callback_fn*)decrement_with_initial_by_key_test },
+  {"binary_increment_with_prefix", 1, (test_callback_fn*)binary_increment_with_prefix_test },
   {"quit", false, (test_callback_fn*)quit_test },
   {"mget", true, (test_callback_fn*)mget_test },
   {"mget_result", true, (test_callback_fn*)mget_result_test },