Merge trunk
authorBrian Aker <brian@tangent.org>
Mon, 15 Aug 2011 22:28:57 +0000 (15:28 -0700)
committerBrian Aker <brian@tangent.org>
Mon, 15 Aug 2011 22:28:57 +0000 (15:28 -0700)
16 files changed:
.bzrignore
example/interface_v0.c
libmemcached/initialize_query.cc
libmemcached/memcached.h
libmemcached/memcached.hpp
libmemcached/protocol/ascii_handler.c
libmemcached/protocol/cache.c
libmemcached/protocol/pedantic.c
libmemcached/protocol/protocol_handler.c
libmemcached/stats.cc
libmemcached/storage.cc
tests/cycle.cc
tests/mem_udp.cc
tests/parser.cc
tests/plus.cpp
tests/replication.cc

index 034514bb07d3fab2b9dd4447002125c9bfaae7f7..c28f4fd1ef443fbfcfe8f52303859a4793477511 100644 (file)
@@ -41,6 +41,7 @@ clients/memdump
 clients/memerror
 clients/memflush
 clients/memparse
+clients/memping
 clients/memrm
 clients/memslap
 clients/memstat
@@ -80,7 +81,9 @@ libmemcached/generated_probes.h
 libmemcached/memcached_configure.h
 libtest/.hg/
 libtest/.hgignore
+libtest/skiptest
 libtest/unittest
+libtest/version.h
 libtest/wait
 libtool
 libtool.m4
@@ -104,6 +107,7 @@ support/libmemcached.pc
 support/libmemcached.spec
 tags
 tests/atomsmasher
+tests/c_sasl_test
 tests/c_test
 tests/cycle
 tests/hash_plus
@@ -113,15 +117,12 @@ tests/memcapable
 tests/memplus
 tests/memslap
 tests/output.cmp
+tests/sasl
 tests/startservers
 tests/testapp
 tests/testhashkit
 tests/testplus
 tests/testudp
 tests/var/
+tmp_chroot
 unittests/unittests
-libtest/version.h
-clients/memping
-libtest/skiptest
-tests/sasl
-tests/c_sasl_test
index 625b4dd92c203d4ad64e5f515c08f2251e91c953..1a847ccf111f819e44be76a62ce3312651028423 100644 (file)
@@ -4,7 +4,9 @@
  * in the protocol library. You might want to have your copy of the protocol
  * specification next to your coffee ;-)
  */
+
 #include "config.h"
+
 #include <assert.h>
 #include <sys/types.h>
 #include <stdio.h>
