clients/memerror
clients/memflush
clients/memparse
+clients/memping
clients/memrm
clients/memslap
clients/memstat
libmemcached/memcached_configure.h
libtest/.hg/
libtest/.hgignore
+libtest/skiptest
libtest/unittest
+libtest/version.h
libtest/wait
libtool
libtool.m4
support/libmemcached.spec
tags
tests/atomsmasher
+tests/c_sasl_test
tests/c_test
tests/cycle
tests/hash_plus
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
* 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>
memcached_return_t initialize_query(memcached_st *self)
{
if (not self)
+ {
return MEMCACHED_INVALID_ARGUMENTS;
+ }
self->query_id++;
memcached_return_t initialize_const_query(const memcached_st *self)
{
if (not self)
+ {
return MEMCACHED_INVALID_ARGUMENTS;
+ }
if (memcached_server_count(self) == 0)
{
#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>
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)
{
key.c_str(), key.length(),
&value[0], value.size(),
expiration, flags);
- return (rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
+ return memcached_success(rc);
}
/**
*
*/
-#include "config.h"
-
#include <libmemcached/protocol/common.h>
#include <libmemcached/byteorder.h>
+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ *
+ * Libmemcached library
+ *
+ * Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * * The names of its contributors may not be used to endorse or
+ * promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
#include <stdlib.h>
#include <string.h>
+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ *
+ * Libmemcached library
+ *
+ * Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * * The names of its contributors may not be used to endorse or
+ * promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
/* -*- 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>
+/* 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>
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;
}
if (not stats)
{
- if (error)
- *error= MEMCACHED_MEMORY_ALLOCATION_FAILURE;
+ *error= MEMCACHED_MEMORY_ALLOCATION_FAILURE;
return NULL;
}
}
}
- if (error)
- *error= rc;
+ *error= rc;
return stats;
}
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)))
{
#include <config.h>
#include <libtest/test.hpp>
-#include <libmemcached/common.h>
+#include <libmemcached/memcached.h>
#include <libmemcached/is.h>
#include <libmemcached/util.h>
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>
#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>
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());
}
}
-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");
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");
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");
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;
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;
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) },
collection_st collection[] ={
{"block", 0, 0, tests},
+ {"error()", 0, 0, error_tests},
{0, 0, 0, 0}
};
using namespace libtest;
-#include <libmemcached/common.h>
+#include <libmemcached/memcached.h>
+#include <libmemcached/server_instance.h>
#include <tests/replication.h>
#include <tests/debug.h>