index 00e8e6420f0bd657c95d0ebd84aa49e1fa7b1328..027b156672cfe547a5b86560c37e4a51573360cf 100644 (file)
@@ -39,7 +39,9 @@
 memcached_return_t initialize_query(memcached_st *self)
 {
   if (not self)
+  {
     return MEMCACHED_INVALID_ARGUMENTS;
+  }
 
   self->query_id++;
 
@@ -59,7 +61,9 @@ memcached_return_t initialize_query(memcached_st *self)
 memcached_return_t initialize_const_query(const memcached_st *self)
 {
   if (not self)
+  {
     return MEMCACHED_INVALID_ARGUMENTS;
+  }
 
   if (memcached_server_count(self) == 0)
   {
index 440898e1e34ea29ab681b665f663748245465d2d..740edfc73a8583b9e4ad9e65cc28fb5d81cd3f23 100644 (file)
@@ -71,6 +71,7 @@
 #include <libmemcached/flush_buffers.h>
 #include <libmemcached/get.h>
 #include <libmemcached/hash.h>
+#include <libmemcached/namespace.h>
 #include <libmemcached/options.h>
 #include <libmemcached/parse.h>
 #include <libmemcached/quit.h>
index 58fff4df7fcc0401f8b2c738bf32d51cf96cb5cb..8c5ca934c9055fda7b1539d927256697f1a53ac9 100644 (file)
@@ -98,6 +98,32 @@ public:
     return memcached_strerror(NULL, rc);
   }
 
+  bool error(std::string& error_message) const
+  {
+    if (memcached_failed(memcached_last_error(memc)))
+    {
+      error_message+= memcached_last_error_message(memc);
+      return true;
+    }
+
+    return false;
+  }
+
+  bool error() const
+  {
+    if (memcached_failed(memcached_last_error(memc)))
+    {
+      return true;
+    }
+
+    return false;
+  }
+
+  bool error(memcached_return_t& arg) const
+  {
+    arg= memcached_last_error(memc);
+    return memcached_failed(arg);
+  }
 
   bool setBehavior(memcached_behavior_t flag, uint64_t data)
   {
@@ -330,7 +356,7 @@ public:
                                          key.c_str(), key.length(),
                                          &value[0], value.size(),
                                          expiration, flags);
-    return (rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
+    return memcached_success(rc);
   }
 
   /**
index 5e7307ae7cdcdbd50fc2fdfd4ab8f6326da2407d..2cceff22f2618468b30d4b1456be8c50fb712d91 100644 (file)
@@ -34,8 +34,6 @@
  *
  */
 
-#include "config.h"
-
 #include <libmemcached/protocol/common.h>
 #include <libmemcached/byteorder.h>
 
index c7c8a6135b2d400eb06c5b8991c337e6afc3cd72..52904df4a7ff3e70fbc8268b908bcb76d6e7b4d9 100644 (file)
@@ -1,3 +1,39 @@
+/*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ * 
+ *  Libmemcached library
+ *
+ *  Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are
+ *  met:
+ *
+ *      * Redistributions of source code must retain the above copyright
+ *  notice, this list of conditions and the following disclaimer.
+ *
+ *      * Redistributions in binary form must reproduce the above
+ *  copyright notice, this list of conditions and the following disclaimer
+ *  in the documentation and/or other materials provided with the
+ *  distribution.
+ *
+ *      * The names of its contributors may not be used to endorse or
+ *  promote products derived from this software without specific prior
+ *  written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
 /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
 #include <stdlib.h>
 #include <string.h>
index ac16099ea10a4755425d40c5f49d303a0284276b..f275b39adf5471f31c14a0197e3d370c0857db75 100644 (file)
@@ -1,5 +1,41 @@
+/*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ * 
+ *  Libmemcached library
+ *
+ *  Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are
+ *  met:
+ *
+ *      * Redistributions of source code must retain the above copyright
+ *  notice, this list of conditions and the following disclaimer.
+ *
+ *      * Redistributions in binary form must reproduce the above
+ *  copyright notice, this list of conditions and the following disclaimer
+ *  in the documentation and/or other materials provided with the
+ *  distribution.
+ *
+ *      * The names of its contributors may not be used to endorse or
+ *  promote products derived from this software without specific prior
+ *  written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
 /* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */
-#include "libmemcached/protocol/common.h"
+#include <libmemcached/protocol/common.h>
 
 #include <sys/types.h>
 #include <inttypes.h>
index fcab1419f7c100083a232b0c405cb0ccf65da806..99b4ff2f965b09c9e9f44f89d5cb97b115b4ecf6 100644 (file)
@@ -1,5 +1,41 @@
+/*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ * 
+ *  Libmemcached library
+ *
+ *  Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are
+ *  met:
+ *
+ *      * Redistributions of source code must retain the above copyright
+ *  notice, this list of conditions and the following disclaimer.
+ *
+ *      * Redistributions in binary form must reproduce the above
+ *  copyright notice, this list of conditions and the following disclaimer
+ *  in the documentation and/or other materials provided with the
+ *  distribution.
+ *
+ *      * The names of its contributors may not be used to endorse or
+ *  promote products derived from this software without specific prior
+ *  written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
 /* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */
-#include "libmemcached/protocol/common.h"
+#include <libmemcached/protocol/common.h>
 
 #include <stdlib.h>
 #include <sys/types.h>
index 05ceb0f211f603dee62a1cf93d51c206de3a3be4..d4d8b33b25c751711e3118d14f86115dcefa7d9d 100644 (file)
@@ -462,21 +462,25 @@ static memcached_return_t ascii_stats_fetch(memcached_stat_st *memc_stat,
 
 memcached_stat_st *memcached_stat(memcached_st *self, char *args, memcached_return_t *error)
 {
+  memcached_return_t unused;
+  if (error == NULL)
+  {
+    error= &unused;
+  }
+
   memcached_return_t rc;
   if (memcached_failed(rc= initialize_query(self)))
   {
-    if (error)
-      *error= rc;
+    *error= rc;
 
     return NULL;
   }
 
   WATCHPOINT_ASSERT(error);
 
-  unlikely (self->flags.use_udp)
+  if (self->flags.use_udp)
   {
-    if (error)
-      *error= MEMCACHED_NOT_SUPPORTED;
+    *error= memcached_set_error(*self, MEMCACHED_NOT_SUPPORTED, MEMCACHED_AT);
 
     return NULL;
   }
@@ -485,8 +489,7 @@ memcached_stat_st *memcached_stat(memcached_st *self, char *args, memcached_retu
 
   if (not stats)
   {
-    if (error)
-      *error= MEMCACHED_MEMORY_ALLOCATION_FAILURE;
+    *error= MEMCACHED_MEMORY_ALLOCATION_FAILURE;
 
     return NULL;
   }
@@ -521,8 +524,7 @@ memcached_stat_st *memcached_stat(memcached_st *self, char *args, memcached_retu
     }
   }
 
-  if (error)
-    *error= rc;
+  *error= rc;
 
   return stats;
 }
index 0fc6e234df7d162be7a2646ec4f7629c050f65ce..d9b5986df04cbb54aca3e89e842a8a83fee2b777 100644 (file)
@@ -355,8 +355,6 @@ static inline memcached_return_t memcached_send(memcached_st *ptr,
                                                 uint64_t cas,
                                                 memcached_storage_action_t verb)
 {
-  WATCHPOINT_ASSERT(!(value == NULL && value_length > 0));
-
   memcached_return_t rc;
   if (memcached_failed(rc= initialize_query(ptr)))
   {
index 5693b04db2a294f344c81e9b25ed691f4e74e845..64d2b860355e217dc53ec59dcccea160c6654e2f 100644 (file)
@@ -42,7 +42,7 @@
 #include <config.h>
 #include <libtest/test.hpp>
 
-#include <libmemcached/common.h>
+#include <libmemcached/memcached.h>
 #include <libmemcached/is.h>
 #include <libmemcached/util.h>
 
index a53db785d1bdb8913fec75ad1fa5e849849a0f2f..4c81cadfa81bb9f11b8ae2d672c72725080d69d0 100644 (file)
@@ -15,7 +15,9 @@
 
 using namespace libtest;
 
-#include <libmemcached/common.h>
+#include <libmemcached/memcached.h>
+#include <libmemcached/server_instance.h>
+#include <libmemcached/io.h>
 
 #include <assert.h>
 #include <stdio.h>
index 2becbd925a49c36efc05a702ff7347a926e8c0c3..45ffd2d0e6554185fb41f0490ef2e199e0dfacff 100644 (file)
@@ -46,9 +46,7 @@ using namespace libtest;
 #include <cerrno>
 #include <cassert>
 
-#define BUILDING_LIBMEMCACHED
-// !NEVER use common.h, always use memcached.h in your own apps
-#include <libmemcached/common.h>
+#include <libmemcached/memcached.h>
 #include <libmemcached/util.h>
 
 #include <tests/parser.h>
index 3bc85bc1a8632526e08e77ea873bd419afbec377..aad1abf1f3060aee78253ebf5b8885a9d498d172 100644 (file)
@@ -59,18 +59,6 @@ using namespace std;
 using namespace memcache;
 using namespace libtest;
 
-extern "C" {
-   test_return_t basic_test(memcached_st *memc);
-   test_return_t increment_test(memcached_st *memc);
-   test_return_t basic_master_key_test(memcached_st *memc);
-   test_return_t mget_result_function(memcached_st *memc);
-   test_return_t basic_behavior(memcached_st *memc);
-   test_return_t mget_test(memcached_st *memc);
-   memcached_return_t callback_counter(const memcached_st *,
-                                       memcached_result_st *,
-                                       void *context);
-}
-
 static void populate_vector(vector<char> &vec, const string &str)
 {
   vec.reserve(str.length());
@@ -86,7 +74,7 @@ static void copy_vec_to_string(vector<char> &vec, string &str)
   }
 }
 
-test_return_t basic_test(memcached_st *memc)
+static test_return_t basic_test(memcached_st *memc)
 {
   Memcache foo(memc);
   const string value_set("This is some data");
@@ -104,7 +92,7 @@ test_return_t basic_test(memcached_st *memc)
   return TEST_SUCCESS;
 }
 
-test_return_t increment_test(memcached_st *original)
+static test_return_t increment_test(memcached_st *original)
 {
   Memcache mcach(original);
   const string key("blah");
@@ -139,7 +127,7 @@ test_return_t increment_test(memcached_st *original)
   return TEST_SUCCESS;
 }
 
-test_return_t basic_master_key_test(memcached_st *original)
+static test_return_t basic_master_key_test(memcached_st *original)
 {
   Memcache foo(original);
   const string value_set("Data for server A");
@@ -167,19 +155,7 @@ test_return_t basic_master_key_test(memcached_st *original)
   return TEST_SUCCESS;
 }
 
-/* Count the results */
-memcached_return_t callback_counter(const memcached_st *,
-                                    memcached_result_st *,
-                                    void *context)
-{
-  unsigned int *counter= static_cast<unsigned int *>(context);
-
-  *counter= *counter +1;
-
-  return MEMCACHED_SUCCESS;
-}
-
-test_return_t mget_test(memcached_st *original)
+static test_return_t mget_test(memcached_st *original)
 {
   Memcache memc(original);
   memcached_return_t mc_rc;
@@ -226,7 +202,7 @@ test_return_t mget_test(memcached_st *original)
   return TEST_SUCCESS;
 }
 
-test_return_t basic_behavior(memcached_st *original)
+static test_return_t basic_behavior(memcached_st *original)
 {
   Memcache memc(original);
   uint64_t value= 1;
@@ -237,6 +213,57 @@ test_return_t basic_behavior(memcached_st *original)
   return TEST_SUCCESS;
 }
 
+static test_return_t error_test(memcached_st *)
+{
+  Memcache memc("--server=localhost:0");
+  std::vector<char> value;
+
+  test_false(memc.set("key", value, time_t(0), uint32_t(0)));
+
+  test_true(memc.error());
+
+  return TEST_SUCCESS;
+}
+
+static test_return_t error_std_string_test(memcached_st *)
+{
+  Memcache memc("--server=localhost:0");
+  std::vector<char> value;
+
+  test_false(memc.set("key", value, time_t(0), uint32_t(0)));
+
+  std::string error_message;
+  test_true(memc.error(error_message));
+  test_false(error_message.empty());
+
+  return TEST_SUCCESS;
+}
+
+static test_return_t error_memcached_return_t_test(memcached_st *)
+{
+  Memcache memc("--server=localhost:0");
+  std::vector<char> value;
+
+  test_false(memc.set("key", value, time_t(0), uint32_t(0)));
+
+  memcached_return_t rc;
+  test_true(memc.error(rc));
+  test_compare(MEMCACHED_CONNECTION_FAILURE, rc);
+
+  return TEST_SUCCESS;
+}
+
+#ifndef __INTEL_COMPILER
+#pragma GCC diagnostic ignored "-fpermissive"
+#endif
+
+test_st error_tests[] ={
+  { "error()", 0, error_test },
+  { "error(std::string&)", 0, error_std_string_test },
+  { "error(memcached_return_t&)", 0, error_memcached_return_t_test },
+  {0, 0, 0}
+};
+
 test_st tests[] ={
   { "basic", 0,
     reinterpret_cast<test_callback_fn*>(basic_test) },
@@ -253,6 +280,7 @@ test_st tests[] ={
 
 collection_st collection[] ={
   {"block", 0, 0, tests},
+  {"error()", 0, 0, error_tests},
   {0, 0, 0, 0}
 };
 
index 033b43229181d520ef68c93a6e9c30a43abd22e5..94f0eba0b692a73896cfaca7deac3d39a0545db5 100644 (file)
@@ -40,7 +40,8 @@
 
 using namespace libtest;
 
-#include <libmemcached/common.h>
+#include <libmemcached/memcached.h>
+#include <libmemcached/server_instance.h>
 #include <tests/replication.h>
 #include <tests/debug.h>