jenkins-promote-staging-trunk-libmemcached-1
authorContinuous Integration <ci@tangent.org>
Tue, 13 Mar 2012 23:56:59 +0000 (16:56 -0700)
committerContinuous Integration <ci@tangent.org>
Tue, 13 Mar 2012 23:56:59 +0000 (16:56 -0700)
171 files changed:
.bzrignore
clients/memcat.cc
clients/memcp.cc
clients/memrm.cc
config/autorun.sh
configure.ac
docs/bin/memaslap.rst
docs/bin/memstat.rst
docs/client_errors/MEMCACHED_AUTH_CONTINUE.rst
docs/client_errors/MEMCACHED_AUTH_FAILURE.rst
docs/client_errors/MEMCACHED_AUTH_PROBLEM.rst
docs/client_errors/MEMCACHED_BAD_KEY_PROVIDED.rst
docs/client_errors/MEMCACHED_BUFFERED.rst
docs/client_errors/MEMCACHED_CLIENT_ERROR.rst
docs/client_errors/MEMCACHED_CONNECTION_BIND_FAILURE.rst
docs/client_errors/MEMCACHED_CONNECTION_FAILURE.rst
docs/client_errors/MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE.rst
docs/client_errors/MEMCACHED_DATA_DOES_NOT_EXIST.rst
docs/client_errors/MEMCACHED_DATA_EXISTS.rst
docs/client_errors/MEMCACHED_DELETED.rst
docs/client_errors/MEMCACHED_DEPRECATED.rst
docs/client_errors/MEMCACHED_E2BIG.rst
docs/client_errors/MEMCACHED_END.rst
docs/client_errors/MEMCACHED_ERRNO.rst
docs/client_errors/MEMCACHED_FAILURE.rst
docs/client_errors/MEMCACHED_FAIL_UNIX_SOCKET.rst
docs/client_errors/MEMCACHED_FETCH_NOTFINISHED.rst
docs/client_errors/MEMCACHED_HOST_LOOKUP_FAILURE.rst
docs/client_errors/MEMCACHED_INVALID_ARGUMENTS.rst
docs/client_errors/MEMCACHED_INVALID_HOST_PROTOCOL.rst
docs/client_errors/MEMCACHED_ITEM.rst
docs/client_errors/MEMCACHED_KEY_TOO_BIG.rst
docs/client_errors/MEMCACHED_MAXIMUM_RETURN.rst
docs/client_errors/MEMCACHED_MEMORY_ALLOCATION_FAILURE.rst
docs/client_errors/MEMCACHED_NOTFOUND.rst
docs/client_errors/MEMCACHED_NOTSTORED.rst
docs/client_errors/MEMCACHED_NOT_SUPPORTED.rst
docs/client_errors/MEMCACHED_NO_KEY_PROVIDED.rst
docs/client_errors/MEMCACHED_NO_SERVERS.rst
docs/client_errors/MEMCACHED_PARSE_ERROR.rst
docs/client_errors/MEMCACHED_PARSE_USER_ERROR.rst
docs/client_errors/MEMCACHED_PARTIAL_READ.rst
docs/client_errors/MEMCACHED_PROTOCOL_ERROR.rst
docs/client_errors/MEMCACHED_READ_FAILURE.rst
docs/client_errors/MEMCACHED_SERVER_ERROR.rst
docs/client_errors/MEMCACHED_SERVER_MARKED_DEAD.rst
docs/client_errors/MEMCACHED_SOME_ERRORS.rst
docs/client_errors/MEMCACHED_STAT.rst
docs/client_errors/MEMCACHED_STORED.rst
docs/client_errors/MEMCACHED_SUCCESS.rst
docs/client_errors/MEMCACHED_TIMEOUT.rst
docs/client_errors/MEMCACHED_UNKNOWN_READ_FAILURE.rst
docs/client_errors/MEMCACHED_UNKNOWN_STAT_KEY.rst
docs/client_errors/MEMCACHED_VALUE.rst
docs/client_errors/MEMCACHED_WRITE_FAILURE.rst
docs/hashkit_create.rst
docs/hashkit_functions.rst
docs/hashkit_value.rst
docs/index.rst
docs/libmemcached-1.0/memcached_touch.rst
docs/libmemcached.rst
docs/libmemcached/defaults.rst [new file with mode: 0644]
docs/libmemcached/memcached_fetch.rst
docs/libmemcached/memcached_last_error_message.rst
docs/libmemcached/memcached_return_t.rst
docs/libmemcached_examples.rst
docs/libmemcachedutil.rst
docs/memcached_analyze.rst
docs/memcached_append.rst
docs/memcached_auto.rst
docs/memcached_behavior.rst
docs/memcached_callback.rst
docs/memcached_cas.rst
docs/memcached_create.rst
docs/memcached_delete.rst
docs/memcached_dump.rst
docs/memcached_flush.rst
docs/memcached_flush_buffers.rst
docs/memcached_generate_hash_value.rst
docs/memcached_get.rst
docs/memcached_memory_allocators.rst
docs/memcached_pool.rst
docs/memcached_quit.rst
docs/memcached_result_st.rst
docs/memcached_sasl.rst
docs/memcached_server_st.rst
docs/memcached_servers.rst
docs/memcached_set.rst
docs/memcached_stats.rst
docs/memcached_strerror.rst
docs/memcached_user_data.rst
docs/memcached_verbosity.rst
docs/memcached_version.rst
docs/types.rst [new file with mode: 0644]
docs/versioning.rst
example/include.am
example/interface_v0.c [deleted file]
example/interface_v0.cc [new file with mode: 0644]
example/interface_v1.c [deleted file]
example/interface_v1.cc [new file with mode: 0644]
example/memcached_light.c [deleted file]
example/memcached_light.cc [new file with mode: 0644]
example/memcached_light.h
example/storage.c [deleted file]
example/storage.cc [new file with mode: 0644]
example/t/include.am [new file with mode: 0644]
example/t/memcached_light.cc [new file with mode: 0644]
libmemcached/include.am
libmemcached/socket.hpp
libmemcachedprotocol-0.0/callback.h
libmemcachedprotocol-0.0/handler.h
libmemcachedprotocol/ascii_handler.c
libmemcachedprotocol/binary_handler.c
libmemcachedprotocol/common.h
libmemcachedprotocol/handler.c
libtest/abort.cc [new file with mode: 0644]
libtest/blobslap_worker.cc
libtest/cmdline.cc
libtest/cmdline.h
libtest/cpu.cc [new file with mode: 0644]
libtest/cpu.hpp [new file with mode: 0644]
libtest/error.h
libtest/fatal.hpp
libtest/gearmand.cc
libtest/include.am
libtest/memcached.cc
libtest/memcached.h
libtest/run.gdb
libtest/server.cc
libtest/server.h
libtest/server_container.cc
libtest/strerror.cc
libtest/test.cc
libtest/test.hpp
libtest/tmpfile.cc [new file with mode: 0644]
libtest/tmpfile.hpp [new file with mode: 0644]
libtest/unittest.cc
m4/ax_check_library.m4
m4/ax_sasl.m4
m4/pandora_warnings.m4
tests/cli.am
tests/hashkit_functions.cc
tests/include.am
tests/libmemcached-1.0/all_tests.cc
tests/libmemcached-1.0/all_tests.h
tests/libmemcached-1.0/callbacks.cc
tests/libmemcached-1.0/deprecated.cc
tests/libmemcached-1.0/include.am
tests/libmemcached-1.0/mem_functions.cc
tests/libmemcached-1.0/mem_functions.h
tests/libmemcached-1.0/memcached_get.cc [new file with mode: 0644]
tests/libmemcached-1.0/memcached_get.h [new file with mode: 0644]
tests/libmemcached-1.0/parser.cc
tests/libmemcached-1.0/pool.cc
tests/libmemcached-1.0/setup_and_teardowns.cc
tests/libmemcached-1.0/setup_and_teardowns.h
tests/libmemcached_world.h
tests/libmemcached_world_socket.h
tests/mem_udp.cc
tests/memcapable.cc
tests/memcat.cc
tests/memcp.cc
tests/memdump.cc
tests/memerror.cc
tests/memexist.cc
tests/memflush.cc
tests/memrm.cc
tests/memstat.cc
tests/memtouch.cc
util/include.am
util/log.hpp [new file with mode: 0644]

index 0ffd2ab565a7d54385ea416a8d3ec44cba152938..a2a8ce45aebe001a5aa5945ff4388148de68738f 100644 (file)
@@ -142,3 +142,5 @@ tests/var/
 tmp_chroot
 unittests/unittests
 tests/libmemcached-1.0/testsocket
+example/t/memcached_light
+libtest/abort
index 86ae279c8c671997ef8dbe0ddc19e1df7d6669c0..c93f1a21d7812fe63824e2879d0d283356fe7725 100644 (file)
@@ -184,7 +184,6 @@ int main(int argc, char *argv[])
 void options_parse(int argc, char *argv[])
 {
   int option_index= 0;
-  int option_rv;
 
   memcached_programs_help_st help_options[]=
   {
@@ -210,7 +209,7 @@ void options_parse(int argc, char *argv[])
 
   while (1)
   {
-    option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);
+    int option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);
     if (option_rv == -1) break;
     switch (option_rv)
     {
index 5422aa7386cbbe7a4b9f36a1bc31ba2a37647b5f..59bd7478bb780a89d447d9c8949b1381c7342baa 100644 (file)
@@ -245,7 +245,7 @@ int main(int argc, char *argv[])
 
     if (memcached_failed(rc))
     {
-      std::cerr << "Error occrrured during operation: " << memcached_last_error_message(memc) << std::endl;
+      std::cerr << "Error occrrured during memcached_set(): " << memcached_last_error_message(memc) << std::endl;
       exit_code= EXIT_FAILURE;
     }
 
@@ -254,6 +254,11 @@ int main(int argc, char *argv[])
     optind++;
   }
 
+  if (opt_verbose)
+  {
+    std::cout << "Calling memcached_free()" << std::endl;
+  }
+
   memcached_free(memc);
 
   if (opt_servers)
index cbfcd2418e64a577a9096e7a0991fc8edb02cf23..61697cd109f9cd81ffc32afd5e2e79a2be4ce60c 100644 (file)
@@ -97,7 +97,7 @@ int main(int argc, char *argv[])
         std::cerr << "Could not find key \"" << argv[optind] << "\"" << std::endl;
       }
     }
-    else if (memcached_failed(rc))
+    else if (memcached_fatal(rc))
     {
       if (opt_verbose)
       {
index 62ad34d1d6aa68be6ed4cfb4097680c277a3fd04..c7e87ed1b8c8611cb7fe244d775a1b264167445f 100755 (executable)
 #  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
+die() { echo "$@"; exit 1; }
+
+run() {
+       echo "$ARGV0: running \`$@' $ARGS"
+       $@ $ARGS
+}
+
+# Try to locate a program by using which, and verify that the file is an
+# executable
+locate_binary() {
+  for f in $@
+  do
+    file=`which $f 2>/dev/null | grep -v '^no '`
+    if test -n "$file" -a -x "$file"; then
+      echo $file
+      return 0
+    fi
+  done
+
+  echo "" 
+  return 1
+}
+
+
+AUTORECONF_FLAGS=" --install --force --verbose -Wall"
+
+if test -f config/pre_hook.sh
+then
+  . config/pre_hook.sh
+fi
+
+if test x$AUTORECONF = x; then
+  AUTORECONF=`locate_binary autoreconf`
+  if test x$AUTORECONF = x; then
+    die "Did not find a supported autoconf"
+  fi
+fi
+
+run $AUTORECONF $AUTORECONF_FLAGS || die "Can't execute autoreconf"
index 8bb9a60a37199fb22dcad18e9b6e1e7f1693fd32..1fe4f7749b29d97cf7e9431a54390fd91c8111be 100644 (file)
@@ -132,6 +132,8 @@ AC_CHECK_HEADERS([cxxabi.h],
                  AC_DEFINE([HAVE_CXXABI_H], [1], [Have cxxabi.h]),
                  AC_DEFINE([HAVE_CXXABI_H], [0], [Have cxxabi.h]))
 
+AC_CHECK_HEADERS([sys/sysctl.h])
+
 AX_COMPILER_VENDOR
 
 AC_FUNC_ALLOCA
@@ -209,6 +211,9 @@ AC_DEFINE([GEARMAND_BLOBSLAP_WORKER], [0], [Support for Gearman Blobslap worker]
 AC_DEFINE([HAVE_LIBPQ], [0], [Support for Postgres])
 AC_DEFINE([HAVE_LIBCURL], [0], [Support for libcurl])
 
+AC_DEFINE([HAVE_MEMCACHED_LIGHT_BINARY], [1], [Support for memcached_light])
+AC_DEFINE([MEMCACHED_LIGHT_BINARY], ["example/memcached_light"], [Support for memcached_light])
+
 AC_CHECK_HEADERS_ONCE(winsock2.h poll.h sys/wait.h fnmatch.h)
 AM_CONDITIONAL(BUILD_POLL, test "x$ac_cv_header_poll_h" = "xno")
 AM_CONDITIONAL(BUILD_WIN32_WRAPPERS, test "x$ac_cv_header_winsock2_h" = "xyes")
index fa73b51f74fb4ca5bb5e7ab1dc2df3d0afe8bd2e..610606754b2d7b0c441f4d4e2468d1601434fda8 100644 (file)
@@ -13,6 +13,8 @@ memaslap [options]
 
 .. option:: --help
 
+.. envvar:: MEMCACHED_SERVERS
+
 -----------
 DESCRIPTION
 -----------
@@ -31,7 +33,7 @@ the threads don't communicate with each other, and there are several socket
 connections in each thread. Each connection keeps key size distribution,
 value size distribution, and command distribution by itself.
 
-You can specify servers via the :option:`--servers` option or via the
+You can specify servers via the :option:`memslap --servers` option or via the
 environment variable :envvar:`MEMCACHED_SERVERS`.
 
 
index 3bbec8f8e2b6ec28dd5fe2f1b839a1f0a06c19dd..9b60297d554dc5beef4efb503acd6dc0d86e6a19 100644 (file)
@@ -42,6 +42,7 @@ For a full list of operations run the tool with:
 
 .. option:: --help
 
+.. option:: --analyze  
 
 ----
 HOME
index 8a3e6c77113cfcf2354221bfa29c19862b04ccbd..e410592cff81d22a72c37628e8df07d4394c9e02 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_AUTH_CONTINUE
 =======================
 
+.. c:type:: MEMCACHED_AUTH_CONTINUE
+
 Authentication has been paused.
index 36d5a0c9447ac59bc84b4dde81d1f07554e69953..9433eb885a757cbc21d076c50254aca4c50041e8 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_AUTH_FAILURE
 ======================
 
+.. c:type:: MEMCACHED_AUTH_FAILURE
+
 The credentials provided are not valid for this server.
index 196d6f98a59a9d39f4b01abb473607742c3edcfd..ba8f22ca3a25109d1ccb39e9569797936de33cc4 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_AUTH_PROBLEM
 ======================
 
+.. c:type:: MEMCACHED_AUTH_PROBLEM
+
 An unknown issue has occured during authentication.
index 73aa4f14d77d72d68006d65a7b406f77d68b8ef3..da1c0b8deddb1456e0d81b68ce0a086244a571c4 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_BAD_KEY_PROVIDED
 ==========================
 
+.. c:type:: MEMCACHED_BAD_KEY_PROVIDED
+
 The key provided is not a valid key.
index d93526ad8d926dff5e9aaef00c40c2d877056cc1..027d0ced575c463959d630d2873bdcb7fe04802b 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_BUFFERED
 ==================
 
+.. c:type:: MEMCACHED_BUFFERED
+
 The request has been buffered.
index 1db8286ff4cbd22ca97546715348a171d09cf3e8..d8df46835ab5f0261826ab79d847216e158c99cb 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_CLIENT_ERROR
 ======================
 
+.. c:type:: MEMCACHED_CLIENT_ERROR
+
 An unknown client error has occured internally.
index 319701cf546fb502cd210bcd3439bbeeeca8b988..221cced15fbd17477777c18e907c227cfd7c1966 100644 (file)
@@ -2,4 +2,7 @@
 MEMCACHED_CONNECTION_BIND_FAILURE
 =================================
 
+.. c:type:: MEMCACHED_CONNECTION_BIND_FAILURE
+.. deprecated:: <0.30
+
 We were not able to bind() to the socket.
index f46fa179948f3d79eb0abb39033ddc1943891401..1d2ca04e87d438b707ded5488bc37c1ae39be91c 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_CONNECTION_FAILURE
 ============================
 
+.. c:type:: MEMCACHED_CONNECTION_FAILURE
+
 A unknown error has occured while trying to connect to a server.
index 4bf2337e28725def46afce950dbb78b759dd1f7e..66fd71877ad749c8bcc3aa194f730eefedcc8fa3 100644 (file)
@@ -2,4 +2,7 @@
 MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE
 ==========================================
 
+.. c:type:: MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE
+.. deprecated:: <0.30
+
 An error has occurred while trying to connect to a server. It is likely that either the number of file descriptors need to be increased or you are out of memory.
index 13d5646a8f8a9e63e70ba74057c41a72c5c7444a..4b5c16aa946e7d4b3df68ab502dc3bc126f55f23 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_DATA_DOES_NOT_EXIST
 =============================
 
+.. c:type:: MEMCACHED_DATA_DOES_NOT_EXIST
+
 The data requested with the key given was not found.
index db0de35da82be982c94b0db3644078a4cf273382..8443cae9fc6f65c618a9112a0533da057b39efdd 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_DATA_EXISTS
 =====================
 
+.. c:type:: MEMCACHED_DATA_EXISTS
+
 The data requested with the key given was not found.
index c1e2acfe989634a697f5c23e88ad04ec5cf61ca9..b2654352f78578652c7ab323555e43ea7a0a41aa 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_DELETED
 =================
 
+.. c:type:: MEMCACHED_DELETED
+
 The object requested by the key has been deleted.
index 733b1c12f16394f671b4fd69b68f8e8a5762f2b6..13de9bcda7d191f1fa9dcf55e5a2699a91607bd3 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_DEPRECATED
 ====================
 
+.. c:type:: MEMCACHED_DEPRECATED
+
 The method that was requested has been deprecated.
index 16c7b9c626c365abc3d449694f16ac71d05f0cf2..fdd04958c859448dd972f1ee4a3ee8ab31c5191b 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_E2BIG
 ===============
 
+.. c:type:: MEMCACHED_E2BIG
+
 Item is too large for the server to store.
index 39ad854226e0443f71096ac9eef0d62575ee2e28..4372448d73283f691cb609dd207641a887ce82ff 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_END
 =============
 
+.. c:type:: MEMCACHED_END
+
 The server has completed returning all of the objects requested.
index 343f37d4c40d4b25d10271d7ec01292e90c17f9c..6064034312b38071412fcd8f5bf62a73fad8d209 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_ERRNO
 ===============
 
+.. c:type:: MEMCACHED_ERRNO
+
 An error has occurred in the driver which has set errno.
index 66c7508329b735967a5f7580b19529196bac088d..9da69fce54de3e9e452cc4a1a29edeaf4efea2ad 100644 (file)
@@ -2,4 +2,7 @@
 MEMCACHED_FAILURE
 =================
 
+.. c:type:: MEMCACHED_FAILURE
+.. deprecated:: <0.30
+
 A unknown failure has occurred in the server.
index d07817111c1244a34856868e5df546d1f3430056..b44fb26126d31114c711678bb07c9ce08114040d 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_FAIL_UNIX_SOCKET
 ==========================
 
+.. c:type:: MEMCACHED_FAIL_UNIX_SOCKET
+
 A connection was not established with the server via a unix domain socket.
index 7e90a5a9fe3c5329debd1b4cae75460e3a84ac4c..cd01172a41dbb22324af6fae90247fae1101a13d 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_FETCH_NOTFINISHED
 ===========================
 
+.. c:type:: MEMCACHED_FETCH_NOTFINISHED
+
 A request has been made, but the server has not finished the fetch of the last request.
index cbfe70ff9b64cbe50a69096a25bac22d645c8589..2f64869c73c57730af7c63818a1349f110b0d5a4 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_HOST_LOOKUP_FAILURE
 =============================
 
+.. c:type:: MEMCACHED_HOST_LOOKUP_FAILURE
+
 A DNS failure has occurred.
index 0684dbf373093714031e21f1b4999d1d45b734b2..69032bbd49a6bf83c68c78fa1bb6f776703dfa91 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_INVALID_ARGUMENTS
 ===========================
 
+.. c:type:: MEMCACHED_INVALID_ARGUMENTS
+
 The arguments supplied to the given function were not valid.
index 181a959edea596ef2b88a6a31b5d87699f8fa387..d6c77234b91e07b45b5608152ee473d22826d407 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_INVALID_HOST_PROTOCOL
 ===============================
 
+.. c:type:: MEMCACHED_INVALID_HOST_PROTOCOL
+
 The server you are connecting too has an invalid protocol. Most likely you are connecting to an older server that does not speak the binary protocol.
index 9f19203722bf4c3f75503742ddedbe63411b4d4a..ee4da97c62259892aa2e83d93fb486e05850fda8 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_ITEM
 ==============
 
+.. c:type:: MEMCACHED_ITEM
+
 An item has been fetched (this is an internal error only).
index cbb2eeb600783444567db282118e4624fc63ca48..c3a58eaa8cc4d6f5ffbc096956d8d4c51750773c 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_KEY_TOO_BIG
 =====================
 
+.. c:type:: MEMCACHED_KEY_TOO_BIG
+
 The key that has been provided is too large for the given server.
index d980e6d6dfd024cd53cba3e17b25345c9360407a..aa7af4ffce442662d82e0e7eaeab12b682380b66 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_MAXIMUM_RETURN
 ========================
 
+.. c:type:: MEMCACHED_MAXIMUM_RETURN
+
 This in an internal only state.
index 3a3472b50dc21eeddee97f519fea0e61901f2dab..fbebfd4d9dbff692a89b36298ef7e831d0042961 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_MEMORY_ALLOCATION_FAILURE
 ===================================
 
+.. c:type:: MEMCACHED_MEMORY_ALLOCATION_FAILURE
+
 An error has occurred while trying to allocate memory.
index c1a6ac16421ab7a3288ced715ccee3cf7c1fc1c2..5525762677844f650619746e2de285690a071d9f 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_NOTFOUND
 ==================
 
+.. c:type:: MEMCACHED_NOTFOUND
+
 The object requested was not found.
index 61ea12b4862ba58cf1c29aad3784f7e91e09778a..f10651af57911cd312ed909fb37b82b15b060223 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_NOTSTORED
 ===================
 
+.. c:type:: MEMCACHED_NOTSTORED
+
 The request to store an object failed.
index f8befa0e260b3e00690ea3b9458c95cbcab7d5c2..5b10b38d4ed37ecb477ae84622160d156168491d 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_NOT_SUPPORTED
 =======================
 
+.. c:type:: MEMCACHED_NOT_SUPPORTED
+
 The given method is not supported in the server.
index 73cc54d54807f95a5fc76e04fc986c6f87b4c58d..39c78de5319cec1d3a9f9ca9f29ef72b3e2c4a36 100644 (file)
@@ -2,4 +2,8 @@
 MEMCACHED_NO_KEY_PROVIDED
 =========================
 
+.. c:type:: MEMCACHED_NO_KEY_PROVIDED
+.. deprecated:: <0.30
+   Use :c:type:`MEMCACHED_BAD_KEY_PROVIDED` instead.
+
 No key was provided.
index 5e61425baa4a7f5a349e708658b70b2e0eb3bb0c..fec92151a026966d88d04e46adb70942cb5777ba 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_NO_SERVERS
 ====================
 
+.. c:type:: MEMCACHED_NO_SERVERS
+
 No servers have been added to the memcached_st object.
index a9c298e6e5900fd0d34889ac0ab1c2fb52a1920f..173073b9e352da6185e9fea30e6e0dd510178364 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_PARSE_ERROR
 =====================
 
+.. c:type:: MEMCACHED_PARSE_ERROR
+
 An error has occurred while trying to parse the configuration string. You should use memparse to determine what the error was.
index 035e57ba6ad3af1d342980223aa39f9483eddbe4..9e3a6292e0c012eb8227b76c5f86df93aff109e9 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_PARSE_USER_ERROR
 ==========================
 
+.. c:type:: MEMCACHED_PARSE_USER_ERROR
+
 An error has occurred  in parsing the configuration string.
index 7d389981ba6d688c10820c051d8c3f08680a9312..78c51e0280a7f408ff446750066955f174fe4d84 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_PARTIAL_READ
 ======================
 
+.. c:type:: MEMCACHED_PARTIAL_READ
+
 The read was only partcially successful.
index add6e902178905f0259d94ae8bf83626efaa5c5c..0899cb3e8dd55f0a8037b3fe074af5d13536581f 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_PROTOCOL_ERROR
 ========================
 
+.. c:type:: MEMCACHED_PROTOCOL_ERROR
+
 An unknown error has occurred in the protocol.
index 0da58b51f4ae36819b204245ee700c57bda7d452..d929de167eaa12336015cdb28768452ed7b5f909 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_READ_FAILURE
 ======================
 
+.. c:type:: MEMCACHED_READ_FAILURE
+
 A read failure has occurred.
index 78036443325ef7988a98319330b904e2e5200291..2cc3164b17bb78bbd7f8781783058a7ec1262720 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_SERVER_ERROR
 ======================
 
+.. c:type:: MEMCACHED_SERVER_ERROR
+
 An unknown error has occurred in the server.
index 25c21ef9b5d44b78d9c5e3c6a991ab18ca994bdd..2c0e915754ca61fe447686161bdf1249796937e9 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_SERVER_MARKED_DEAD
 ============================
 
+.. c:type:: MEMCACHED_SERVER_MARKED_DEAD
+
 The requested server has been marked dead.
index 6666c3d180ea461bb950b187eeafe31262900b74..1217da8ec39f38ed100d38e16b383620f2b242c5 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_SOME_ERRORS
 =====================
 
+.. c:type:: MEMCACHED_SOME_ERRORS
+
 A multi request has been made, and some underterminate number of errors have occurred.
index 39f8109cd92766b904a56081231eb3a902e66dc2..8b1da4e3d7a347a1817daed4bae40e2a374a6662 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_STAT
 ==============
 
+.. c:type:: MEMCACHED_STAT
+
 A "stat" command has been returned in the protocol.
index daebc625022403075d15fd4bf2678ad441dc74eb..9bcc5bf351fa7ee9a41980678b208f9f10c6cbb2 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_STORED
 ================
 
+.. c:type:: MEMCACHED_STORED
+
 The requested object has been successfully stored on the server.
index f4e398c2bf97bc47b7244e2b666b4a85b8a992ac..633a7087eaabecf0ffa00d317536225f86d6003e 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_SUCCESS
 =================
 
+.. c:type:: MEMCACHED_SUCCESS
+
 The request was successfully executed.
index 27479a7fd30b31391f762cca9475f6a4c2a487f8..ea39b3a0315c3bba506db537e8f21aa3e90a5dcd 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_TIMEOUT
 =================
 
+.. c:type:: MEMCACHED_TIMEOUT
+
 Operation has timed out.
index 2056c4d6fc7b608ed0566f1b78dac9b54432bc79..06e168d9046410a1c332ced24eb5d97114975467 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_UNKNOWN_READ_FAILURE
 ==============================
 
+.. c:type:: MEMCACHED_UNKNOWN_READ_FAILURE
+
 An unknown read failure only occurs when either there is a bug in the server, or in rare cases where an ethernet nic is reporting dubious information.
index 0fe362e00f76e0bdd45db049b235658cd9023863..03ef4157bbcc6032c018fdbb1542a8e1fcc770af 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_UNKNOWN_STAT_KEY
 ==========================
 
+.. c:type:: MEMCACHED_UNKNOWN_STAT_KEY
+
 The server you are communicating with has a stat key which has not be defined in the protocol.
index 3eae4a18f99c2a8254458f3a324d470f2a327c86..b26fcfb85d52581a2532fb6553843aeb3465a0d7 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_VALUE
 ===============
 
+.. c:type:: MEMCACHED_VALUE
+
 A value has been returned from the server (this is an internal condition only).
index 72388ff9187181de87d111da621af929efaae323..ca3ba45c77bd136138d9cf3899d17e0d4c62bbbc 100644 (file)
@@ -2,4 +2,6 @@
 MEMCACHED_WRITE_FAILURE
 =======================
 
+.. c:type:: MEMCACHED_WRITE_FAILURE
+
 An error has occured while trying to write to a server.
index bf96da751716277eeed2b283336bf181393468cd..a46729a9729cd38f7eb372a4ee1f96c475df9800 100644 (file)
@@ -2,6 +2,8 @@
 Creating a hashkit structure
 ============================
 
+.. highlightlang:: c
+
 .. index:: object: hashkit_st
 
 --------
@@ -12,13 +14,13 @@ SYNOPSIS
  
 .. c:type:: hashkit_st
 
-.. c:function:: hashkit_st *hashkit_create(hashkit_st *hash);
+.. c:function:: hashkit_st *hashkit_create(hashkit_st *hash)
  
-.. c:function:: hashkit_st *hashkit_clone(hashkit_st *destination, const hashkit_st *ptr);
+.. c:function:: hashkit_st *hashkit_clone(hashkit_st *destination, const hashkit_st *ptr)
 
-.. c:function:: void hashkit_free(hashkit_st *hash);
+.. c:function:: void hashkit_free(hashkit_st *hash)
 
-.. c:function:: bool hashkit_is_allocated(const hashkit_st *hash);
+.. c:function:: bool hashkit_is_allocated(const hashkit_st *hash)
 
 Compile and link with -lhashkit
 
@@ -27,19 +29,19 @@ DESCRIPTION
 -----------
 
 
-The :c:func:`hashkit_create()` function initializes a hashkit object for use. If
+The :c:func:`hashkit_create` function initializes a hashkit object for use. If
 you pass a NULL argument for hash, then the memory for the object is
 allocated. If you specify a pre-allocated piece of memory, that is
 initialized for use.
 
-The :c:func:`hashkit_clone()` function initializes a hashkit object much like
-:c:func:`hashkit_create()`, but instead of using default settings it will use
+The :c:func:`hashkit_clone` function initializes a hashkit object much like
+:c:func:`hashkit_create`, but instead of using default settings it will use
 the settings of the ptr hashkit object.
 
-The :c:func:`hashkit_free()` frees any resources being consumed by the hashkit
-objects that were initialized with :c:func:`hashkit_create()` or :c:func:`hashkit_clone()`.
+The :c:func:`hashkit_free` frees any resources being consumed by the hashkit
+objects that were initialized with :c:func:`hashkit_create` or :c:func:`hashkit_clone`.
 
-The :c:func:`hashkit_is_allocated()` reports where the memory was allocated 
+The :c:func:`hashkit_is_allocated` reports where the memory was allocated 
 for a hashkit object.
 
 
@@ -48,12 +50,12 @@ RETURN VALUE
 ------------
 
 
-:c:func:`hashkit_create()` and :c:func:`hashkit_clone()` will return NULL on 
+:c:func:`hashkit_create` and :c:func:`hashkit_clone` will return NULL on 
 failure or non-NULL on success.
 
-:c:func:`hashkit_is_allocated()` returns true if the memory for the hashkit
-object was allocated inside of :c:func:`hashkit_create()` or 
-:c:func:`hashkit_clone()`, otherwise it is false and was user-supplied memory.
+:c:func:`hashkit_is_allocated` returns true if the memory for the hashkit
+object was allocated inside of :c:func:`hashkit_create` or 
+:c:func:`hashkit_clone`, otherwise it is false and was user-supplied memory.
 
 
 ----
index 737171d4b54f10c3c5a40ea783cd8efcf48f86f5..4db416614ca4536eb7537126051da6251e792f66 100644 (file)
@@ -13,25 +13,25 @@ SYNOPSIS
 
 #include <libhashkit/hashkit.h>
  
-.. c:function:: uint32_t hashkit_default(const char *key, size_t key_length);
+.. c:function:: uint32_t hashkit_default(const char *key, size_t key_length)
 
-.. c:function:: uint32_t hashkit_fnv1_64(const char *key, size_t key_length);
+.. c:function:: uint32_t hashkit_fnv1_64(const char *key, size_t key_length)
 
-.. c:function:: uint32_t hashkit_fnv1a_64(const char *key, size_t key_length);
+.. c:function:: uint32_t hashkit_fnv1a_64(const char *key, size_t key_length)
 
-.. c:function:: uint32_t hashkit_fnv1_32(const char *key, size_t key_length);
+.. c:function:: uint32_t hashkit_fnv1_32(const char *key, size_t key_length)
 
-.. c:function:: uint32_t hashkit_fnv1a_32(const char *key, size_t key_length);
+.. c:function:: uint32_t hashkit_fnv1a_32(const char *key, size_t key_length)
 
-.. c:function:: uint32_t hashkit_crc32(const char *key, size_t key_length);
+.. c:function:: uint32_t hashkit_crc32(const char *key, size_t key_length)
 
-.. c:function:: uint32_t hashkit_hsieh(const char *key, size_t key_length);
+.. c:function:: uint32_t hashkit_hsieh(const char *key, size_t key_length)
 
-.. c:function:: uint32_t hashkit_murmur(const char *key, size_t key_length);
+.. c:function:: uint32_t hashkit_murmur(const char *key, size_t key_length)
 
-.. c:function:: uint32_t hashkit_jenkins(const char *key, size_t key_length);
+.. c:function:: uint32_t hashkit_jenkins(const char *key, size_t key_length)
 
-.. c:function:: uint32_t hashkit_md5(const char *key, size_t key_length);
+.. c:function:: uint32_t hashkit_md5(const char *key, size_t key_length)
 
 Compile and link with -lhashkit
 
@@ -45,7 +45,7 @@ These functions generate hash values from a key using a variety of
 algorithms. These functions can be used standalone, or as arguments
 to hashkit_set_hash_fn(3) or hashkit_set_continuum_hash_fn(3).
 
-The hashkit_hsieh() is only available if the library is built with
+The hashkit_hsieh is only available if the library is built with
 the appropriate flag enabled.
 
 
index f418a394f14d5085819d1f260d0c018612808964..d27e35281ee74814941bd34f22ed469a5a98b986 100644 (file)
@@ -14,19 +14,16 @@ SYNOPSIS
 
 #include <libhashkit/hashkit.h>
 
-.. c:function:: uint32_t hashkit_value(hashkit_st *hash, const char *key, size_t key_length);
+.. c:function:: uint32_t hashkit_value(hashkit_st *hash, const char *key, size_t key_length)
  
-
 Compile and link with -lhashkit
 
-
-
 -----------
 DESCRIPTION
 -----------
 
 
-The :c:func:`hashkit_value()` function generates a 32-bit hash value from the
+The :c:func:`hashkit_value` function generates a 32-bit hash value from the
 given key and key_length. The hash argument is an initialized hashkit
 object, and distribution type and hash function is used from this
 object while generating the value.
index e0dba59b8adb18bca6737750ab69c854eeeb59cd..9dcc7aa25e3cf905e3f4d5cc64ffbcb560b54d30 100644 (file)
@@ -61,8 +61,9 @@ Advanced Topics
    memcached_strerror
    error_messages
    memcached_user_data
-   memcached_verbosity
-   memcached_version
+   memcached_verbosity 
+   memcached_version 
+   libmemcached/defaults
 
 ##################
 Interface Versions
@@ -91,6 +92,7 @@ Platform Specific
    :maxdepth: 1
 
    tap
+   types
 
 #################################
 Deriving statistics from a server
index 7390dd14aaf547a670938a34e58a5f35c06273cc..76b015cb02ce4a3c065d8d7a7211ead0b6d913a2 100644 (file)
@@ -1,5 +1,5 @@
 ===========================================
-memcached_touch(), memcached_touch_by_key()
+memcached_touch, memcached_touch_by_key
 ===========================================
 
 .. index:: object: memcached_st
@@ -11,9 +11,9 @@ SYNOPSIS
 
 #include <libmemcached/memcached.h>
  
-.. c:function:: memcached_return_t memcached_touch (memcached_st *ptr, const char *key, size_t key_length, time_t expiration);
+.. c:function:: memcached_return_t memcached_touch (memcached_st *ptr, const char *key, size_t key_length, time_t expiration)
 
-.. c:function:: memcached_return_t memcached_touch_by_key (memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, time_t expiration);
+.. c:function:: memcached_return_t memcached_touch_by_key (memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, time_t expiration)
 
 Compile and link with -lmemcached
 
@@ -22,8 +22,8 @@ DESCRIPTION
 -----------
 
 
-:c:func:`memcached_touch()` is used to update the expiration time on an existing key.
-:c:func:`memcached_touch_by_key()` works the same, but it takes a master key 
+:c:func:`memcached_touch` is used to update the expiration time on an existing key.
+:c:func:`memcached_touch_by_key` works the same, but it takes a master key 
 to find the given value.
 
 
@@ -34,7 +34,7 @@ RETURN
 
 A value of type :c:type:`memcached_return_t` is returned
 On success that value will be :c:type:`MEMCACHED_SUCCESS`.
-Use :c:func:`memcached_strerror()` to translate this value to a printable 
+Use :c:func:`memcached_strerror` to translate this value to a printable 
 string.
 
 ----
index a97db699575f35967327950f6c9a21d146855aa1..af5ef416a7629b0008c8a6fdc0b602ee7516a30e 100644 (file)
@@ -41,17 +41,17 @@ matched based on server order as supplied by the user). It implements
 a modular and consistent method of object distribution.
 
 There are multiple implemented routing and hashing methods. See the
-:c:func:`memcached_behavior_set()` manpage for more information.
+:c:func:`memcached_behavior_set` manpage for more information.
 
 All operations are performed against a :c:type:`memcached_st` structure.
 These structures can either be dynamically allocated or statically
-allocated and then initialized by :c:func:`memcached_create()`. Functions have 
+allocated and then initialized by :c:func:`memcached_create`. Functions have 
 been written in order to encapsulate the :c:type:`memcached_st`. It is not
 recommended that you operate directly against the structure.
 
 Nearly all functions return a :c:type:`memcached_return_t` value.
 This value can be translated to a printable string with 
-:c:type:`memcached_strerror()`.
+:c:type:`memcached_strerror`.
 
 Objects are stored on servers by hashing keys. The hash value maps the key to a particular server. All clients understand how this hashing works, so it is possibly to reliably both push data to a server and retrieve data from a server.
 
@@ -71,7 +71,7 @@ PKG_CHECK_MODULES(DEPS, libmemcached >= 0.8.0)
 AC_SUBST(DEPS_CFLAGS)
 AC_SUBST(DEPS_LIBS)
 
-Some features of the library must be enabled through :c:func:`memcached_behavior_set()`.
+Some features of the library must be enabled through :c:func:`memcached_behavior_set`.
 
 Hope you enjoy it!
 
@@ -84,46 +84,46 @@ CONSTANTS
 A number of constants have been provided for in the library.
 
 
-.. c:var:: MEMCACHED_DEFAULT_PORT
+.. c:macro:: MEMCACHED_DEFAULT_PORT
  
  The default port used by memcached(3).
  
 
-
-.. c:var:: MEMCACHED_MAX_KEY
+.. c:macro:: MEMCACHED_MAX_KEY
  
  Default maximum size of a key (which includes the null pointer). Master keys
  have no limit, this only applies to keys used for storage.
  
 
-
-.. c:var:: MEMCACHED_MAX_KEY
+.. c:macro:: MEMCACHED_MAX_KEY
  
  Default size of key (which includes the null pointer).
  
 
-
-.. c:var:: MEMCACHED_STRIDE
+.. c:macro:: MEMCACHED_STRIDE
  
  This is the "stride" used in the consistent hash used between replicas.
  
 
-
-.. c:var:: MEMCACHED_MAX_HOST_LENGTH
+.. c:macro:: MEMCACHED_MAX_HOST_LENGTH
  
  Maximum allowed size of the hostname.
  
 
-.. c:var:: LIBMEMCACHED_VERSION_STRING
+.. c:macro:: LIBMEMCACHED_VERSION_STRING
  
  String value of libmemcached version such as "1.23.4"
 
 
-.. c:var:: LIBMEMCACHED_VERSION_HEX
+.. c:macro:: LIBMEMCACHED_VERSION_HEX
  
  Hex value of the version number. "0x00048000" This can be used for comparing versions based on number.
  
 
+.. c:macro:: MEMCACHED_PREFIX_KEY_MAX_SIZE
+
+ Maximum length allowed for namespacing of a key.
+
 
 
 ---------------------
@@ -134,7 +134,7 @@ THREADS AND PROCESSES
 When using threads or forked processes it is important to keep one instance
 of :c:type:`memcached_st` per process or thread. Without creating your own 
 locking structures you can not share a single :c:type:`memcached_st`. However, 
-you can call :c:func:`memcached_quit()` on a :c:type:`memcached_st` and then use the resulting cloned structure.
+you can call :c:func:`memcached_quit` on a :c:type:`memcached_st` and then use the resulting cloned structure.
 
 
 ----
diff --git a/docs/libmemcached/defaults.rst b/docs/libmemcached/defaults.rst
new file mode 100644 (file)
index 0000000..356c047
--- /dev/null
@@ -0,0 +1,36 @@
+======== 
+DEFAULTS 
+======== 
+
+
+.. c:macro:: MEMCACHED_DEFAULT_TIMEOUT
+
+Value 5000
+
+.. c:macro:: MEMCACHED_DEFAULT_CONNECT_TIMEOUT
+
+  Value 4000
+
+.. c:macro:: MEMCACHED_CONTINUUM_ADDITION
+
+  Value 10.  How many extra slots we should build for in the continuum.
+
+.. c:macro:: MEMCACHED_SERVER_FAILURE_LIMIT
+
+  Value 5
+
+.. c:macro:: MEMCACHED_SERVER_FAILURE_RETRY_TIMEOUT
+
+  Value 2
+
+.. c:macro:: MEMCACHED_SERVER_FAILURE_DEAD_TIMEOUT
+
+  Value 0
+
+.. c:macro:: `MEMCACHED_PREFIX_KEY_MAX_SIZE`
+
+  Value 128
+
+.. c:macro:: MEMCACHED_VERSION_STRING_LENGTH
+
+  Value 24
index 9d9951016df549a9cced375b7be4abde03f1f7b8..de40c64f8f494bede647bb77bf97c5927faeef56 100644 (file)
@@ -1,5 +1,5 @@
 =================
-memcached_fetch()
+memcached_fetch
 =================
 
 .. index:: object: memcached_st
@@ -14,7 +14,7 @@ SYNOPSIS
 .. c:function::  char *memcached_fetch(memcached_st *ptr, char *key, size_t *key_length, size_t *value_length, uint32_t *flags, memcached_return_t *error)
 
    .. deprecated:: 0.50
-      Use :c:func:`memcached_fetch_result()` instead.
+      Use :c:func:`memcached_fetch_result` instead.
 
 Compile and link with -lmemcached
 
@@ -23,14 +23,14 @@ Compile and link with -lmemcached
 DESCRIPTION
 -----------
 
-:c:func:`memcached_fetch()` is used to fetch an individual value from the server. :c:func:`memcached_mget()` must always be called before using this method.  
+:c:func:`memcached_fetch` is used to fetch an individual value from the server. :c:func:`memcached_mget` must always be called before using this method.  
 You must pass in a key and its length to fetch the object. You must supply
 three pointer variables which will give you the state of the returned
 object.  A :c:type:`uint32_t` pointer to contain whatever flags you stored with the value, a :c:type:`size_t` pointer which will be filled with size of of the 
 object, and a :c:type:`memcached_return_t` pointer to hold any error. The 
-object will be returned upon success and NULL will be returned on failure. :c:type:`MEMCACHD_END` is returned by the \*error value when all objects that have been found are returned. The final value upon :c:type:`MEMCACHED_END` is null. 
+object will be returned upon success and NULL will be returned on failure. :c:type:`MEMCACHED_END` is returned by the \*error value when all objects that have been found are returned. The final value upon :c:type:`MEMCACHED_END` is null. 
 
-Values returned by :c:func:`memcached_fetch()` must be freed by the caller. 
+Values returned by :c:func:`memcached_fetch` must be freed by the caller. 
 
 All of the above functions are not tested when the 
 :c:type:`MEMCACHED_BEHAVIOR_USE_UDP` has been set. Executing any of these 
@@ -41,11 +41,11 @@ functions with this behavior on will result in :c:type:`MEMCACHED_NOT_SUPPORTED`
 RETURN
 ------
 
-:c:func:`memcached_fetch()` sets error to 
+:c:func:`memcached_fetch` sets error to 
 to :c:type:`MEMCACHED_END` upon successful conclusion.
 :c:type:`MEMCACHED_NOTFOUND` will be return if no keys at all were found.
 
-:c:type:`MEMCACHED_KEY_TOO_BIG` is set to error whenever :c::func:`memcached_fetch()` was used
+:c:type:`MEMCACHED_KEY_TOO_BIG` is set to error whenever :c:func:`memcached_fetch` was used
 and the key was set larger then :c:type:`MEMCACHED_MAX_KEY`, which was the largest
 key allowed for the original memcached ascii server.
 
index 2a18d598d0222c3c9b5385fd67b83ef873a194e7..f91f7ae2b4e0c2407cd57f0a88bb7cf1eef07fdb 100644 (file)
@@ -10,7 +10,7 @@ SYNOPSIS
 
 #include <libmemcached/memcached.h>
  
-.. c:function::  const char *memcached_last_error_message(memcached_st *);
+.. c:function::  const char *memcached_last_error_message(memcached_st *)
 
 Compile and link with -lmemcached
 
@@ -19,7 +19,7 @@ Compile and link with -lmemcached
 DESCRIPTION
 -----------
 
-:c:func:`memcached_last_error_message()` is used to return the last error
+:c:func:`memcached_last_error_message` is used to return the last error
 message that the server responded too. If this error came from a specific
 server, its hostname and port will be provided in the error message.
 
@@ -27,7 +27,7 @@ server, its hostname and port will be provided in the error message.
 RETURN
 ------
 
-memcached_last_error_message() returns a const char* which does not need to be
+memcached_last_error_message returns a const char* which does not need to be
 de-allocated. If no error has occurred then it will return NULL.
 
 ----
index 40f6f96f0a752cf52c59f18d9c6b365ebeda0d51..9eba3fabeb42bfecfcadec012856cbae53ec59ef 100644 (file)
@@ -10,129 +10,123 @@ SYNOPSIS
 
 .. c:type:: memcached_return_t
 
-.. c:function:: const char *libmemcached_strerror(libmemcached_return_t rc)
+.. c:function:: const char *libmemcached_strerror(memcached_return_t rc)
 
-.. c:function:: bool libmemcached_success(libmemcached_return_t rc)
+.. c:function:: bool libmemcached_success(memcached_return_t rc)
 
-.. c:function:: bool libmemcached_failure(libmemcached_return_t rc)
+.. c:function:: bool libmemcached_failure(memcached_return_t rc)
 
-.. c:function:: bool libmemcache_continue(libmemcached_return_t rc)
+.. c:function:: bool libmemcache_continue(memcached_return_t rc)
 
+.. c:function:: bool memcached_success(memcached_return_t)
 
+.. c:function:: bool memcached_failure(memcached_return_t)
 
-:c:func:`memcached_success()` return true if :c:type:`MEMCACHED_SUCCESS` tested true.
 
-:c:func:`memcached_failure()` return true if any value other then :c:type:`MEMCACHED_SUCCESS` was provided.
+:c:func:`memcached_success` return true if :c:type:`MEMCACHED_SUCCESS` tested true.
+
+:c:func:`memcached_failure` return true if any value other then :c:type:`MEMCACHED_SUCCESS` was provided.
 
 
 Libmemcached return types:
 ++++++++++++++++++++++++++
 
 
-.. c:type:: MEMCACHED_SUCCESS
-
-Success
-
-.. c:type:: MEMCACHED_FAILURE
+:c:type:`MEMCACHED_SUCCESS`
 
-.. c:type:: MEMCACHED_HOST_LOOKUP_FAILURE
+:c:type:`MEMCACHED_FAILURE`
 
-.. c:type:: MEMCACHED_CONNECTION_FAILURE
+:c:type:`MEMCACHED_HOST_LOOKUP_FAILURE`
 
-.. c:type:: MEMCACHED_CONNECTION_BIND_FAILURE
-.. deprecated:: <0.30
+:c:type:`MEMCACHED_CONNECTION_FAILURE`
 
-.. c:type:: MEMCACHED_WRITE_FAILURE
+:c:type:`MEMCACHED_CONNECTION_BIND_FAILURE`
 
-.. c:type:: MEMCACHED_READ_FAILURE
+:c:type:`MEMCACHED_WRITE_FAILURE`
 
-.. c:type:: MEMCACHED_UNKNOWN_READ_FAILURE
+:c:type:`MEMCACHED_READ_FAILURE`
 
-.. c:type:: MEMCACHED_PROTOCOL_ERROR
+:c:type:`MEMCACHED_UNKNOWN_READ_FAILURE`
 
-.. c:type:: MEMCACHED_CLIENT_ERROR
+:c:type:`MEMCACHED_PROTOCOL_ERROR`
 
-.. c:type:: MEMCACHED_SERVER_ERROR
+:c:type:`MEMCACHED_CLIENT_ERROR`
 
-.. c:type:: MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE
-.. deprecated:: <0.30
+:c:type:`MEMCACHED_SERVER_ERROR`
 
-.. c:type:: MEMCACHED_DATA_EXISTS
+:c:type:`MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE`
 
-.. c:type:: MEMCACHED_DATA_DOES_NOT_EXIST
+:c:type:`MEMCACHED_DATA_EXISTS`
 
-.. c:type:: MEMCACHED_NOTSTORED
+:c:type:`MEMCACHED_DATA_DOES_NOT_EXIST`
 
-.. c:type:: MEMCACHED_STORED
+:c:type:`MEMCACHED_NOTSTORED`
 
-.. c:type:: MEMCACHED_NOTFOUND
+:c:type:`MEMCACHED_STORED`
 
-.. c:type:: MEMCACHED_MEMORY_ALLOCATION_FAILURE
+:c:type:`MEMCACHED_NOTFOUND`
 
-.. c:type:: MEMCACHED_PARTIAL_READ
+:c:type:`MEMCACHED_MEMORY_ALLOCATION_FAILURE`
 
-.. c:type:: MEMCACHED_SOME_ERRORS
+:c:type:`MEMCACHED_PARTIAL_READ`
 
-.. c:type:: MEMCACHED_NO_SERVERS
+:c:type:`MEMCACHED_SOME_ERRORS`
 
-.. c:type:: MEMCACHED_END
+:c:type:`MEMCACHED_NO_SERVERS`
 
-.. c:type:: MEMCACHED_DELETED
+:c:type:`MEMCACHED_END`
 
-.. c:type:: MEMCACHED_VALUE
+:c:type:`MEMCACHED_DELETED`
 
-.. c:type:: MEMCACHED_STAT
+:c:type:`MEMCACHED_VALUE`
 
-.. c:type:: MEMCACHED_ITEM
+:c:type:`MEMCACHED_STAT`
 
-.. c:type:: MEMCACHED_ERRNO
+:c:type:`MEMCACHED_ITEM`
 
-.. c:type:: MEMCACHED_FAIL_UNIX_SOCKET
-.. deprecated:: <0.30
+:c:type:`MEMCACHED_ERRNO`
 
-.. c:type:: MEMCACHED_NOT_SUPPORTED
+:c:type:`MEMCACHED_FAIL_UNIX_SOCKET`
 
-.. c:type:: MEMCACHED_NO_KEY_PROVIDED
-.. deprecated:: <0.30
-   Use :c:type:`MEMCACHED_BAD_KEY_PROVIDED` instead.
+:c:type:`MEMCACHED_NOT_SUPPORTED`
 
-.. c:type:: MEMCACHED_FETCH_NOTFINISHED
+:c:type:`MEMCACHED_NO_KEY_PROVIDED`
 
-.. c:type:: MEMCACHED_TIMEOUT
+:c:type:`MEMCACHED_FETCH_NOTFINISHED`
 
-   Connection to server timed out.
+:c:type:`MEMCACHED_TIMEOUT`
 
-.. c:type:: MEMCACHED_BUFFERED
+:c:type:`MEMCACHED_BUFFERED`
 
-.. c:type:: MEMCACHED_BAD_KEY_PROVIDED
+:c:type:`MEMCACHED_BAD_KEY_PROVIDED`
 
-.. c:type:: MEMCACHED_INVALID_HOST_PROTOCOL
+:c:type:`MEMCACHED_INVALID_HOST_PROTOCOL`
 
-.. c:type:: MEMCACHED_SERVER_MARKED_DEAD
+:c:type:`MEMCACHED_SERVER_MARKED_DEAD`
 
-.. c:type:: MEMCACHED_UNKNOWN_STAT_KEY
+:c:type:`MEMCACHED_UNKNOWN_STAT_KEY`
 
-.. c:type:: MEMCACHED_E2BIG
+:c:type:`MEMCACHED_E2BIG`
 
-.. c:type:: MEMCACHED_INVALID_ARGUMENTS
+:c:type:`MEMCACHED_INVALID_ARGUMENTS`
 
-.. c:type:: MEMCACHED_KEY_TOO_BIG
+:c:type:`MEMCACHED_KEY_TOO_BIG`
 
-.. c:type:: MEMCACHED_AUTH_PROBLEM
+:c:type:`MEMCACHED_AUTH_PROBLEM`
 
-.. c:type:: MEMCACHED_AUTH_FAILURE
+:c:type:`MEMCACHED_AUTH_FAILURE`
 
-.. c:type:: MEMCACHED_AUTH_CONTINUE
+:c:type:`MEMCACHED_AUTH_CONTINUE`
 
-.. c:type:: MEMCACHED_PARSE_ERROR
+:c:type:`MEMCACHED_PARSE_ERROR`
 
-.. c:type:: MEMCACHED_PARSE_USER_ERROR
+:c:type:`MEMCACHED_PARSE_USER_ERROR`
 
-.. c:type:: MEMCACHED_DEPRECATED
+:c:type:`MEMCACHED_DEPRECATED`
    
 --------
 SEE ALSO
 --------
 
-:manpage:`memcached(8)` :manpage:`libmemcached(3)` :manpage:`memcached_client_error()` or :manpage:`memcached_worker_error()`
+:manpage:`memcached` :manpage:`libmemcached` :manpage:`memcached_client_error` or :manpage:`memcached_worker_error`
 
index a9e30b30f864e49bb8653f467d355aea59da62c2..a43ee1a2a11f77a07cffd6614531359ab9e0d13b 100644 (file)
@@ -30,7 +30,7 @@ Connecting to servers
 
 
 In the above code you create a :c:type:`memcached_st` object with three server 
-by making use of :c:func:`memcached_create_with_options()`.
+by making use of :c:func:`memcached_create`.
 
 
 --------------------------
index e50c800d2787dc104f4f50a9b5d7a2f5397fa68a..692aa2ef444bda18ff2d6f4b7c4439f77a674b2f 100644 (file)
@@ -35,7 +35,7 @@ THREADS
 Do not try to access an instance of :c:type:`memcached_st` from multiple threads
 at the same time. If you want to access memcached from multiple threads
 you should either clone the :c:type:`memcached_st`, or use the memcached pool
-implementation. see :c:func:`memcached_pool_create()`.
+implementation. see :c:func:`memcached_pool_create`.
 
 
 ----
index 9a0c49d232f007a9ca21433e37622a219be5f9b1..88f3ad9d6b74076d8666606bc5db1c7cce375ce0 100644 (file)
@@ -14,8 +14,10 @@ SYNOPSIS
 
 
 #include <libmemcached/memcached.h>
+
+.. c:type:: memcached_analysis_st
  
-.. c:function::  memcached_analysis_st * memcached_analyze (memcached_st *ptr, memcached_stat_st *stat, memcached_return_t *error);
+.. c:function::  memcached_analysis_st * memcached_analyze (memcached_st *ptr, memcached_stat_st *stat, memcached_return_t *error)
 
 Compile and link with -lmemcached
 
@@ -28,11 +30,11 @@ DESCRIPTION
 collection of servers) for their current state. Queries to find state return a
 :c:type:`memcached_analysis_st` structure. You are responsible for freeing this structure.
 
-:c:func:`memcached_analyze()` analyzes useful information based on the 
+:c:func:`memcached_analyze` analyzes useful information based on the 
 provided servers and sets the result to the :c:type:`memcached_analysis_st` 
 structure. The return value must be freed by the calling application.
 
-A command line tool, :c:func:`memstat()` with the option :option:`--analyze`, 
+A command line tool, :program:`memstat` with the option :option:`memstat --analyze`, 
 is provided so that you do not have to write an application to use this method.
 
 
index a99b2cbc53deb4a48e44072d326861a97071a0f2..0510a3164f4ab1d73376c9d370f6a60510e6ea7b 100644 (file)
@@ -18,9 +18,9 @@ SYNOPSIS
 
 .. c:function:: memcached_return_t memcached_append(memcached_st *ptr, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags)
 
-.. c:function:: memcached_return_t memcached_prepend_by_key(memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags);
+.. c:function:: memcached_return_t memcached_prepend_by_key(memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags)
 
-.. c:function:: memcached_return_t memcached_append_by_key(memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags);
+.. c:function:: memcached_return_t memcached_append_by_key(memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags)
 
 Compile and link with -lmemcached
 
@@ -30,7 +30,7 @@ DESCRIPTION
 -----------
 
 
-:c:func:`memcached_prepend()` and memcached_append are used to 
+:c:func:`memcached_prepend` and memcached_append are used to 
 modify information on a server. All methods take a key, and its length to
 store the object. Keys are currently limited to 250 characters when using 
 either a version of memcached which is 1.4 or below, or when using the text 
@@ -40,18 +40,18 @@ meant to be used as a bitmap). "flags" is a 4byte space that is stored
 alongside of the main value. Many sub libraries make use of this field, 
 so in most cases users should avoid making use of it.
 
-:c:func:`memcached_prepend()` places a segment of data before the last piece 
+:c:func:`memcached_prepend` places a segment of data before the last piece 
 of data stored. Currently expiration and key are not used in the server.
 
-:c:func:`memcached_append()` places a segment of data at the end of the last 
+:c:func:`memcached_append` places a segment of data at the end of the last 
 piece of data stored. Currently expiration and key are not used in the server.
 
-:c:func:`memcached_prepend_by_key()` and 
-:c:func:`memcached_append_by_key_by_key()` methods both behave in a similar 
+:c:func:`memcached_prepend_by_key` and 
+:c:func:`memcached_append_by_key` methods both behave in a similar 
 method as the non key methods. The difference is that they use their 
 group_key parameter to map objects to particular servers.
 
-If you are looking for performance, :c:func:`memcached_set()` with non-blocking
+If you are looking for performance, :c:func:`memcached_set` with non-blocking
 IO is the fastest way to store data on the server.
 
 All of the above functions are testsed with the 
@@ -81,7 +81,7 @@ RETURN
 
 All methods return a value of type :c:type:`memcached_return_t`.
 On success the value will be :c:type:`MEMCACHED_SUCCESS`.
-Use :c:func:`memcached_strerror()` to translate this value to a printable 
+Use :c:func:`memcached_strerror` to translate this value to a printable 
 string.
 
 
index c008cd5de23cc55439af274376f7fdd2545ee8bf..c3f4c7f5b8343bfe44d6a8e54e0ff78709c37177 100644 (file)
@@ -10,21 +10,21 @@ SYNOPSIS
 
 #include <libmemcached/memcached.h>
  
-.. c:function:: memcached_return_t memcached_increment (memcached_st *ptr, const char *key, size_t key_length, unsigned int offset, uint64_t *value);
+.. c:function:: memcached_return_t memcached_increment (memcached_st *ptr, const char *key, size_t key_length, uint32_t offset, uint64_t *value)
 
-.. c:function:: memcached_return_t memcached_decrement (memcached_st *ptr, const char *key, size_t key_length, unsigned int offset, uint64_t *value);
+.. c:function:: memcached_return_t memcached_decrement (memcached_st *ptr, const char *key, size_t key_length, uint32_t offset, uint64_t *value)
 
-.. c:function:: memcached_return_t memcached_increment_with_initial (memcached_st *ptr, const char *key, size_t key_length, uint64_t offset, uint64_t initial, time_t expiration, uint64_t *value);
+.. c:function:: memcached_return_t memcached_increment_with_initial (memcached_st *ptr, const char *key, size_t key_length, uint64_t offset, uint64_t initial, time_t expiration, uint64_t *value)
 
-.. c:function:: memcached_return_t memcached_decrement_with_initial (memcached_st *ptr, const char *key, size_t key_length, uint64_t offset, uint64_t initial, time_t expiration, uint64_t *value);
+.. c:function:: memcached_return_t memcached_decrement_with_initial (memcached_st *ptr, const char *key, size_t key_length, uint64_t offset, uint64_t initial, time_t expiration, uint64_t *value)
 
-.. c:function::  memcached_return_t memcached_increment_by_key (memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, unsigned int offset, uint64_t *value);
+.. c:function::  memcached_return_t memcached_increment_by_key (memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, uint32_t offset, uint64_t *value)
 
-.. c:function:: memcached_return_t memcached_decrement_by_key (memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, unsigned int offset, uint64_t *value);
+.. c:function:: memcached_return_t memcached_decrement_by_key (memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, uint32_t offset, uint64_t *value)
 
-.. c:function:: memcached_return_t memcached_increment_with_initial_by_key (memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, uint64_t offset, uint64_t initial, time_t expiration, uint64_t *value);
+.. c:function:: memcached_return_t memcached_increment_with_initial_by_key (memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, uint64_t offset, uint64_t initial, time_t expiration, uint64_t *value)
 
-.. c:function:: memcached_return_t memcached_decrement_with_initial_by_key (memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, uint64_t offset, uint64_t initial, time_t expiration, uint64_t *value);
+.. c:function:: memcached_return_t memcached_decrement_with_initial_by_key (memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, uint64_t offset, uint64_t initial, time_t expiration, uint64_t *value)
 
 Compile and link with -lmemcached
 
@@ -38,36 +38,35 @@ DESCRIPTION
 (overflow and underflow are not detected). This gives you the ability to use
 memcached to generate shared sequences of values.
 
-memcached_increment() takes a key and keylength and increments the value by
-the offset passed to it. The value is then returned via the unsigned int
+memcached_increment takes a key and keylength and increments the value by
+the offset passed to it. The value is then returned via the uint32_t
 value pointer you pass to it.
 
-memcached_decrement() takes a key and keylength and decrements the value by
-the offset passed to it. The value is then returned via the unsigned int
+memcached_decrement takes a key and keylength and decrements the value by
+the offset passed to it. The value is then returned via the uint32_t
 value pointer you pass to it.
 
-memcached_increment_with_initial() takes a key and keylength and increments
+memcached_increment_with_initial takes a key and keylength and increments
 the value by the offset passed to it. If the object specified by key does
 not exist, one of two things may happen: If the expiration value is
 MEMCACHED_EXPIRATION_NOT_ADD, the operation will fail. For all other
 expiration values, the operation will succeed by seeding the value for that
 key with a initial value to expire with the provided expiration time. The
-flags will be set to zero.The value is then returned via the unsigned int
+flags will be set to zero.The value is then returned via the uint32_t
 value pointer you pass to it.
 
-memcached_decrement_with_initial() takes a key and keylength and decrements
+memcached_decrement_with_initial takes a key and keylength and decrements
 the value by the offset passed to it. If the object specified by key does
 not exist, one of two things may happen: If the expiration value is
 MEMCACHED_EXPIRATION_NOT_ADD, the operation will fail. For all other
 expiration values, the operation will succeed by seeding the value for that
 key with a initial value to expire with the provided expiration time. The
-flags will be set to zero.The value is then returned via the unsigned int
+flags will be set to zero.The value is then returned via the uint32_t
 value pointer you pass to it.
 
-memcached_increment_by_key(), memcached_decrement_by_key(),
-memcached_increment_with_initial_by_key(), and
-memcached_decrement_with_initial_by_key() are master key equivalents of the
-above.
+:c:func:`memcached_increment_by_key`, :c:func:`memcached_decrement_by_key`,
+:c:func:`memcached_increment_with_initial_by_key`, and
+:c:func:`memcached_decrement_with_initial_by_key` are master key equivalents of the above.
 
 
 ------
@@ -75,9 +74,9 @@ RETURN
 ------
 
 
-A value of type \ ``memcached_return_t``\  is returned.
-On success that value will be \ ``MEMCACHED_SUCCESS``\ .
-Use memcached_strerror() to translate this value to a printable string.
+A value of type :c:type:`memcached_return_t`  is returned.
+On success that value will be :c:type:`MEMCACHED_SUCCESS`.
+Use memcached_strerror to translate this value to a printable string.
 
 
 ----
index 3480d2511ca3817b9631bd733c854957b148b1d5..ee1bb234d22aca29ee8f7b45320c7d4e01907d66 100644 (file)
@@ -14,10 +14,12 @@ SYNOPSIS
 
 
 #include <libmemcached/memcached.h>
+
+.. c:type:: memcached_behavior_t
  
-.. c:function:: uint64_t memcached_behavior_get (memcached_st *ptr, memcached_behavior flag);
+.. c:function:: uint64_t memcached_behavior_get (memcached_st *ptr, memcached_behavior_t flag)
 
-.. c:function:: memcached_return_t memcached_behavior_set (memcached_st *ptr, memcached_behavior flag, uint64_t data);
+.. c:function:: memcached_return_t memcached_behavior_set (memcached_st *ptr, memcached_behavior_t flag, uint64_t data)
 
 Compile and link with -lmemcached
 
@@ -26,17 +28,17 @@ Compile and link with -lmemcached
 DESCRIPTION
 -----------
 
-:manpage:`libmemcached(3)` behavior can be modified by using :c:func:`memcached_behavior_set()`. Default behavior is the library strives to be quick and 
+:manpage:`libmemcached(3)` behavior can be modified by using :c:func:`memcached_behavior_set`. Default behavior is the library strives to be quick and 
 accurate. Some behavior, while being faster, can also result in not entirely 
-accurate behavior (for instance, :c:func:`memcached_set()` will always respond 
+accurate behavior (for instance, :c:func:`memcached_set` will always respond 
 with :c:type:`MEMCACHED_SUCCESS`).
 
-:c:func:`memcached_behavior_get()` takes a behavior flag and returns whether or not that behavior is currently enabled in the client.
+:c:func:`memcached_behavior_get` takes a behavior flag and returns whether or not that behavior is currently enabled in the client.
 
-:c:func:`memcached_behavior_set()` changes the value of a particular option 
+:c:func:`memcached_behavior_set` changes the value of a particular option 
 of the client. It takes both a flag (listed below) and a value. For simple 
 on or off options you just need to pass in a value of 1. Calls to
-:c:func:`memcached_behavior_set()` will flush and reset all connections.
+:c:func:`memcached_behavior_set` will flush and reset all connections.
 
 
 .. c:type:: MEMCACHED_BEHAVIOR_USE_UDP
@@ -44,7 +46,12 @@ on or off options you just need to pass in a value of 1. Calls to
 Causes :manpage:`libmemcached(3)` to use the UDP transport when communicating
 with a memcached server. Not all I/O operations are testsed
 when this behavior is enababled. The following operations will return
-:c:type:`MEMCACHED_NOT_SUPPORTED` when executed with the :c:type:`MEMCACHED_BEHAVIOR_USE_UDP` enabled: :c:func:`memcached_version()`, :c:func:`memcached_stat()`, :c:func:`memcached_get()`, :c:func:`memcached_get_by_key()`, :c:func:`memcached_mget()`, :c:func:`memcached_mget_by_key()`, :c:func:`memcached_fetch()`, :c:func:`memcached_fetch_result()`, :c:func:`memcached_value_fetch()`.
+:c:type:`MEMCACHED_NOT_SUPPORTED` when executed with the
+:c:type:`MEMCACHED_BEHAVIOR_USE_UDP` enabled: :c:func:`memcached_version`,
+:c:func:`memcached_stat`, :c:func:`memcached_get`,
+:c:func:`memcached_get_by_key`, :c:func:`memcached_mget`,
+:c:func:`memcached_mget_by_key`, :c:func:`memcached_fetch`,
+:c:func:`memcached_fetch_result`, :c:func:`memcached_fetch_execute`.
 
 All other operations are testsed but are executed in a 'fire-and-forget'
 mode, in which once the client has executed the operation, no attempt
@@ -114,7 +121,8 @@ Support CAS operations (this is not enabled by default at this point in the serv
 
 .. c:type:: MEMCACHED_BEHAVIOR_KETAMA
 
-Sets the default distribution to MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA and the hash to MEMCACHED_HASH_MD5.
+Sets the default distribution to MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA and
+the hash to :c:type:`MEMCACHED_HASH_MD5`.
 
 
 .. c:type:: MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED
@@ -123,7 +131,11 @@ Sets the default distribution to MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA and th
 
 .. c:type:: MEMCACHED_BEHAVIOR_KETAMA_HASH
 
-Sets the hashing algorithm for host mapping on continuum. The value can be set to either MEMCACHED_HASH_DEFAULT, MEMCACHED_HASH_MD5, MEMCACHED_HASH_CRC, MEMCACHED_HASH_FNV1_64, MEMCACHED_HASH_FNV1A_64, MEMCACHED_HASH_FNV1_32, and MEMCACHED_HASH_FNV1A_32.
+Sets the hashing algorithm for host mapping on continuum. The value can be set
+to either :c:type:`MEMCACHED_HASH_DEFAULT`, :c:type:`MEMCACHED_HASH_MD5`,
+:c:type:`MEMCACHED_HASH_CRC`, :c:type:`MEMCACHED_HASH_FNV1_64`,
+:c:type:`MEMCACHED_HASH_FNV1A_64`, :c:type:`MEMCACHED_HASH_FNV1_32`, and
+:c:type:`MEMCACHED_HASH_FNV1A_32`.
 
 .. c:type:: MEMCACHED_BEHAVIOR_KETAMA_COMPAT
 
@@ -131,7 +143,7 @@ Sets the compatibility mode. The value can be set to either MEMCACHED_KETAMA_COM
 
 .. c:type:: MEMCACHED_BEHAVIOR_POLL_TIMEOUT
 
-Modify the timeout value that is used by poll(). The default value is -1. An signed int pointer must be passed to memcached_behavior_set() to change this value. For memcached_behavior_get() a signed int value will be cast and returned as the unsigned long long.
+Modify the timeout value that is used by poll. The default value is -1. An signed int pointer must be passed to memcached_behavior_set to change this value. For memcached_behavior_get a signed int value will be cast and returned as the unsigned long long.
 
 .. c:type:: MEMCACHED_BEHAVIOR_USER_DATA
 .. deprecated:: < 0.30
@@ -269,8 +281,8 @@ RETURN
 ------
 
 
-memcached_behavior_get() returns either the current value of the get, or 0
-or 1 on simple flag behaviors (1 being enabled). memcached_behavior_set()
+memcached_behavior_get returns either the current value of the get, or 0
+or 1 on simple flag behaviors (1 being enabled). memcached_behavior_set
 returns failure or success.
 
 
@@ -279,7 +291,7 @@ NOTES
 -----
 
 
-memcached_behavior_set() in version .17 was changed from taking a pointer
+memcached_behavior_set in version .17 was changed from taking a pointer
 to data value, to taking a uin64_t.
 
 
index 060e43ab69664c8a2cd2236c85106e57bda7c19f..0641aa4af64c781f8f3c23317c0bbb7fd79667cf 100644 (file)
@@ -13,10 +13,12 @@ SYNOPSIS
 --------
 
 #include <libmemcached/memcached.h>
+
+.. c:type:: memcached_callback_t
  
-.. c:function:: memcached_return_t memcached_callback_set (memcached_st *ptr, memcached_callback_t flag, const void *data);
+.. c:function:: memcached_return_t memcached_callback_set (memcached_st *ptr, memcached_callback_t flag, const void *data)
  
-.. c:function:: void * memcached_callback_get (memcached_st *ptr, memcached_callback_t flag, memcached_return_t *error);
+.. c:function:: void * memcached_callback_get (memcached_st *ptr, memcached_callback_t flag, memcached_return_t *error)
 
 Compile and link with -lmemcached
 
@@ -30,10 +32,10 @@ libmemcached(3) can have callbacks set key execution points. These either
 provide function calls at points in the code, or return pointers to
 structures for particular usages.
 
-:c:func:`memcached_callback_get()` takes a callback flag and returns the 
-structure or function set by :c:func:`memcached_callback_set()`.
+:c:func:`memcached_callback_get` takes a callback flag and returns the 
+structure or function set by :c:func:`memcached_callback_set`.
 
-:c:func:`memcached_callback_set()` changes the function/structure assigned by a
+:c:func:`memcached_callback_set` changes the function/structure assigned by a
 callback flag. No connections are reset.
 
 You can use :c:type:`MEMCACHED_CALLBACK_USER_DATA` to provide custom context 
@@ -42,14 +44,14 @@ if required for any of the callbacks.
 
 .. c:type:: MEMCACHED_CALLBACK_CLEANUP_FUNCTION
  
-When :c:func:`memcached_delete()` is called this function will be excuted. At 
+When :c:func:`memcached_delete` is called this function will be excuted. At 
 the point of its execution all connections are closed.
  
 
 
 .. c:type:: MEMCACHED_CALLBACK_CLONE_FUNCTION
  
-When :c:func:`memcached_delete()` is called this function will be excuted. 
+When :c:func:`memcached_delete` is called this function will be excuted. 
 At the point of its execution all connections are closed.
 
 .. c:type:: MEMCACHED_CALLBACK_PREFIX_KEY
@@ -59,9 +61,9 @@ At the point of its execution all connections are closed.
 .. c:type:: MEMCACHED_CALLBACK_NAMESPACE
  
 You can set a value which will be used to create a domain for your keys.
-The value specified here will be prefixed to each of your keys. The value can 
-not be greater then :c:type:`MEMCACHED_PREFIX_KEY_MAX_SIZE - 1` and will 
-reduce :c:type:`MEMCACHED_MAX_KEY` by the value of your key. 
+The value specified here will be prefixed to each of your keys. The value can
+not be greater then :c:macro:`MEMCACHED_PREFIX_KEY_MAX_SIZE` - 1 and will
+reduce :c:macro:`MEMCACHED_MAX_KEY` by the value of your key. 
 
 The prefix key is only applied to the primary key, not the master key. 
 :c:type:`MEMCACHED_FAILURE` will be returned if no key is set. In the case of 
@@ -72,7 +74,7 @@ If you set a value with the value being NULL then the prefix key is disabled.
 .. c:type:: MEMCACHED_CALLBACK_USER_DATA
  
 This allows you to store a pointer to a specifc piece of data. This can be
-retrieved from inside of :c:func:`memcached_fetch_execute()`. Cloning a 
+retrieved from inside of :c:func:`memcached_fetch_execute`. Cloning a 
 :c:type:`memcached_st` will copy the pointer to the clone.
  
 .. c:type:: MEMCACHED_CALLBACK_MALLOC_FUNCTION
@@ -122,11 +124,11 @@ RETURN
 ------
 
 
-:c:func:`memcached_callback_get()` return the function or structure that was 
+:c:func:`memcached_callback_get` return the function or structure that was 
 provided. Upon error, nothing is set, null is returned, and the 
 :c:type:`memcached_return_t` argument is set to :c:type:`MEMCACHED_FAILURE`.
 
-:c:func:`memcached_callback_set()` returns :c:type:`MEMCACHED_SUCCESS` upon 
+:c:func:`memcached_callback_set` returns :c:type:`MEMCACHED_SUCCESS` upon 
 successful setting, otherwise :c:type:`MEMCACHED_FAILURE` on error.
 
 
index c2138bc8979d18263acd91a46321bbfa6a17a2f5..a796f303f5c5a13a772c559c4d1bc15320659cf4 100644 (file)
@@ -12,9 +12,9 @@ SYNOPSIS
 
 #include <libmemcached/memcached.h>
 
-.. c:function:: memcached_return_t memcached_cas(memcached_st *ptr, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags, uint64_t cas);
+.. c:function:: memcached_return_t memcached_cas(memcached_st *ptr, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags, uint64_t cas)
 
-.. c:function:: memcached_return_t memcached_cas_by_key(memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags, uint64_t cas);
+.. c:function:: memcached_return_t memcached_cas_by_key(memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags, uint64_t cas)
 
 Compile and link with -lmemcached
 
@@ -23,17 +23,17 @@ Compile and link with -lmemcached
 DESCRIPTION
 -----------
 
-:c:func:`memcached_cas()` overwrites data in the server as long as the "cas" 
+:c:func:`memcached_cas` overwrites data in the server as long as the "cas" 
 value is still the same in the server. You can get the cas value of a result 
-by calling :c:func:`memcached_result_cas()` on a memcached_result_st(3) 
+by calling :c:func:`memcached_result_cas` on a memcached_result_st(3) 
 structure. At the point that this note was written cas is still buggy in memached. Turning on tests for it in libmemcached(3) is optional. Please see 
-:c:func:`memcached_set()` for information on how to do this.
+:c:func:`memcached_set` for information on how to do this.
 
-:c:func:`memcached_cas_by_key()` method behaves in a similar method as the non 
-key methods. The difference is that it uses the :c:type:`group_key` parameter 
+:c:func:`memcached_cas_by_key` method behaves in a similar method as the non 
+key methods. The difference is that it uses the group_key parameter 
 to map objects to particular servers.
 
-:c:func:`memcached_cas()` is testsed with the :c:type:`MEMCACHED_BEHAVIOR_USE_UDP` behavior enabled. However, when using these operations with this behavior 
+:c:func:`memcached_cas` is testsed with the :c:type:`MEMCACHED_BEHAVIOR_USE_UDP` behavior enabled. However, when using these operations with this behavior 
 on, there are limits to the size of the payload being sent to the server.  The 
 reason for these limits is that the Memcached Server does not allow 
 multi-datagram requests and the current server implementation sets a datagram 
@@ -56,7 +56,7 @@ RETURN
 
 All methods return a value of type :c:type:`memcached_return_t`.
 On success the value will be :c:type:`MEMCACHED_SUCCESS`.
-Use :c:func:`memcached_strerror()` to translate this value to a printable 
+Use :c:func:`memcached_strerror` to translate this value to a printable 
 string.
 
 
index 8e1d30f532d62ae76fa45e3b198f119db6cf0992..5eaaee03b016143965c7c746e6832101ece75f49 100644 (file)
@@ -8,7 +8,7 @@ SYNOPSIS
 
 #include <libmemcached/memcached.h>
 
-.. c:type:: memcachd_st
+.. c:type:: memcached_st
 
 .. c:function:: memcached_st* memcached_create(memcached_st *ptr)
  
@@ -25,29 +25,29 @@ Compile and link with -lmemcached
 DESCRIPTION
 -----------
 
-:c:func:`memcached_create()` is used to create a :c:type:`memcached_st` 
+:c:func:`memcached_create` is used to create a :c:type:`memcached_st` 
 structure that will then be used by other libmemcached(3) functions to 
 communicate with the server. You should either pass a statically declared 
-:c:type:`memcached_st` to :c:func:`memcached_create()` or
+:c:type:`memcached_st` to :c:func:`memcached_create` or
 a NULL. If a NULL passed in then a structure is allocated for you.
 
 Please note, when you write new application use 
-:c:func:`memcached_create_with_options()` over 
-:c:func:`memcached_create()`.
+:c:func:`memcached` over 
+:c:func:`memcached_create`.
 
-:c:func:`memcached_clone()` is similar to :c:func:`memcached_create()` but 
+:c:func:`memcached_clone` is similar to :c:func:`memcached_create` but 
 it copies the defaults and list of servers from the source 
 :c:type:`memcached_st`. If you pass a null as the argument for the source 
-to clone, it is the same as a call to :c:func:`memcached_create()`.
+to clone, it is the same as a call to :c:func:`memcached_create`.
 If the destination argument is NULL a :c:type:`memcached_st` will be allocated 
 for you.
 
-:c:func:`memcached_servers_reset()` allows you to zero out the list of 
+:c:func:`memcached_servers_reset` allows you to zero out the list of 
 servers that the :c:type:`memcached_st` has.
 
 To clean up memory associated with a :c:type:`memcached_st` structure you 
-should pass it to :c:func:`memcached_free()` when you are finished using it. 
-:c:func:`memcached_free()` is the only way to make sure all memory is 
+should pass it to :c:func:`memcached_free` when you are finished using it. 
+:c:func:`memcached_free` is the only way to make sure all memory is 
 deallocated when you finish using the structure.
 
 You may wish to avoid using memcached_create(3) or memcached_clone(3) with a
@@ -60,10 +60,10 @@ RETURN
 ------
 
 
-:c:func:`memcached_create()` returns a pointer to the :c:type:`memcached_st` 
+:c:func:`memcached_create` returns a pointer to the :c:type:`memcached_st` 
 that was created (or initialized). On an allocation failure, it returns NULL.
 
-:c:func:`memcached_clone()` returns a pointer to the :c:type:`memcached_st` 
+:c:func:`memcached_clone` returns a pointer to the :c:type:`memcached_st` 
 that was created (or initialized). On an allocation failure, it returns NULL.
 
 
index acea40fafcd7de40f523cd48de891afb776fdae4..1c4f2661bd11e9a5b7145fdcae97ee6a043c5f5e 100644 (file)
@@ -11,9 +11,9 @@ SYNOPSIS
 
 #include <libmemcached/memcached.h>
  
-.. c:function:: memcached_return_t memcached_delete (memcached_st *ptr, const char *key, size_t key_length, time_t expiration);
+.. c:function:: memcached_return_t memcached_delete (memcached_st *ptr, const char *key, size_t key_length, time_t expiration)
 
-.. c:function:: memcached_return_t memcached_delete_by_key (memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, time_t expiration);
+.. c:function:: memcached_return_t memcached_delete_by_key (memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, time_t expiration)
 
 Compile and link with -lmemcached
 
@@ -22,8 +22,8 @@ DESCRIPTION
 -----------
 
 
-:c:func:`memcached_delete()` is used to delete a particular key. 
-:c:func:`memcached_delete_by_key()` works the same, but it takes a master key 
+:c:func:`memcached_delete` is used to delete a particular key. 
+:c:func:`memcached_delete_by_key` works the same, but it takes a master key 
 to find the given value.
 
 Expiration works by placing the item into a delete queue, which means that
@@ -42,7 +42,7 @@ RETURN
 
 A value of type :c:type:`memcached_return_t` is returned
 On success that value will be :c:type:`MEMCACHED_SUCCESS`.
-Use :c:func:`memcached_strerror()` to translate this value to a printable 
+Use :c:func:`memcached_strerror` to translate this value to a printable 
 string.
 
 If you are using the non-blocking mode of the library, success only
index 3ef1c43c0ec97decceaf425563678e4b9d1ef165..988410fc40fbdac1b57505962a75a2009845a3ab 100644 (file)
@@ -15,9 +15,9 @@ SYNOPSIS
 
 #include <libmemcached/memcached.h>
 
-.. c:function:: memcached_return_t memcached_dump (memcached_st *ptr, memcached_dump_fn *function, void *context, uint32_t number_of_callbacks);
+.. c:function:: memcached_return_t memcached_dump (memcached_st *ptr, memcached_dump_fn *function, void *context, uint32_t number_of_callbacks)
  
-.. c:function::  typedef memcached_return_t (*memcached_dump_fn)(memcached_st *ptr,  const char *key, size_t key_length, void *context);
+.. c:type:: memcached_return_t (*memcached_dump_fn)(memcached_st *ptr,  const char *key, size_t key_length, void *context)
 
 Compile and link with -lmemcached
 
@@ -28,7 +28,7 @@ DESCRIPTION
 -----------
 
 
-:c:func:`memcached_dump()` is used to get a list of keys found in memcached(1) 
+:c:func:`memcached_dump` is used to get a list of keys found in memcached(1) 
 servers. Because memcached(1) does not guarentee to dump all keys you can not 
 assume you have fetched all keys from the server. The function takes an array
 of callbacks that it will use to execute on keys as they are found.
@@ -43,7 +43,7 @@ RETURN
 
 A value of type :c:type:`memcached_return_t` is returned
 On success that value will be :c:type:`MEMCACHED_SUCCESS`.
-Use :c:func:`memcached_strerror()` to translate this value to a printable 
+Use :c:func:`memcached_strerror` to translate this value to a printable 
 string.
 
 
index a5c273de8730dfa9e1f2e45292f26252a12d7d02..042a4d424fe4cf31d87d033301d3060623512cbc 100644 (file)
@@ -14,7 +14,7 @@ SYNOPSIS
 
 #include <libmemcached/memcached.h>
  
-.. c:function:: memcached_return_t memcached_flush (memcached_st *ptr, time_t expiration);
+.. c:function:: memcached_return_t memcached_flush (memcached_st *ptr, time_t expiration)
 
 Compile and link with -lmemcached
 
@@ -24,7 +24,7 @@ DESCRIPTION
 -----------
 
 
-:c:func::`memcached_flush()` is used to wipe clean the contents of :program:`memcached` servers.
+:c:func::`memcached_flush` is used to wipe clean the contents of :program:`memcached` servers.
 It will either do this immediately or expire the content based on the
 expiration time passed to the method (a value of zero causes an immediate
 flush). The operation is not atomic to multiple servers, just atomic to a
@@ -39,7 +39,7 @@ RETURN
 
 A value of type :c:type:`memcached_return_t` is returned 
 On success that value will be :c:type:`MEMCACHED_SUCCESS`.
-Use :c:type:`memcached_strerror()` to translate this value to a printable string.
+Use :c:type:`memcached_strerror` to translate this value to a printable string.
 
 ----
 HOME
index 1a6088c26cf307f7d1fc6631d033efbef5852472..888c9254420ed6d1072d4a3faa095e9e87311229 100644 (file)
@@ -13,7 +13,7 @@ SYNOPSIS
 
 #include <libmemcached/memcached.h>
  
-.. c:function:: memcached_return_t memcached_flush_buffers (memcached_st *ptr);
+.. c:function:: memcached_return_t memcached_flush_buffers (memcached_st *ptr)
 
 Compile and link with -lmemcached
 
@@ -23,7 +23,7 @@ DESCRIPTION
 -----------
 
 
-:c:func:`memcached_flush_buffers()` is used in conjunction with 
+:c:func:`memcached_flush_buffers` is used in conjunction with 
 :c:type:`MEMCACHED_BEHAVIOR_BUFFER_REQUESTS` (see memcached_behavior(3)) to flush all buffers by sending the buffered commands to the server for processing.
 
 
@@ -34,7 +34,7 @@ RETURN
 
 A value of type :c:type:`memcached_return_t` is returned
 On success that value will be :c:type:`MEMCACHED_SUCCESS`.
-Use :c:func:`memcached_strerror()` to translate this value to a printable 
+Use :c:func:`memcached_strerror` to translate this value to a printable 
 string.
 
 
index 3da05dfd87a7f48551af4986c1a88ebb3cc02797..5b835df9e6a48c1d710351abf533e8e3e3951cfe 100644 (file)
@@ -13,10 +13,33 @@ SYNOPSIS
 
 
 #include <libmemcached/memcached.h>
+
+.. c:type:: memcached_hash_t
  
-.. c:function:: uint32_t memcached_generate_hash_value (const char *key, size_t key_length, memcached_hash_t hash_algorithm);
+.. c:function:: uint32_t memcached_generate_hash_value (const char *key, size_t key_length, memcached_hash_t hash_algorithm)
+
+.. c:function:: uint32_t memcached_generate_hash (memcached_st *ptr, const char *key, size_t key_length)
+
+.. c:type:: MEMCACHED_HASH_DEFAULT
+
+.. c:type:: MEMCACHED_HASH_MD5
+
+.. c:type:: MEMCACHED_HASH_CRC
+
+.. c:type:: MEMCACHED_HASH_FNV1_64
+
+.. c:type:: MEMCACHED_HASH_FNV1A_64
+
+.. c:type:: MEMCACHED_HASH_FNV1_32
+
+.. c:type:: MEMCACHED_HASH_FNV1A_32
+
+.. c:type:: MEMCACHED_HASH_JENKINS
+
+.. c:type:: MEMCACHED_HASH_MURMUR
+
+.. c:type:: MEMCACHED_HASH_HSIEH
 
-.. c:function:: uint32_t memcached_generate_hash (memcached_st *ptr, const char *key, size_t key_length);
 
 Compile and link with -lmemcachedutil -lmemcached
 
@@ -26,17 +49,17 @@ DESCRIPTION
 -----------
 
 
-:c:func:`memcached_generate_hash_value()` allows you to hash a key using one of
+:c:func:`memcached_generate_hash_value` allows you to hash a key using one of
 the hash functions defined in the library. This method is provided for
 the convenience of higher-level language bindings and is not necessary
 for normal memcache operations.
 
 The allowed hash algorithm constants are listed in the manpage for
-:c:func:`memcached_behavior_set()`.
+:c:func:`memcached_behavior_set`.
 
-:c:func:`memcached_generate_hash()` takes a :c:type:`memcached_st` struture 
+:c:func:`memcached_generate_hash` takes a :c:type:`memcached_st` struture 
 and produces the hash value that would have been generated based on the 
-defaults of the :c:type:`memcached_st structure`.
+defaults of :c:type:`memcached_st`.
 
 As of version 0.36 all hash methods have been placed into the library
 libhashkit(3) which is linked with libmemcached(3). For more information please see its documentation.
index 4285b3ae370757f25f01509f626ae2a644410ad7..59309669f8533d77e805e27c06476e03f2124480 100644 (file)
@@ -27,6 +27,8 @@ SYNOPSIS
 
 .. c:function:: memcached_return_t memcached_mget_execute_by_key (memcached_st *ptr, const char *group_key, size_t group_key_length, const char * const *keys, const size_t *key_length, size_t number_of_keys, memcached_execute_fn *callback, void *context, uint32_t number_of_callbacks)
 
+.. c:type:: memcached_return_t (*memcached_execute_fn)(const memcached_st *ptr, memcached_result_st *result, void *context)
+
 Compile and link with -lmemcached
 
 
@@ -35,36 +37,36 @@ DESCRIPTION
 -----------
 
 
-:c:func:`memcached_get()` is used to fetch an individual value from the server. 
+:c:func:`memcached_get` is used to fetch an individual value from the server. 
 You must pass in a key and its length to fetch the object. You must supply
 three pointer variables which will give you the state of the returned
 object.  A :c:type:`uint32_t` pointer to contain whatever flags you stored with the value, a :c:type:`size_t` pointer which will be filled with size of of 
 the object, and a :c:type:`memcached_return_t` pointer to hold any error. The 
 object will be returned upon success and NULL will be returned on failure. Any 
-object returned by :c:func:`memcached_get()` must be released by the caller 
+object returned by :c:func:`memcached_get` must be released by the caller 
 application.
 
-:c:func:`memcached_mget()` is used to select multiple keys at once. For 
+:c:func:`memcached_mget` is used to select multiple keys at once. For 
 multiple key operations it is always faster to use this function. This function always works asynchronously. 
 
-To retrieve data after a successful execution of :c:func:`memcached_mget()`, you will need to
-call :c:func:`memcached_fetch_result()`.  You should continue to call this function until 
+To retrieve data after a successful execution of :c:func:`memcached_mget`, you will need to
+call :c:func:`memcached_fetch_result`.  You should continue to call this function until 
 it returns a NULL (i.e. no more values). If you need to quit in the middle of a
-:c:func:`memcached_mget()` call, you can execute a :c:func:`memcached_quit()`, those this is not required.
+:c:func:`memcached_mget` call, you can execute a :c:func:`memcached_quit`, those this is not required.
 
-:c:func:`memcached_fetch_result()` is used to fetch an individual value from the server. :c:func:`memcached_mget()` must always be called before using this method.  
+:c:func:`memcached_fetch_result` is used to fetch an individual value from the server. :c:func:`memcached_mget` must always be called before using this method.  
 You must pass in a key and its length to fetch the object. You must supply
 three pointer variables which will give you the state of the returned
 object.  A :c:type:`uint32_t` pointer to contain whatever flags you stored with the value, a :c:type:`size_t` pointer which will be filled with size of of the 
 object, and a :c:type:`memcached_return_t` pointer to hold any error. The 
-object will be returned upon success and NULL will be returned on failure. :c:type:`MEMCACHD_END` is returned by the \*error value when all objects that have been found are returned. The final value upon :c:type:`MEMCACHED_END` is null. 
+object will be returned upon success and NULL will be returned on failure. :c:type:`MEMCACHED_END` is returned by the \*error value when all objects that have been found are returned. The final value upon :c:type:`MEMCACHED_END` is null. 
 
-:c:func:`memcached_fetch_result()` is used to return a :c:type:`memcached_result_st` structure from a memcached server. The result object is forward compatible 
+:c:func:`memcached_fetch_result` is used to return a :c:type:`memcached_result_st` structure from a memcached server. The result object is forward compatible 
 with changes to the server. For more information please refer to the 
 :c:type:`memcached_result_st` help. This function will dynamically allocate a 
 result structure for you if you do not pass one to the function.
 
-:c:func:`memcached_fetch_execute()` is a callback function for result sets. 
+:c:func:`memcached_fetch_execute` is a callback function for result sets. 
 Instead of returning the results to you for processing, it passes each of the
 result sets to the list of functions you provide. It passes to the function
 a :c:type:`memcached_st` that can be cloned for use in the called 
@@ -74,18 +76,18 @@ a memory reference you supply the calling function. Currently only one value
 is being passed to each function call. In the future there will be an option 
 to allow this to be an array.
 
-:c:func:`memcached_mget_execute()` and :c:func:`memcached_mget_execute_by_key()`
-is similar to :c:func:`memcached_mget()`, but it may trigger the supplied 
+:c:func:`memcached_mget_execute` and :c:func:`memcached_mget_execute_by_key`
+is similar to :c:func:`memcached_mget`, but it may trigger the supplied 
 callbacks with result sets while sending out the queries. If you try to 
-perform a really large multiget with :c:func:`memcached_mget()` you may 
+perform a really large multiget with :c:func:`memcached_mget` you may 
 encounter a deadlock in the OS kernel (it will fail to write data to the 
-socket because the input buffer is full). :c:func:`memcached_mget_execute()
+socket because the input buffer is full). :c:func:`memcached_mget_execute` 
 solves this problem by processing some of the results before continuing 
 sending out requests. Please note that this function is only available in 
 the binary protocol.
 
-:c:func:`memcached_get_by_key()` and :c:func:`memcached_mget_by_key()` behave 
-in a similar nature as :c:func:`memcached_get()` and :c:func:`memcached_mget()`.
+:c:func:`memcached_get_by_key` and :c:func:`memcached_mget_by_key` behave 
+in a similar nature as :c:func:`memcached_get` and :c:func:`memcached_mget`.
 The difference is that they take a master key that is used for determining 
 which server an object was stored if key partitioning was used for storage.
 
@@ -99,17 +101,17 @@ RETURN
 ------
 
 
-All objects retrieved via :c:func:`memcached_get()` or :c:func:`memcached_get_by_key()` must be freed with :manpage:`free(3)`.
+All objects retrieved via :c:func:`memcached_get` or :c:func:`memcached_get_by_key` must be freed with :manpage:`free(3)`.
 
-:c:func:`memcached_get()` will return NULL on 
+:c:func:`memcached_get` will return NULL on 
 error. You must look at the value of error to determine what the actual error 
 was.
 
-:c:func:`memcached_fetch_execute()` return :c:type:`MEMCACHED_SUCCESS` if
+:c:func:`memcached_fetch_execute` return :c:type:`MEMCACHED_SUCCESS` if
 all keys were successful. :c:type:`MEMCACHED_NOTFOUND` will be return if no
 keys at all were found.
 
-:c:func:`memcached_fetch_result()` sets error
+:c:func:`memcached_fetch_result` sets error
 to :c:type:`MEMCACHED_END` upon successful conclusion.
 :c:type:`MEMCACHED_NOTFOUND` will be return if no keys at all were found.
 
index ce8af386d65baa587b44945d0c9012cc8e32a9bc..12a4ce5e0a77a9b16852093d8fc8dcfcd2615559 100644 (file)
@@ -13,19 +13,19 @@ SYNOPSIS
 
 #include <libmemcached/memcached.h>
 
-.. c:function:: memcached_return_t memcached_set_memory_allocators (memcached_st *ptr, memcached_malloc_fn mem_malloc, memcached_free_fn mem_free, memcached_realloc_fn mem_realloc, memcached_calloc_fn mem_calloc, void *context);
+.. c:function:: memcached_return_t memcached_set_memory_allocators (memcached_st *ptr, memcached_malloc_fn mem_malloc, memcached_free_fn mem_free, memcached_realloc_fn mem_realloc, memcached_calloc_fn mem_calloc, void *context)
 
-.. c:function:: void memcached_get_memory_allocators (memcached_st *ptr, memcached_malloc_fn *mem_malloc, memcached_free_fn *mem_free, memcached_realloc_fn *mem_realloc, memcached_calloc_fn *mem_calloc);
+.. c:function:: void memcached_get_memory_allocators (memcached_st *ptr, memcached_malloc_fn *mem_malloc, memcached_free_fn *mem_free, memcached_realloc_fn *mem_realloc, memcached_calloc_fn *mem_calloc)
 
-.. c:function:: void * memcached_get_memory_allocators_context(const memcached_st *ptr);
+.. c:function:: void * memcached_get_memory_allocators_context(const memcached_st *ptr)
 
-.. c:function:: void * (*memcached_malloc_fn) (memcached_st *ptr, const size_t size, void *context);
+.. c:function:: void * (*memcached_malloc_fn) (memcached_st *ptr, const size_t size, void *context)
 
-.. c:function:: void * (*memcached_realloc_fn) (memcached_st *ptr, void *mem, const size_t size, void *context);
+.. c:function:: void * (*memcached_realloc_fn) (memcached_st *ptr, void *mem, const size_t size, void *context)
 
-.. c:function:: void (*memcached_free_fn) (memcached_st *ptr, void *mem, void *context);
+.. c:function:: void (*memcached_free_fn) (memcached_st *ptr, void *mem, void *context)
 
-.. c:function:: void * (*memcached_calloc_fn) (memcached_st *ptr, size_t nelem, const size_t elsize, void *context);
+.. c:function:: void * (*memcached_calloc_fn) (memcached_st *ptr, size_t nelem, const size_t elsize, void *context)
 
 Compile and link with -lmemcached
 
@@ -39,18 +39,18 @@ DESCRIPTION
 libmemcached(3) allows you to specify your own memory allocators, optimized
 for your application. This enables libmemcached to be used inside of applications that have their own malloc implementation.
 
-:c:func:`memcached_set_memory_allocators()` is used to set the memory 
+:c:func:`memcached_set_memory_allocators` is used to set the memory 
 allocators used by the memcached instance specified by ptr. Please note that 
 you cannot override only one of the memory allocators, you have to specify a 
 complete new set if you want to override one of them. All of the memory 
 allocation functions should behave as specified in the C99 standard. Specify 
 NULL as all functions to reset them to the default values.
 
-:c:func:`memcached_get_memory_allocators()` is used to get the currently used 
+:c:func:`memcached_get_memory_allocators` is used to get the currently used 
 memory allocators by a mamcached handle.
 
-:c:func:`memcached_get_memory_allocators_context()` returns the void \* that 
-was passed in during the call to :c:func:`memcached_set_memory_allocators()`.
+:c:func:`memcached_get_memory_allocators_context` returns the void \* that 
+was passed in during the call to :c:func:`memcached_set_memory_allocators`.
 
 The first argument to the memory allocator functions is a pointer to a
 memcached structure, the is passed as const and you will need to clone
@@ -72,7 +72,7 @@ RETURN
 ------
 
 
-:c:func:`memcached_set_memory_allocators()` return :c:type:`MEMCACHED_SUCCESS` 
+:c:func:`memcached_set_memory_allocators` return :c:type:`MEMCACHED_SUCCESS` 
 upon success, and :c:type:`MEMCACHED_FAILURE` if you don't pass a complete set 
 of function pointers.
 
index 3f8882f83661ab51d7fd689933717d58552ee9f8..a3080788f4bb919a385dd14123f30b717cee842b 100644 (file)
@@ -14,26 +14,26 @@ SYNOPSIS
 
 .. c:function:: memcached_pool_st* memcached_pool_create(memcached_st* mmc, int initial, int max)
 .. deprecated:: 0.46
-   Use :c:func:`memcached_pool()`
+   Use :c:func:`memcached_pool`
  
 .. c:function:: memcached_st* memcached_pool_destroy(memcached_pool_st* pool)
  
 .. c:function:: memcached_st* memcached_pool_pop(memcached_pool_st* pool, bool block, memcached_return_t *rc)
 .. deprecated:: 0.53
-   Use :c:func:`memcached_pool_fetch()`
+   Use :c:func:`memcached_pool_fetch`
 
-.. c:function:: memcached_st* memcached_pool_fetch(memcached_pool_st*, struct timespec* relative_time, memcached_return_t* rc);
+.. c:function:: memcached_st* memcached_pool_fetch(memcached_pool_st*, struct timespec* relative_time, memcached_return_t* rc)
 
 .. versionadded:: 0.53
-   Synonym for memcached_pool_pop()
+   Synonym for memcached_pool_pop
 
 .. c:function:: memcached_return_t memcached_pool_push(memcached_pool_st* pool, memcached_st *mmc)
 .. deprecated:: 0.53
-   Use :c:func:`memcached_pool_push()`
+   Use :c:func:`memcached_pool_push`
 
-.. c:function:: memcached_return_t memcached_pool_release(memcached_pool_st* pool, memcached_st* mmc);
+.. c:function:: memcached_return_t memcached_pool_release(memcached_pool_st* pool, memcached_st* mmc)
 .. versionadded:: 0.53
-   Synonym for memcached_pool_push().
+   Synonym for memcached_pool_push.
  
 .. c:function:: memcached_return_t memcached_pool_behavior_set(memcached_pool_st *pool, memcached_behavior_t flag, uint64_t data)
  
@@ -46,41 +46,41 @@ DESCRIPTION
 -----------
 
 
-:c:func:`memcached_pool()` is used to create a connection pool of objects you 
+:c:func:`memcached_pool` is used to create a connection pool of objects you 
 may use to remove the overhead of using memcached_clone for short lived
 :c:type:`memcached_st` objects. Please see :doc:`libmemcached_configuration` for details on the format of the configuration string.
 
-:c:func:`memcached_pool_destroy()` is used to destroy the connection pool
-created with :c:func:`memcached_pool_create()` and release all allocated
+:c:func:`memcached_pool_destroy` is used to destroy the connection pool
+created with :c:func:`memcached_pool_create` and release all allocated
 resources. It will return the pointer to the :c:type:`memcached_st` structure
-passed as an argument to :c:func:`memcached_pool_create()`, and returns the ownership of the pointer to the caller when created with :c:func:`memcached_pool_create()`, otherwise NULL is returned..
+passed as an argument to :c:func:`memcached_pool_create`, and returns the ownership of the pointer to the caller when created with :c:func:`memcached_pool_create`, otherwise NULL is returned..
 
-:c:func:`memcached_pool_fetch()` is used to fetch a connection structure from the
+:c:func:`memcached_pool_fetch` is used to fetch a connection structure from the
 connection pool. The relative_time argument specifies if the function should
 block and wait for a connection structure to be available if we try
 to exceed the maximum size. You need to specify time in relative time.
 
-:c:func:`memcached_pool_release()` is used to return a connection structure back to the pool.
+:c:func:`memcached_pool_release` is used to return a connection structure back to the pool.
 
-:c:func:`memcached_pool_behavior_get()` and :c:func:`memcached_pool_behavior_set()` is used to get/set behavior flags on all connections in the pool.
+:c:func:`memcached_pool_behavior_get` and :c:func:`memcached_pool_behavior_set` is used to get/set behavior flags on all connections in the pool.
 
-Both :c:func:`memcached_pool_release()` and :c:func:`memcached_pool_fetch()` are thread safe.
+Both :c:func:`memcached_pool_release` and :c:func:`memcached_pool_fetch` are thread safe.
 
 ------
 RETURN
 ------
 
-:c:func:`memcached_pool_destroy()` returns the pointer (and ownership) to the :c:type:`memcached_st` structure used to create the pool. If connections are in use it returns NULL.
+:c:func:`memcached_pool_destroy` returns the pointer (and ownership) to the :c:type:`memcached_st` structure used to create the pool. If connections are in use it returns NULL.
 
-:c:func:`memcached_pool_pop()` returns a pointer to a :c:type:`memcached_st` structure from the pool (or NULL if an allocation cannot be satisfied).
+:c:func:`memcached_pool_pop` returns a pointer to a :c:type:`memcached_st` structure from the pool (or NULL if an allocation cannot be satisfied).
 
-:c:func:`memcached_pool_release()` returns :c:type:`MEMCACHED_SUCCESS` upon success.
+:c:func:`memcached_pool_release` returns :c:type:`MEMCACHED_SUCCESS` upon success.
 
-:c:func:`memcached_pool_behavior_get()` and :c:func:`memcached_pool_behavior_get()` returns :c:type:`MEMCACHED_SUCCESS` upon success.
+:c:func:`memcached_pool_behavior_get` and :c:func:`memcached_pool_behavior_get` returns :c:type:`MEMCACHED_SUCCESS` upon success.
 
 If any methods returns MEMCACHED_IN_PROGRESS then a lock on the pool could not be obtained. If any of the parameters passed to any of these functions is invalid, MEMCACHED_INVALID_ARGUMENTS will be returned.
 
-memcached_pool_fetch() may return MEMCACHED_TIMEOUT if a timeout occurs while waiting for a free memcached_st. MEMCACHED_NOTFOUND if no memcached_st was available.
+memcached_pool_fetch may return MEMCACHED_TIMEOUT if a timeout occurs while waiting for a free memcached_st. MEMCACHED_NOTFOUND if no memcached_st was available.
 
 
 ----
index 8377f63ce51c0c98abf4fd1b3fc68ef3ea5ce0c3..b94832ec9d8259b42ba64cb339284117d951e42c 100644 (file)
@@ -10,7 +10,7 @@ SYNOPSIS
 
 #include <libmemcached/memcached.h>
  
-.. c:function:: void memcached_quit (memcached_st *ptr);
+.. c:function:: void memcached_quit (memcached_st *ptr)
 
 Compile and link with -lmemcached
 
@@ -19,14 +19,14 @@ DESCRIPTION
 -----------
 
 
-:c:func:`memcached_quit()` will disconnect you from all currently connected 
-servers. It will also reset the state of the connection (ie, any :c:func:`memcached_fetch()` you are in the middle of will be terminated). This function is 
-called automatically when you call :c:func:`memcached_free()` on the :c:type:`memcached_st` structure.
+:c:func:`memcached_quit` will disconnect you from all currently connected 
+servers. It will also reset the state of the connection (ie, any :c:func:`memcached_fetch` you are in the middle of will be terminated). This function is 
+called automatically when you call :c:func:`memcached_free` on the :c:type:`memcached_st` structure.
 
 You do not need to call this on your own. All operations to change server
 hashes and parameters will handle connections to the server for you. This
 function is provided mainly so that you can timeout your connections or
-reset connections during the middle of a :c:func:`memcached_fetch()`.
+reset connections during the middle of a :c:func:`memcached_fetch`.
 
 
 ------
@@ -34,9 +34,9 @@ RETURN
 ------
 
 
-A value of type :c:type:`memcached_return` is returned
-On success that value will be :c:type:`MEMCACHED_SUCCESS`.
-Use :c:func:`memcached_strerror()` to translate this value to a printable string.
+A value of type :c:type:`memcached_return_t` is returned On success that value
+will be :c:type:`MEMCACHED_SUCCESS`.  Use :c:func:`memcached_strerror` to
+translate this value to a printable string.
 
 
 ----
index 295b2229ebb669a2ede77e227de2a8d7723e50da..3cd9afe2bd873060ebe88a79c5de3cb3280d56f1 100644 (file)
@@ -10,21 +10,21 @@ SYNOPSIS
 
 .. c:type:: memcached_result_st
 
-.. c:function:: memcached_result_st * memcached_result_create (memcached_st *ptr, memcached_result_st *result);
+.. c:function:: memcached_result_st * memcached_result_create (memcached_st *ptr, memcached_result_st *result)
 
-.. c:function:: void memcached_result_free (memcached_result_st *result);
+.. c:function:: void memcached_result_free (memcached_result_st *result)
 
-.. c:function:: const char * memcached_result_key_value (memcached_result_st *result);
+.. c:function:: const char * memcached_result_key_value (memcached_result_st *result)
 
-.. c:function:: size_t memcached_result_key_length (const memcached_result_st *result);
+.. c:function:: size_t memcached_result_key_length (const memcached_result_st *result)
 
-.. c:function:: const char *memcached_result_value (memcached_result_st *ptr);
+.. c:function:: const char *memcached_result_value (memcached_result_st *ptr)
 
-.. c:function:: size_t memcached_result_length (const memcached_result_st *ptr);
+.. c:function:: size_t memcached_result_length (const memcached_result_st *ptr)
 
 .. c:function:: uint32_t memcached_result_flags (const memcached_result_st *result)
 
-.. c:function:: uint64_t memcached_result_cas (const memcached_result_st *result);
+.. c:function:: uint64_t memcached_result_cas (const memcached_result_st *result)
 
 .. c:function:: memcached_return_t memcached_result_set_value (memcached_result_st *ptr, const char *value, size_t length)
 
@@ -52,39 +52,40 @@ objects over char \* return functions.
 The structure of :c:type:`memcached_result_st` has been encapsulated, you should
 not write code to directly access members of the structure.
 
-:c:func:`memcached_result_create()` will either allocate memory for a
+:c:func:`memcached_result_create` will either allocate memory for a
 :c:type:`memcached_result_st` or will initialize a structure passed to it.
 
-:c:func:`memcached_result_free()` will deallocate any memory attached to the
+:c:func:`memcached_result_free` will deallocate any memory attached to the
 structure. If the structure was also allocated, it will deallocate it.
 
-:c:func:`memcached_result_key_value()` returns the key value associated with the
+:c:func:`memcached_result_key_value` returns the key value associated with the
 current result object.
 
-:c:func:`memcached_result_key_length()` returns the key length associated with 
+:c:func:`memcached_result_key_length` returns the key length associated with 
 the current result object.
 
-:c:func:`memcached_result_value()` returns the result value associated with the
+:c:func:`memcached_result_value` returns the result value associated with the
 current result object.
 
-:c:func:`memcached_result_length()` returns the result length associated with 
+:c:func:`memcached_result_length` returns the result length associated with 
 the current result object.
 
-:c:func:`memcached_result_flags()` returns the flags associated with the
+:c:func:`memcached_result_flags` returns the flags associated with the
 current result object.
 
-:c:func:`memcached_result_cas()` returns the cas associated with the
+:c:func:`memcached_result_cas` returns the cas associated with the
 current result object. This value will only be available if the server
 tests it.
 
-:c:func:`memcached_result_set_value()` takes a byte array and a size and sets
+:c:func:`memcached_result_set_value` takes a byte array and a size and sets
 the result to this value. This function is used for trigger responses.
 
-:c:func:`void memcached_result_set_flags()` takes a result structure and stores
-a new value for the flags field.
+:c:func:`memcached_result_set_flags` takes a result structure and stores a new
+value for the flags field.
 
-:c:func:`void memcached_result_set_expiration(A)` takes a result structure and stores a new value for the expiration field (this is only used by read 
-through triggers).
+:c:func:`memcached_result_set_expiration` takes a result structure and stores
+a new value for the expiration field (this is only used by read through
+triggers).
 
 You may wish to avoid using memcached_result_create(3) with a
 stack based allocation. The most common issues related to ABI safety involve
@@ -97,7 +98,7 @@ RETURN
 
 
 Varies, see particular functions. All structures must have
-:c:func:`memcached_result_free()` called on them for cleanup purposes. Failure 
+:c:func:`memcached_result_free` called on them for cleanup purposes. Failure 
 to do this will result in leaked memory.
 
 
index bd51348bff8d3df3e0f6a612e07f37c4af50bb68..2a2e5699088047cc160a55d103600a363033c83b 100644 (file)
@@ -15,9 +15,9 @@ SYNOPSIS
 
 .. c:function:: const sasl_callback_t *memcached_get_sasl_callbacks(memcached_st *ptr)
 
-.. c:function:: memcached_return memcached_set_sasl_auth_data(memcached_st *ptr, const char *username, const char *password)
+.. c:function:: memcached_return_t memcached_set_sasl_auth_data(memcached_st *ptr, const char *username, const char *password)
 
-.. c:function:: memcached_return memcached_destroy_sasl_auth_data(memcached_st *ptr)
+.. c:function:: memcached_return_t memcached_destroy_sasl_auth_data(memcached_st *ptr)
 
 Compile and link with -lmemcached
 
@@ -34,16 +34,13 @@ libsasl to perform SASL authentication.
 Please note that SASL requires the memcached binary protocol, and you have
 to specify the callbacks before you connect to the server.
 
-:c:func:`memcached_set_sasl_auth_data()` is a helper function defining
+:c:func:`memcached_set_sasl_auth_data` is a helper function defining
 the basic functionality for you, but it will store the username and password
 in memory. If you choose to use this method you have to call
 :c:type:`memcached_destroy_sasl_auth_data` before calling 
 :c:type:`memcached_free` to avoid a memory leak. You should NOT call 
 :c:type:`memcached_destroy_sasl_auth_data` if you specify your own callback 
-function with :c:func:`memcached_set_sasl_callbacks()`.
-
-You as a client user have to initialize libsasl by using :c:type:`sasl_client_init` before enabling it in libmemcached, and you have to shut down libsasl by
-calling :c:func:`sasl_done()` when you are done using SASL from libmemcached.
+function with :c:func:`memcached_set_sasl_callbacks`.
 
 
 ------
@@ -51,8 +48,9 @@ RETURN
 ------
 
 
-:c:func:`memcached_get_sasl_callbacks()` returns the callbacks currently used
-by this memcached handle. :c:func:`memcached_get_sasl_set_auth_data()` returns :c:type:`MEMCACHED_SUCCESS` upon success.
+:c:func:`memcached_get_sasl_callbacks` returns the callbacks currently used by
+this memcached handle. :c:func:`memcached_set_sasl_auth_data` returns
+:c:type:`MEMCACHED_SUCCESS` upon success.
 
 
 ----
index 9a8c8fc2d1d1a27bc2f9f62c41586e5473779fc2..6bca49b8f5dd8ae82cb8ddbc23eabc51836968c6 100644 (file)
@@ -13,11 +13,15 @@ SYNOPSIS
 
 .. c:type:: memcached_server_instance_st
 
+.. c:type:: memcached_server_list_st
+
+.. c:type:: memcached_server_st
+
 .. c:function:: const memcached_server_instance_st memcached_server_list (memcached_st *ptr)
 
 .. c:function:: void memcached_server_list_free (memcached_server_list_st list)
  
-.. c:function:: memcached_server_list_st memcached_server_list_append (memcached_server_list_st list, const char *hostname, unsigned int port, memcached_return_t *error)
+.. c:function:: memcached_server_list_st memcached_server_list_append (memcached_server_list_st list, const char *hostname, in_port_t port, memcached_return_t *error)
  
 .. c:function:: uint32_t memcached_server_list_count (memcached_server_list_st list)
  
@@ -26,6 +30,8 @@ SYNOPSIS
 .. c:function:: void memcached_server_error_reset (memcached_server_instance_st list)
 .. deprecated:: 0.39
    
+.. c:function:: void memcached_servers_parse ()
+.. deprecated:: 0.39
 
 Compile and link with -lmemcached
 
@@ -40,18 +46,18 @@ libmemcached(3) operates on a list of hosts which are stored in
 directly. Functions are provided to modify these structures (and more can be
 added, just ask!).
 
-:c:func:`memcached_server_list()` is used to provide an array of all defined hosts. This was incorrectly documented as "requiring free()" up till version 0.39.
+:c:func:`memcached_server_list` is used to provide an array of all defined hosts. This was incorrectly documented as "requiring free" up till version 0.39.
 
-:c:func:`memcached_server_list_free()` deallocates all memory associated with the array of :c:type:`memcached_server_st` that you passed to it.
+:c:func:`memcached_server_list_free` deallocates all memory associated with the array of :c:type:`memcached_server_st` that you passed to it.
 
-:c:func:`memcached_server_list_append()` adds a server to the end of a
+:c:func:`memcached_server_list_append` adds a server to the end of a
 :c:type:`memcached_server_st` array. On error null will be returned and the
 :c:type:`memcached_return_t` pointer you passed into the function will be set with the appropriate error. If the value of port is zero, it is set to the default
 port of a memcached server.
 
-DEPRECATED :c:func:`memcached_servers_parse()`, please see :c:func:`memcached()`
+DEPRECATED :c:func:`memcached_servers_parse`, please see :c:func:`memcached`
 
-:c:func:`memcached_server_error()` can be used to look at the text of the last error message sent by the server to to the client.
+:c:func:`memcached_server_error` can be used to look at the text of the last error message sent by the server to to the client.
 
 Before version 0.39 theses functions used a memcache_server_st \*. In 0.39
 memcached_server_st \* was aliased to :c:type:`memcached_server_list_st`. This was done for a style reason to help clean up some concepts in the code.
index 6ec518148cd300ac8e41cb2b6ea1481ffb98962a..e86dad81e6af543347295daa8d3b791da0e7ed0f 100644 (file)
@@ -40,38 +40,38 @@ these hosts determine routing to keys. Functions are provided to add keys to
 memcached_st structures. To manipulate lists of servers see
 memcached_server_st(3).
 
-:c:func:`memcached_server_count()` provides you a count of the current number of
+:c:func:`memcached_server_count` provides you a count of the current number of
 servers being used by a :c:type:`memcached_st` structure.
 
-:c:func:`memcached_server_add()` pushes a single TCP server into the :c:type:`memcached_st` structure. This server will be placed at the end. Duplicate servers
+:c:func:`memcached_server_add` pushes a single TCP server into the :c:type:`memcached_st` structure. This server will be placed at the end. Duplicate servers
  are allowed, so duplication is not checked. Executing this function with the :c:type:`MEMCACHED_BEHAVIOR_USE_UDP` behavior set will result in a :c:type:`MEMCACHED_INVALID_HOST_PROTOCOL`.
 
-:c:func:`memcached_server_add_udp()` pushes a single UDP server into the :c:type:`memcached_st` structure. This server will be placed at the end. Duplicate 
+:c:func:`memcached_server_add_udp` pushes a single UDP server into the :c:type:`memcached_st` structure. This server will be placed at the end. Duplicate 
 servers are allowed, so duplication is not checked. Executing this function with out setting the :c:type:`MEMCACHED_BEHAVIOR_USE_UDP` behavior will result in a
 :c:type:`MEMCACHED_INVALID_HOST_PROTOCOL`.
 
-:c:func:`memcached_server_add_unix_socket()` pushes a single UNIX socket into the :c:type:`memcached_st` structure. This UNIX socket will be placed at the end.
+:c:func:`memcached_server_add_unix_socket` pushes a single UNIX socket into the :c:type:`memcached_st` structure. This UNIX socket will be placed at the end.
 Duplicate servers are allowed, so duplication is not checked. The length
 of the filename must be one character less than :c:type:`MEMCACHED_MAX_HOST_LENGTH`.
 
-:c:func:`memcached_server_push()` pushes an array of :c:type:`memcached_server_st` into the :c:type:`memcached_st` structure. These servers will be placed at 
+:c:func:`memcached_server_push` pushes an array of :c:type:`memcached_server_st` into the :c:type:`memcached_st` structure. These servers will be placed at 
 the end. Duplicate servers are allowed, so duplication is not checked. A
 copy is made of structure so the list provided (and any operations on
 the list) are not saved.
 
-:c:func:`memcached_server_by_key()` allows you to provide a key and retrieve the
+:c:func:`memcached_server_by_key` allows you to provide a key and retrieve the
 server which would be used for assignment.
 
-:c:func:`memcached_server_get_last_disconnect()` returns a pointer to the last 
+:c:func:`memcached_server_get_last_disconnect` returns a pointer to the last 
 server for which there was a connection problem. It does not mean this 
 particular server is currently dead but if the library is reporting a server 
 is, the returned server is a very good candidate.
 
-:c:func:`memcached_server_cursor()` takes a memcached_st and loops through the 
+:c:func:`memcached_server_cursor` takes a memcached_st and loops through the 
 list of hosts currently in the cursor calling the list of callback 
 functions provided. You can optionally pass in a value via 
 context which will be provided to each callback function. An error
-return from any callback will terminate the loop. :c:func:`memcached_server_cursor()` is passed the original caller :c:type:`memcached_st` in its current state.
+return from any callback will terminate the loop. :c:func:`memcached_server_cursor` is passed the original caller :c:type:`memcached_st` in its current state.
 
 
 ------
index 29d8d24176aa6a744394d6c411a1564fd71387ae..6cbebe062f9b46f5af73718050c3af14e90c6a01 100644 (file)
@@ -12,17 +12,17 @@ SYNOPSIS
 
 #include <libmemcached/memcached.h>
  
-.. c:function:: memcached_return_t memcached_set (memcached_st *ptr, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags);
+.. c:function:: memcached_return_t memcached_set (memcached_st *ptr, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags)
 
-.. c:function:: memcached_return_t memcached_add (memcached_st *ptr, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags);
+.. c:function:: memcached_return_t memcached_add (memcached_st *ptr, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags)
 
-.. c:function:: memcached_return_t memcached_replace (memcached_st *ptr, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags);
+.. c:function:: memcached_return_t memcached_replace (memcached_st *ptr, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags)
 
-.. c:function:: memcached_return_t memcached_set_by_key(memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags);
+.. c:function:: memcached_return_t memcached_set_by_key(memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags)
 
-.. c:function:: memcached_return_t memcached_add_by_key(memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags);
+.. c:function:: memcached_return_t memcached_add_by_key(memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags)
 
-.. c:function:: memcached_return_t memcached_replace_by_key(memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags);
+.. c:function:: memcached_return_t memcached_replace_by_key(memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, const char *value, size_t value_length, time_t expiration, uint32_t flags)
 
 Compile and link with -lmemcached
 
@@ -32,32 +32,32 @@ DESCRIPTION
 -----------
 
 
-:c:func:`memcached_set()`, :c:func:`memcached_add()`, and :c:func:`memcached_replace()` are all used to store information on the server. All methods take a key, and its length to store the object. Keys are currently limited to 250 characters when using either a version of memcached(1) which is 1.4 or below, or when using the text protocol. You must supply both a value and a length. Optionally you
+:c:func:`memcached_set`, :c:func:`memcached_add`, and :c:func:`memcached_replace` are all used to store information on the server. All methods take a key, and its length to store the object. Keys are currently limited to 250 characters when using either a version of memcached(1) which is 1.4 or below, or when using the text protocol. You must supply both a value and a length. Optionally you
 store the object. Keys are currently limited to 250 characters by the
 memcached(1) server. You must supply both a value and a length. Optionally you
 may test an expiration time for the object and a 16 byte value (it is meant to be used as a bitmap). "flags" is a 4byte space that is stored alongside of the main value. Many sub libraries make use of this field, so in most cases users should avoid making use of it.
 
-:c:func:`memcached_set()` will write an object to the server. If an object 
+:c:func:`memcached_set` will write an object to the server. If an object 
 already exists it will overwrite what is in the server. If the object does not 
 exist it will be written. If you are using the non-blocking mode this function
 will always return true unless a network error occurs.
 
-:c:func:`memcached_replace()` replaces an object on the server. If the object is not found on the server an error occurs.
+:c:func:`memcached_replace` replaces an object on the server. If the object is not found on the server an error occurs.
 
-:c:func:`memcached_add()` adds an object to the server. If the object is found on the server an error occurs, otherwise the value is stored.
+:c:func:`memcached_add` adds an object to the server. If the object is found on the server an error occurs, otherwise the value is stored.
 
-:c:func:`memcached_cas()` overwrites data in the server as long as the "cas" 
+:c:func:`memcached_cas` overwrites data in the server as long as the "cas" 
 value is still the same in the server. You can get the cas value of a result by 
-calling :c:func:`memcached_result_cas()` on a memcached_result_st(3) structure. At the point 
+calling :c:func:`memcached_result_cas` on a memcached_result_st(3) structure. At the point 
 that this note was written cas is still buggy in memached. Turning on tests
-for it in libmemcached(3) is optional. Please see memcached_set() for 
+for it in libmemcached(3) is optional. Please see memcached_set for 
 information on how to do this.
 
-:c:func:`memcached_set_by_key()`, :c:func:`memcached_add_by_key()`, and :c:func:`memcached_replace_by_key()` methods all behave in a similar method as the non 
+:c:func:`memcached_set_by_key`, :c:func:`memcached_add_by_key`, and :c:func:`memcached_replace_by_key` methods all behave in a similar method as the non 
 key methods. The difference is that they use their group_key parameter to map
 objects to particular servers.
 
-If you are looking for performance, :c:func:`memcached_set()` with non-blocking IO is the fastest way to store data on the server.
+If you are looking for performance, :c:func:`memcached_set` with non-blocking IO is the fastest way to store data on the server.
 
 All of the above functions are testsed with the :c:type:`MEMCACHED_BEHAVIOR_USE_UDP` behavior enabled. However, when using these operations with this behavior 
 on, there are limits to the size of the payload being sent to the server.  
@@ -78,9 +78,9 @@ RETURN
 
 All methods return a value of type :c:type:`memcached_return_t`.
 On success the value will be :c:type:`MEMCACHED_SUCCESS`.
-Use :c:func:`memcached_strerror()` to translate this value to a printable string.
+Use :c:func:`memcached_strerror` to translate this value to a printable string.
 
-For :c:func:`memcached_replace()` and :c:func:`memcached_add()`, :c:type:`MEMCACHED_NOTSTORED` is a legitmate error in the case of a collision.
+For :c:func:`memcached_replace` and :c:func:`memcached_add`, :c:type:`MEMCACHED_NOTSTORED` is a legitmate error in the case of a collision.
 
 
 ----
index 2cd36b6b5cdbe49ddfad1feec9f57fe0d3bea07d..828ef8c6864bd60d120bc6a7772dd724f25e7e5f 100644 (file)
@@ -14,15 +14,19 @@ SYNOPSIS
 
 #include <libmemcached/memcached.h>
 
-.. c:function:: memcached_stat_st *memcached_stat (memcached_st *ptr, char *args, memcached_return_t *error);
+.. c:type:: memcached_stat_st
 
-.. c:function:: memcached_return_t memcached_stat_servername (memcached_stat_st *stat, char *args, const char *hostname, unsigned int port);
+.. c:type:: memcached_return_t (*memcached_stat_fn)(memcached_server_instance_st server, const char *key, size_t key_length, const char *value, size_t value_length, void *context)
 
-.. c:function:: char * memcached_stat_get_value (memcached_st *ptr, memcached_stat_st *stat, const char *key, memcached_return_t *error);
+.. c:function:: memcached_stat_st *memcached_stat (memcached_st *ptr, char *args, memcached_return_t *error)
 
-.. c:function:: char ** memcached_stat_get_keys (memcached_st *ptr, memcached_stat_st *stat, memcached_return_t *error);
+.. c:function:: memcached_return_t memcached_stat_servername (memcached_stat_st *stat, char *args, const char *hostname, in_port_t port)
 
-.. c:function:: memcached_return_t memcached_stat_execute (memcached_st *memc, const char *args, memcached_stat_fn func, void *context);
+.. c:function:: char * memcached_stat_get_value (memcached_st *ptr, memcached_stat_st *stat, const char *key, memcached_return_t *error)
+
+.. c:function:: char ** memcached_stat_get_keys (memcached_st *ptr, memcached_stat_st *stat, memcached_return_t *error)
+
+.. c:function:: memcached_return_t memcached_stat_execute (memcached_st *memc, const char *args, memcached_stat_fn func, void *context)
 
 Compile and link with -lmemcached
 
@@ -33,20 +37,20 @@ DESCRIPTION
 
 libmemcached(3) has the ability to query a memcached server (or collection
 of servers) for their current state. Queries to find state return a
-:c:type:`memcached_stat_st` structure. You are responsible for freeing this structure. While it is possible to access the structure directly it is not advisable. :c:func:`memcached_stat_get_value()` has been provided to query the structure.
+:c:type:`memcached_stat_st` structure. You are responsible for freeing this structure. While it is possible to access the structure directly it is not advisable. :c:func:`memcached_stat_get_value` has been provided to query the structure.
 
-:c:func:`memcached_stat_execute()` uses the servers found in :c:type:`memcached_stat_st` and executes a "stat" command on each server. args is an optional argument that can be passed in to modify the behavior of "stats". You will need to supply a callback function that will be supplied each pair of values returned by
+:c:func:`memcached_stat_execute` uses the servers found in :c:type:`memcached_stat_st` and executes a "stat" command on each server. args is an optional argument that can be passed in to modify the behavior of "stats". You will need to supply a callback function that will be supplied each pair of values returned by
 the memcached server.
 
-:c:func:`memcached_stat()` fetches an array of :c:type:`memcached_stat_st` structures containing the state of all available memcached servers. The return value must be freed by the calling application. If called with the :c:type:`MEMCACHED_BEHAVIOR_USE_UDP` behavior set, a NULL value is returned and the error parameter is set to :c:type:`MEMCACHED_NOT_SUPPORTED`.
+:c:func:`memcached_stat` fetches an array of :c:type:`memcached_stat_st` structures containing the state of all available memcached servers. The return value must be freed by the calling application. If called with the :c:type:`MEMCACHED_BEHAVIOR_USE_UDP` behavior set, a NULL value is returned and the error parameter is set to :c:type:`MEMCACHED_NOT_SUPPORTED`.
 
-:c:func:`memcached_stat_servername()` can be used standalone without a :c:type:`memcached_st` to obtain the state of a particular server.  "args" is used to define a particular state object (a list of these are not provided for by either
-the :c:func:`memcached_stat_get_keys()` call nor are they defined in the memcached protocol). You must specify the hostname and port of the server you want to
+:c:func:`memcached_stat_servername` can be used standalone without a :c:type:`memcached_st` to obtain the state of a particular server.  "args" is used to define a particular state object (a list of these are not provided for by either
+the :c:func:`memcached_stat_get_keys` call nor are they defined in the memcached protocol). You must specify the hostname and port of the server you want to
 obtain information on.
 
-:c:func:`memcached_stat_get_value()` returns the value of a particular state key. You specify the key you wish to obtain.  The key must be null terminated.
+:c:func:`memcached_stat_get_value` returns the value of a particular state key. You specify the key you wish to obtain.  The key must be null terminated.
 
-:c:func:`memcached_stat_get_keys()` returns a list of keys that the server has state objects on. You are responsible for freeing this list.
+:c:func:`memcached_stat_get_keys` returns a list of keys that the server has state objects on. You are responsible for freeing this list.
 
 A command line tool, memstat(1), is provided so that you do not have to write
 an application to do this.
index 6f8f78214a2124d7f025fedcb0c376400916bc52..07023b8d94cedfaac0a4d1ad80f1ca9b43e5f842 100644 (file)
@@ -11,7 +11,7 @@ SYNOPSIS
 
 #include <libmemcached/memcached.h>
 
-.. c:function:: const char * memcached_strerror (memcached_st *ptr, memcached_return_t rc);
+.. c:function:: const char * memcached_strerror (memcached_st *ptr, memcached_return_t rc)
 
 Compile and link with -lmemcached
 
@@ -21,7 +21,7 @@ DESCRIPTION
 -----------
 
 
-:c:func:`memcached_strerror()` takes a :c:type:`memcached_return_t` value and returns a string describing the error.
+:c:func:`memcached_strerror` takes a :c:type:`memcached_return_t` value and returns a string describing the error.
 
 This string must not be modified by the application.
 
@@ -35,7 +35,7 @@ RETURN
 ------
 
 
-:c:func:`memcached_strerror()` returns a string describing a :c:type:`memcached_return_t` value.
+:c:func:`memcached_strerror` returns a string describing a :c:type:`memcached_return_t` value.
 
 
 ----
index 45482f70da4ae97315fb27b293659cca61b16fae..a0bc602bb0629d4e084f09a28ee2e24969e049db 100644 (file)
@@ -21,13 +21,15 @@ SYNOPSIS
 
 
 
-.. code-block:: perl
+.. code-block:: c
 
-   #include <libmemcached/memcached.h>
-   void *memcached_get_user_data (memcached_st *ptr);
-   void *memcached_set_user_data (memcached_st *ptr, void *data);
+#include <libmemcached/memcached.h>
+
+.. c:function:: void *memcached_get_user_data (memcached_st *ptr)
+
+.. c:function:: void *memcached_set_user_data (memcached_st *ptr, void *data)
+
+Compile and link with -lmemcached
 
 
 
@@ -39,10 +41,10 @@ DESCRIPTION
 libmemcached(3) allows you to store a pointer to a user specific data inside
 the memcached_st structure.
 
-:c:func:`memcached_set_user_data()` is used to set the user specific data in the
+:c:func:`memcached_set_user_data` is used to set the user specific data in the
 :c:type:`memcached_st` structure.
 
-:c:func:`memcached_get_user_data()` is used to retrieve the user specific data in the :c:type:`memcached_st` structure.
+:c:func:`memcached_get_user_data` is used to retrieve the user specific data in the :c:type:`memcached_st` structure.
 
 
 ------
@@ -50,9 +52,9 @@ RETURN
 ------
 
 
-:c:func:`memcached_set_user_data()` returns the previous value of the user specific data.
+:c:func:`memcached_set_user_data` returns the previous value of the user specific data.
 
-:c:func:`memcached_get_user_data()` returns the current value uf the user specific data.
+:c:func:`memcached_get_user_data` returns the current value uf the user specific data.
 
 
 ----
index 1266660b6b87ae00bfe96e84aec8f570f811fb6c..c3ae0d89cc05098d84cdaaa178aafee434d0b0df 100644 (file)
@@ -12,7 +12,7 @@ SYNOPSIS
 
 #include <libmemcached/memcached.h>
 
-.. c:function:: memcached_return_t memcached_verbosity (memcached_st *ptr, unsigned int verbosity);
+.. c:function:: memcached_return_t memcached_verbosity (memcached_st *ptr, uint32_t verbosity)
 
 Compile and link with -lmemcached
 
@@ -22,7 +22,7 @@ DESCRIPTION
 -----------
 
 
-:c:func:`memcached_verbosity()` modifies the "verbosity" of the
+:c:func:`memcached_verbosity` modifies the "verbosity" of the
 memcached(1) servers referenced in the :c:type:`memcached_st`  parameter.
 
 
@@ -35,7 +35,7 @@ A value of type :c:type:`memcached_return_t` is returned.
 
 On success that value will be :c:type:`MEMCACHED_SUCCESS`.
 
-Use :c:func:`memcached_strerror()` to translate this value to a printable string.
+Use :c:func:`memcached_strerror` to translate this value to a printable string.
 
 
 ----
index 6d81f5ea16158e10c40b0fe980fd1b9c45c9d654..20b8b25a20150943bcf2e0f7f238ab5d0476ae1c 100644 (file)
@@ -23,9 +23,9 @@ DESCRIPTION
 -----------
 
 
-:c:func:`memcached_lib_version()` is used to return a simple version string representing the libmemcached version (client library version, not server version)
+:c:func:`memcached_lib_version` is used to return a simple version string representing the libmemcached version (client library version, not server version)
 
-:c:func:`memcached_version()` is used to set the major, minor, and micro versions of each memcached server being used by the memcached_st connection structure. It returns the memcached server return code.
+:c:func:`memcached_version` is used to set the major, minor, and micro versions of each memcached server being used by the memcached_st connection structure. It returns the memcached server return code.
 
 
 ------
@@ -33,15 +33,15 @@ RETURN
 ------
 
 
-:c:func:`memcached_lib_version()` returns a string with the version of the libmemcached driver.
+:c:func:`memcached_lib_version` returns a string with the version of the libmemcached driver.
 
-A value of :c:type:`memcached_return_t` is returned from :c:func:'memcached_version()'
+A value of :c:type:`memcached_return_t` is returned from :c:func:'memcached_version'
 
 On success that value will be :c:type:`MEMCACHED_SUCCESS`. 
 
 If called with the :c:func:`MEMCACHED_BEHAVIOR_USE_UDP` behavior set, the value :c:type:`MEMCACHED_NOT_SUPPORTED` will be returned. 
 
-Use :c:func:`memcached_strerror()` to translate this value to 
+Use :c:func:`memcached_strerror` to translate this value to 
 a printable string.
 
 
diff --git a/docs/types.rst b/docs/types.rst
new file mode 100644 (file)
index 0000000..ea41874
--- /dev/null
@@ -0,0 +1,27 @@
+================
+Required C types
+================
+
+.. highlightlang:: c
+
+Types
+-----
+  
+C Types Used
+------------
+  
+.. c:type:: bool
+
+.. c:type:: uint32_t
+
+.. c:type:: uint64_t
+
+.. c:type:: in_port_t
+
+.. c:type:: size_t
+
+.. c:type:: time_t
+
+.. c:type:: struct timespec
+
+.. c:type:: sasl_callback_t
index dd7f896dff4b1aa19e301bddf018fdcae8e5b04f..dd3bee9dbe72931a006058c6508da0f8efeb0a72 100644 (file)
@@ -2,8 +2,7 @@
 Versioning
 ==========
 
-Libmemcached is layed out by interface version. The 1.0 version would be found  in:
-  libmemcached-1.0/memcached.h
+Libmemcached is layed out by interface version. The 1.0 version would be found  in: libmemcached-1.0/memcached.h
 
 The historic libmemcached/memcached.h includes libmemcached-1.0/memcached.h. For best practice you should include the version of libmemcacached that you used during development.
 
index 625c46809eead12be2dd4abeab23053321dedebe..bf620d0c2d4344c5f4dcffa5050546e91c0e678d 100644 (file)
@@ -13,11 +13,15 @@ noinst_HEADERS+= \
 
 example_memcached_light_SOURCES= \
                                 example/byteorder.cc \
-                                example/interface_v0.c \
-                                example/interface_v1.c \
-                                example/memcached_light.c
+                                example/interface_v0.cc \
+                                example/interface_v1.cc \
+                                example/memcached_light.cc \
+                                util/daemon.cc \
+                                util/pidfile.cc
 
 example_memcached_light_LDADD= libmemcached/libmemcachedprotocol.la \
                                $(LIBEVENT_LDFLAGS)
 
-example_memcached_light_SOURCES+= example/storage.c
+example_memcached_light_SOURCES+= example/storage.cc
+
+include example/t/include.am
diff --git a/example/interface_v0.c b/example/interface_v0.c
deleted file mode 100644 (file)
index ef5ba47..0000000
+++ /dev/null
@@ -1,596 +0,0 @@
-/* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */
-/**
- * This file contains an implementation of the callback interface for level 0
- * 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>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <libmemcachedprotocol-0.0/handler.h>
-#include <example/byteorder.h>
-#include "example/storage.h"
-#include "example/memcached_light.h"
-
-static protocol_binary_response_status noop_command_handler(const void *cookie,
-                                                            protocol_binary_request_header *header,
-                                                            memcached_binary_protocol_raw_response_handler response_handler)
-{
-  protocol_binary_response_no_extras response= {
-    .message.header.response= {
-      .magic= PROTOCOL_BINARY_RES,
-      .opcode= PROTOCOL_BINARY_CMD_NOOP,
-      .status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS),
-      .opaque= header->request.opaque
-    }
-  };
-
-  return response_handler(cookie, header, (void*)&response);
-}
-
-static protocol_binary_response_status quit_command_handler(const void *cookie,
-                                                            protocol_binary_request_header *header,
-                                                            memcached_binary_protocol_raw_response_handler response_handler)
-{
-  protocol_binary_response_no_extras response= {
-    .message.header.response= {
-      .magic= PROTOCOL_BINARY_RES,
-      .opcode= PROTOCOL_BINARY_CMD_QUIT,
-      .status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS),
-      .opaque= header->request.opaque
-    }
-  };
-
-  if (header->request.opcode == PROTOCOL_BINARY_CMD_QUIT)
-    response_handler(cookie, header, (void*)&response);
-
-  /* I need a better way to signal to close the connection */
-  return PROTOCOL_BINARY_RESPONSE_EINTERNAL;
-}
-
-static protocol_binary_response_status get_command_handler(const void *cookie,
-                                                           protocol_binary_request_header *header,
-                                                           memcached_binary_protocol_raw_response_handler response_handler)
-{
-  uint8_t opcode= header->request.opcode;
-  union {
-    protocol_binary_response_get response;
-    char buffer[4096];
-  } msg= {
-    .response.message.header.response= {
-      .magic= PROTOCOL_BINARY_RES,
-      .opcode= opcode,
-      .status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS),
-      .opaque= header->request.opaque
-    }
-  };
-
-  struct item *item= get_item(header + 1, ntohs(header->request.keylen));
-  if (item)
-  {
-    msg.response.message.body.flags= htonl(item->flags);
-    char *ptr= (char*)(msg.response.bytes + sizeof(*header) + 4);
-    uint32_t bodysize= 4;
-    msg.response.message.header.response.cas= example_htonll(item->cas);
-    if (opcode == PROTOCOL_BINARY_CMD_GETK || opcode == PROTOCOL_BINARY_CMD_GETKQ)
-    {
-      memcpy(ptr, item->key, item->nkey);
-      msg.response.message.header.response.keylen= htons((uint16_t)item->nkey);
-      ptr += item->nkey;
-      bodysize += (uint32_t)item->nkey;
-    }
-    memcpy(ptr, item->data, item->size);
-    bodysize += (uint32_t)item->size;
-    msg.response.message.header.response.bodylen= htonl(bodysize);
-    msg.response.message.header.response.extlen= 4;
-
-    release_item(item);
-    return response_handler(cookie, header, (void*)&msg);
-  }
-  else if (opcode == PROTOCOL_BINARY_CMD_GET || opcode == PROTOCOL_BINARY_CMD_GETK)
-  {
-    msg.response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_KEY_ENOENT);
-    return response_handler(cookie, header, (void*)&msg);
-  }
-
-  /* Q shouldn't report a miss ;-) */
-  return PROTOCOL_BINARY_RESPONSE_SUCCESS;
-}
-
-static protocol_binary_response_status delete_command_handler(const void *cookie,
-                                                              protocol_binary_request_header *header,
-                                                              memcached_binary_protocol_raw_response_handler response_handler)
-{
-  size_t keylen= ntohs(header->request.keylen);
-  char *key= ((char*)header) + sizeof(*header);
-  protocol_binary_response_no_extras response= {
-    .message.header.response= {
-      .magic= PROTOCOL_BINARY_RES,
-      .opcode= header->request.opcode,
-      .opaque= header->request.opaque
-    }
-  };
-
-  if (!delete_item(key, keylen))
-  {
-    response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_KEY_ENOENT);
-    return response_handler(cookie, header, (void*)&response);
-  }
-  else if (header->request.opcode == PROTOCOL_BINARY_CMD_DELETE)
-  {
-    /* DELETEQ doesn't want success response */
-    response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS);
-    return response_handler(cookie, header, (void*)&response);
-  }
-
-  return PROTOCOL_BINARY_RESPONSE_SUCCESS;
-}
-
-static protocol_binary_response_status flush_command_handler(const void *cookie,
-                                                             protocol_binary_request_header *header,
-                                                             memcached_binary_protocol_raw_response_handler response_handler)
-{
-  uint8_t opcode= header->request.opcode;
-
-  /* @fixme sett inn when! */
-  flush(0);
-
-  if (opcode == PROTOCOL_BINARY_CMD_FLUSH)
-  {
-    protocol_binary_response_no_extras response= {
-      .message.header.response= {
-        .magic= PROTOCOL_BINARY_RES,
-        .opcode= opcode,
-        .status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS),
-        .opaque= header->request.opaque
-      }
-    };
-    return response_handler(cookie, header, (void*)&response);
-  }
-
-  return PROTOCOL_BINARY_RESPONSE_SUCCESS;
-}
-
-static protocol_binary_response_status arithmetic_command_handler(const void *cookie,
-                                                                  protocol_binary_request_header *header,
-                                                                  memcached_binary_protocol_raw_response_handler response_handler)
-{
-  protocol_binary_request_incr *req= (void*)header;
-  protocol_binary_response_incr response= {
-    .message.header.response= {
-      .magic= PROTOCOL_BINARY_RES,
-      .opcode= header->request.opcode,
-      .opaque= header->request.opaque,
-    },
-  };
-
-  uint16_t keylen= ntohs(header->request.keylen);
-  uint64_t initial= example_ntohll(req->message.body.initial);
-  uint64_t delta= example_ntohll(req->message.body.delta);
-  uint32_t expiration= ntohl(req->message.body.expiration);
-  uint32_t flags= 0;
-  void *key= req->bytes + sizeof(req->bytes);
-  protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS;
-
-  uint64_t value= initial;
-
-  struct item *item= get_item(key, keylen);
-  if (item != NULL)
-  {
-    if (header->request.opcode == PROTOCOL_BINARY_CMD_INCREMENT ||
-        header->request.opcode == PROTOCOL_BINARY_CMD_INCREMENTQ)
-    {
-      value= (*(uint64_t*)item->data) + delta;
-    }
-    else
-    {
-      if (delta > *(uint64_t*)item->data)
-      {
-        value= 0;
-      }
-      else
-      {
-        value= *(uint64_t*)item->data - delta;
-      }
-    }
-    expiration= (uint32_t)item->exp;
-    flags= item->flags;
-
-    release_item(item);
-    delete_item(key, keylen);
-  }
-
-  item= create_item(key, keylen, NULL, sizeof(value), flags, (time_t)expiration);
-  if (item == NULL)
-  {
-    rval= PROTOCOL_BINARY_RESPONSE_ENOMEM;
-  }
-  else
-  {
-    memcpy(item->data, &value, sizeof(value));
-    put_item(item);
-  }
-
-  response.message.header.response.status= htons(rval);
-  if (rval == PROTOCOL_BINARY_RESPONSE_SUCCESS)
-  {
-    response.message.header.response.bodylen= ntohl(8);
-    response.message.body.value= example_ntohll((*(uint64_t*)item->data));
-    response.message.header.response.cas= example_ntohll(item->cas);
-
-    release_item(item);
-    if (header->request.opcode == PROTOCOL_BINARY_CMD_INCREMENTQ ||
-        header->request.opcode == PROTOCOL_BINARY_CMD_DECREMENTQ)
-    {
-      return PROTOCOL_BINARY_RESPONSE_SUCCESS;
-    }
-  }
-
-  return response_handler(cookie, header, (void*)&response);
-}
-
-static protocol_binary_response_status version_command_handler(const void *cookie,
-                                                               protocol_binary_request_header *header,
-                                                               memcached_binary_protocol_raw_response_handler response_handler)
-{
-  const char *versionstring= "1.0.0";
-  union {
-    protocol_binary_response_header packet;
-    char buffer[256];
-  } response= {
-    .packet.response= {
-      .magic= PROTOCOL_BINARY_RES,
-      .opcode= PROTOCOL_BINARY_CMD_VERSION,
-      .status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS),
-      .opaque= header->request.opaque,
-      .cas= 0,
-      .bodylen= htonl((uint32_t)strlen(versionstring))
-    }
-  };
-
-  memcpy(response.buffer + sizeof(response.packet), versionstring, strlen(versionstring));
-
-  return response_handler(cookie, header, (void*)&response);
-}
-
-static protocol_binary_response_status concat_command_handler(const void *cookie,
-                                                              protocol_binary_request_header *header,
-                                                              memcached_binary_protocol_raw_response_handler response_handler)
-{
-  protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS;
-  uint16_t keylen= ntohs(header->request.keylen);
-  uint64_t cas= example_ntohll(header->request.cas);
-  void *key= header + 1;
-  uint32_t vallen= ntohl(header->request.bodylen) - keylen;
-  void *val= (char*)key + keylen;
-
-  struct item *item= get_item(key, keylen);
-  struct item *nitem= NULL;
-
-  if (item == NULL)
-  {
-    rval= PROTOCOL_BINARY_RESPONSE_KEY_ENOENT;
-  }
-  else if (cas != 0 && cas != item->cas)
-  {
-    rval= PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS;
-  }
-  else if ((nitem= create_item(key, keylen, NULL, item->size + vallen,
-                               item->flags, item->exp)) == NULL)
-  {
-    release_item(item);
-    rval= PROTOCOL_BINARY_RESPONSE_ENOMEM;
-  }
-  else
-  {
-    if (header->request.opcode == PROTOCOL_BINARY_CMD_APPEND ||
-        header->request.opcode == PROTOCOL_BINARY_CMD_APPENDQ)
-    {
-      memcpy(nitem->data, item->data, item->size);
-      memcpy(((char*)(nitem->data)) + item->size, val, vallen);
-    }
-    else
-    {
-      memcpy(nitem->data, val, vallen);
-      memcpy(((char*)(nitem->data)) + vallen, item->data, item->size);
-    }
-    release_item(item);
-    delete_item(key, keylen);
-    put_item(nitem);
-    cas= nitem->cas;
-    release_item(nitem);
-
-    if (header->request.opcode == PROTOCOL_BINARY_CMD_APPEND ||
-        header->request.opcode == PROTOCOL_BINARY_CMD_PREPEND)
-    {
-      protocol_binary_response_no_extras response= {
-        .message= {
-          .header.response= {
-            .magic= PROTOCOL_BINARY_RES,
-            .opcode= header->request.opcode,
-            .status= htons(rval),
-            .opaque= header->request.opaque,
-            .cas= example_htonll(cas),
-          }
-        }
-      };
-      return response_handler(cookie, header, (void*)&response);
-    }
-  }
-
-  return rval;
-}
-
-static protocol_binary_response_status set_command_handler(const void *cookie,
-                                                           protocol_binary_request_header *header,
-                                                           memcached_binary_protocol_raw_response_handler response_handler)
-{
-  size_t keylen= ntohs(header->request.keylen);
-  size_t datalen= ntohl(header->request.bodylen) - keylen - 8;
-  protocol_binary_request_replace *request= (void*)header;
-  uint32_t flags= ntohl(request->message.body.flags);
-  time_t timeout= (time_t)ntohl(request->message.body.expiration);
-  char *key= ((char*)header) + sizeof(*header) + 8;
-  char *data= key + keylen;
-
-  protocol_binary_response_no_extras response= {
-    .message= {
-      .header.response= {
-        .magic= PROTOCOL_BINARY_RES,
-        .opcode= header->request.opcode,
-        .status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS),
-        .opaque= header->request.opaque
-      }
-    }
-  };
-
-  if (header->request.cas != 0)
-  {
-    /* validate cas */
-    struct item* item= get_item(key, keylen);
-    if (item != NULL)
-    {
-      if (item->cas != example_ntohll(header->request.cas))
-      {
-        release_item(item);
-        response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS);
-        return response_handler(cookie, header, (void*)&response);
-      }
-      release_item(item);
-    }
-  }
-
-  delete_item(key, keylen);
-  struct item* item= create_item(key, keylen, data, datalen, flags, timeout);
-  if (item == NULL)
-  {
-    response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_ENOMEM);
-  }
-  else
-  {
-    put_item(item);
-    /* SETQ shouldn't return a message */
-    if (header->request.opcode == PROTOCOL_BINARY_CMD_SET)
-    {
-      response.message.header.response.cas= example_htonll(item->cas);
-      release_item(item);
-      return response_handler(cookie, header, (void*)&response);
-    }
-    release_item(item);
-
-    return PROTOCOL_BINARY_RESPONSE_SUCCESS;
-  }
-
-  return response_handler(cookie, header, (void*)&response);
-}
-
-static protocol_binary_response_status add_command_handler(const void *cookie,
-                                                           protocol_binary_request_header *header,
-                                                           memcached_binary_protocol_raw_response_handler response_handler)
-{
-  size_t keylen= ntohs(header->request.keylen);
-  size_t datalen= ntohl(header->request.bodylen) - keylen - 8;
-  protocol_binary_request_add *request= (void*)header;
-  uint32_t flags= ntohl(request->message.body.flags);
-  time_t timeout= (time_t)ntohl(request->message.body.expiration);
-  char *key= ((char*)header) + sizeof(*header) + 8;
-  char *data= key + keylen;
-
-  protocol_binary_response_no_extras response= {
-    .message= {
-      .header.response= {
-        .magic= PROTOCOL_BINARY_RES,
-        .opcode= header->request.opcode,
-        .status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS),
-        .opaque= header->request.opaque
-      }
-    }
-  };
-
-  struct item* item= get_item(key, keylen);
-  if (item == NULL)
-  {
-    item= create_item(key, keylen, data, datalen, flags, timeout);
-    if (item == NULL)
-      response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_ENOMEM);
-    else
-    {
-      put_item(item);
-      /* ADDQ shouldn't return a message */
-      if (header->request.opcode == PROTOCOL_BINARY_CMD_ADD)
-      {
-        response.message.header.response.cas= example_htonll(item->cas);
-        release_item(item);
-        return response_handler(cookie, header, (void*)&response);
-      }
-      release_item(item);
-      return PROTOCOL_BINARY_RESPONSE_SUCCESS;
-    }
-  }
-  else
-  {
-    release_item(item);
-    response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS);
-  }
-
-  return response_handler(cookie, header, (void*)&response);
-}
-
-static protocol_binary_response_status replace_command_handler(const void *cookie,
-                                                               protocol_binary_request_header *header,
-                                                               memcached_binary_protocol_raw_response_handler response_handler)
-{
-  size_t keylen= ntohs(header->request.keylen);
-  size_t datalen= ntohl(header->request.bodylen) - keylen - 8;
-  protocol_binary_request_replace *request= (void*)header;
-  uint32_t flags= ntohl(request->message.body.flags);
-  time_t timeout= (time_t)ntohl(request->message.body.expiration);
-  char *key= ((char*)header) + sizeof(*header) + 8;
-  char *data= key + keylen;
-
-  protocol_binary_response_no_extras response= {
-    .message= {
-      .header.response= {
-        .magic= PROTOCOL_BINARY_RES,
-        .opcode= header->request.opcode,
-        .status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS),
-        .opaque= header->request.opaque
-      }
-    }
-  };
-
-  struct item* item= get_item(key, keylen);
-  if (item == NULL)
-  {
-    response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_KEY_ENOENT);
-  }
-  else if (header->request.cas == 0 || example_ntohll(header->request.cas) == item->cas)
-  {
-    release_item(item);
-    delete_item(key, keylen);
-    item= create_item(key, keylen, data, datalen, flags, timeout);
-
-    if (item == NULL)
-    {
-      response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_ENOMEM);
-    }
-    else
-    {
-      put_item(item);
-      /* REPLACEQ shouldn't return a message */
-      if (header->request.opcode == PROTOCOL_BINARY_CMD_REPLACE)
-      {
-        response.message.header.response.cas= example_htonll(item->cas);
-        release_item(item);
-        return response_handler(cookie, header, (void*)&response);
-      }
-      release_item(item);
-      return PROTOCOL_BINARY_RESPONSE_SUCCESS;
-    }
-  }
-  else
-  {
-    response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS);
-    release_item(item);
-  }
-
-  return response_handler(cookie, header, (void*)&response);
-}
-
-static protocol_binary_response_status stat_command_handler(const void *cookie,
-                                                            protocol_binary_request_header *header,
-                                                            memcached_binary_protocol_raw_response_handler response_handler)
-{
-  /* Just send the terminating packet*/
-  protocol_binary_response_no_extras response= {
-    .message= {
-      .header.response= {
-        .magic= PROTOCOL_BINARY_RES,
-        .opcode= PROTOCOL_BINARY_CMD_STAT,
-        .status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS),
-        .opaque= header->request.opaque
-      }
-    }
-  };
-
-  return response_handler(cookie, header, (void*)&response);
-}
-
-memcached_binary_protocol_callback_st interface_v0_impl= {
-  .interface_version= MEMCACHED_PROTOCOL_HANDLER_V0,
-#ifdef FUTURE
-  /*
-  ** There is a number of bugs in the extra options for gcc causing
-  ** warning on these struct initializers. It hurts my heart to remove
-  ** it so I'll just leave it in here so that we can enable it when
-  ** we can drop support for the broken compilers
-  */
-  .interface.v0.comcode[PROTOCOL_BINARY_CMD_GET]= get_command_handler,
-  .interface.v0.comcode[PROTOCOL_BINARY_CMD_SET]= set_command_handler,
-  .interface.v0.comcode[PROTOCOL_BINARY_CMD_ADD]= add_command_handler,
-  .interface.v0.comcode[PROTOCOL_BINARY_CMD_REPLACE]= replace_command_handler,
-  .interface.v0.comcode[PROTOCOL_BINARY_CMD_DELETE]= delete_command_handler,
-  .interface.v0.comcode[PROTOCOL_BINARY_CMD_INCREMENT]= arithmetic_command_handler,
-  .interface.v0.comcode[PROTOCOL_BINARY_CMD_DECREMENT]= arithmetic_command_handler,
-  .interface.v0.comcode[PROTOCOL_BINARY_CMD_QUIT]= quit_command_handler,
-  .interface.v0.comcode[PROTOCOL_BINARY_CMD_FLUSH]= flush_command_handler,
-  .interface.v0.comcode[PROTOCOL_BINARY_CMD_GETQ]= get_command_handler,
-  .interface.v0.comcode[PROTOCOL_BINARY_CMD_NOOP]= noop_command_handler,
-  .interface.v0.comcode[PROTOCOL_BINARY_CMD_VERSION]= version_command_handler,
-  .interface.v0.comcode[PROTOCOL_BINARY_CMD_GETK]= get_command_handler,
-  .interface.v0.comcode[PROTOCOL_BINARY_CMD_GETKQ]= get_command_handler,
-  .interface.v0.comcode[PROTOCOL_BINARY_CMD_APPEND]= concat_command_handler,
-  .interface.v0.comcode[PROTOCOL_BINARY_CMD_PREPEND]= concat_command_handler,
-  .interface.v0.comcode[PROTOCOL_BINARY_CMD_STAT]= stat_command_handler,
-  .interface.v0.comcode[PROTOCOL_BINARY_CMD_SETQ]= set_command_handler,
-  .interface.v0.comcode[PROTOCOL_BINARY_CMD_ADDQ]= add_command_handler,
-  .interface.v0.comcode[PROTOCOL_BINARY_CMD_REPLACEQ]= replace_command_handler,
-  .interface.v0.comcode[PROTOCOL_BINARY_CMD_DELETEQ]= delete_command_handler,
-  .interface.v0.comcode[PROTOCOL_BINARY_CMD_INCREMENTQ]= arithmetic_command_handler,
-  .interface.v0.comcode[PROTOCOL_BINARY_CMD_DECREMENTQ]= arithmetic_command_handler,
-  .interface.v0.comcode[PROTOCOL_BINARY_CMD_QUITQ]= quit_command_handler,
-  .interface.v0.comcode[PROTOCOL_BINARY_CMD_FLUSHQ]= flush_command_handler,
-  .interface.v0.comcode[PROTOCOL_BINARY_CMD_APPENDQ]= concat_command_handler,
-  .interface.v0.comcode[PROTOCOL_BINARY_CMD_PREPENDQ]= concat_command_handler,
-#endif
-};
-
-void initialize_interface_v0_handler(void)
-{
-  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_GET]= get_command_handler;
-  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_SET]= set_command_handler;
-  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_ADD]= add_command_handler;
-  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_REPLACE]= replace_command_handler;
-  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_DELETE]= delete_command_handler;
-  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_INCREMENT]= arithmetic_command_handler;
-  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_DECREMENT]= arithmetic_command_handler;
-  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_QUIT]= quit_command_handler;
-  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_FLUSH]= flush_command_handler;
-  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_GETQ]= get_command_handler;
-  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_NOOP]= noop_command_handler;
-  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_VERSION]= version_command_handler;
-  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_GETK]= get_command_handler;
-  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_GETKQ]= get_command_handler;
-  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_APPEND]= concat_command_handler;
-  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_PREPEND]= concat_command_handler;
-  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_STAT]= stat_command_handler;
-  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_SETQ]= set_command_handler;
-  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_ADDQ]= add_command_handler;
-  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_REPLACEQ]= replace_command_handler;
-  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_DELETEQ]= delete_command_handler;
-  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_INCREMENTQ]= arithmetic_command_handler;
-  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_DECREMENTQ]= arithmetic_command_handler;
-  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_QUITQ]= quit_command_handler;
-  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_FLUSHQ]= flush_command_handler;
-  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_APPENDQ]= concat_command_handler;
-  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_PREPENDQ]= concat_command_handler;
-}
diff --git a/example/interface_v0.cc b/example/interface_v0.cc
new file mode 100644 (file)
index 0000000..e4f5c90
--- /dev/null
@@ -0,0 +1,561 @@
+/* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */
+/**
+ * This file contains an implementation of the callback interface for level 0
+ * 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>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <libmemcachedprotocol-0.0/handler.h>
+#include <example/byteorder.h>
+#include "example/memcached_light.h"
+#include "example/storage.h"
+#include "util/log.hpp"
+
+
+using namespace datadifferential;
+
+static util::log_info_st *log_file= NULL;
+
+static protocol_binary_response_status noop_command_handler(const void *cookie,
+                                                            protocol_binary_request_header *header,
+                                                            memcached_binary_protocol_raw_response_handler response_handler)
+{
+  protocol_binary_response_no_extras response;
+  memset(&response, 0, sizeof(protocol_binary_response_no_extras));
+
+  response.message.header.response.magic= PROTOCOL_BINARY_RES;
+  response.message.header.response.opcode= PROTOCOL_BINARY_CMD_NOOP;
+  response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS);
+  response.message.header.response.opaque= header->request.opaque;
+
+  return response_handler(cookie, header, (protocol_binary_response_header*)&response);
+}
+
+static protocol_binary_response_status quit_command_handler(const void *cookie,
+                                                            protocol_binary_request_header *header,
+                                                            memcached_binary_protocol_raw_response_handler response_handler)
+{
+  protocol_binary_response_no_extras response;
+  memset(&response, 0, sizeof(protocol_binary_response_no_extras));
+
+  response.message.header.response.magic= PROTOCOL_BINARY_RES;
+  response.message.header.response.opcode= PROTOCOL_BINARY_CMD_QUIT;
+  response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS);
+  response.message.header.response.opaque= header->request.opaque;
+
+  if (header->request.opcode == PROTOCOL_BINARY_CMD_QUIT)
+  {
+    response_handler(cookie, header, (protocol_binary_response_header*)&response);
+  }
+
+  /* I need a better way to signal to close the connection */
+  return PROTOCOL_BINARY_RESPONSE_EINTERNAL;
+}
+
+static protocol_binary_response_status get_command_handler(const void *cookie,
+                                                           protocol_binary_request_header *header,
+                                                           memcached_binary_protocol_raw_response_handler response_handler)
+{
+  uint8_t opcode= header->request.opcode;
+  union protocol_binary_response_get_un {
+    protocol_binary_response_get response;
+    char buffer[4096];
+  };
+  
+  protocol_binary_response_get_un msg;
+  memset(&msg, 0, sizeof(protocol_binary_response_get_un));
+
+  msg.response.message.header.response.magic= PROTOCOL_BINARY_RES;
+  msg.response.message.header.response.opcode= opcode;
+  msg.response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS);
+  msg.response.message.header.response.opaque= header->request.opaque;
+
+  struct item *item= get_item(header + 1, ntohs(header->request.keylen));
+  if (item)
+  {
+    msg.response.message.body.flags= htonl(item->flags);
+    char *ptr= (char*)(msg.response.bytes + sizeof(*header) + 4);
+    uint32_t bodysize= 4;
+    msg.response.message.header.response.cas= example_htonll(item->cas);
+    if (opcode == PROTOCOL_BINARY_CMD_GETK || opcode == PROTOCOL_BINARY_CMD_GETKQ)
+    {
+      memcpy(ptr, item->key, item->nkey);
+      msg.response.message.header.response.keylen= htons((uint16_t)item->nkey);
+      ptr += item->nkey;
+      bodysize += (uint32_t)item->nkey;
+    }
+    memcpy(ptr, item->data, item->size);
+    bodysize += (uint32_t)item->size;
+    msg.response.message.header.response.bodylen= htonl(bodysize);
+    msg.response.message.header.response.extlen= 4;
+
+    release_item(item);
+    return response_handler(cookie, header, (protocol_binary_response_header*)&msg);
+  }
+  else if (opcode == PROTOCOL_BINARY_CMD_GET || opcode == PROTOCOL_BINARY_CMD_GETK)
+  {
+    msg.response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_KEY_ENOENT);
+    return response_handler(cookie, header, (protocol_binary_response_header*)&msg);
+  }
+
+  /* Q shouldn't report a miss ;-) */
+  return PROTOCOL_BINARY_RESPONSE_SUCCESS;
+}
+
+static protocol_binary_response_status delete_command_handler(const void *cookie,
+                                                              protocol_binary_request_header *header,
+                                                              memcached_binary_protocol_raw_response_handler response_handler)
+{
+  size_t keylen= ntohs(header->request.keylen);
+
+  char *key= ((char*)header) + sizeof(*header);
+  protocol_binary_response_no_extras response;
+  memset(&response, 0, sizeof(protocol_binary_response_no_extras));
+
+  response.message.header.response.magic= PROTOCOL_BINARY_RES;
+  response.message.header.response.opcode= header->request.opcode;
+  response.message.header.response.opaque= header->request.opaque;
+
+  if (delete_item(key, keylen) == false)
+  {
+    log_file->write(util::VERBOSE_NOTICE, "%s not found: %.*s", __func__, keylen, key);
+    response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_KEY_ENOENT);
+    return response_handler(cookie, header, (protocol_binary_response_header*)&response);
+  }
+  else if (header->request.opcode == PROTOCOL_BINARY_CMD_DELETE)
+  {
+    log_file->write(util::VERBOSE_NOTICE, "%s not found: %.*s", __func__, keylen, key);
+    /* DELETEQ doesn't want success response */
+    response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS);
+    return response_handler(cookie, header, (protocol_binary_response_header*)&response);
+  }
+
+  log_file->write(util::VERBOSE_NOTICE, "%s deleted: %.*s", __func__, keylen, key);
+
+  return PROTOCOL_BINARY_RESPONSE_SUCCESS;
+}
+
+static protocol_binary_response_status flush_command_handler(const void *cookie,
+                                                             protocol_binary_request_header *header,
+                                                             memcached_binary_protocol_raw_response_handler response_handler)
+{
+  uint8_t opcode= header->request.opcode;
+
+  /* @fixme sett inn when! */
+  flush(0);
+
+  if (opcode == PROTOCOL_BINARY_CMD_FLUSH)
+  {
+    protocol_binary_response_no_extras response;
+    memset(&response, 0, sizeof(protocol_binary_response_no_extras));
+
+    response.message.header.response.magic= PROTOCOL_BINARY_RES;
+    response.message.header.response.opcode= opcode;
+    response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS);
+    response.message.header.response.opaque= header->request.opaque;
+
+    return response_handler(cookie, header, (protocol_binary_response_header*)&response);
+  }
+
+  return PROTOCOL_BINARY_RESPONSE_SUCCESS;
+}
+
+static protocol_binary_response_status arithmetic_command_handler(const void *cookie,
+                                                                  protocol_binary_request_header *header,
+                                                                  memcached_binary_protocol_raw_response_handler response_handler)
+{
+  protocol_binary_request_incr *req= (protocol_binary_request_incr*)header;
+  protocol_binary_response_incr response;
+  memset(&response, 0, sizeof(protocol_binary_response_incr));
+
+  response.message.header.response.magic= PROTOCOL_BINARY_RES;
+  response.message.header.response.opcode= header->request.opcode;
+  response.message.header.response.opaque= header->request.opaque;
+
+  uint16_t keylen= ntohs(header->request.keylen);
+  uint64_t initial= example_ntohll(req->message.body.initial);
+  uint64_t delta= example_ntohll(req->message.body.delta);
+  uint32_t expiration= ntohl(req->message.body.expiration);
+  uint32_t flags= 0;
+  void *key= req->bytes + sizeof(req->bytes);
+  protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS;
+
+  uint64_t value= initial;
+
+  struct item *item= get_item(key, keylen);
+  if (item != NULL)
+  {
+    if (header->request.opcode == PROTOCOL_BINARY_CMD_INCREMENT ||
+        header->request.opcode == PROTOCOL_BINARY_CMD_INCREMENTQ)
+    {
+      value= (*(uint64_t*)item->data) + delta;
+    }
+    else
+    {
+      if (delta > *(uint64_t*)item->data)
+      {
+        value= 0;
+      }
+      else
+      {
+        value= *(uint64_t*)item->data - delta;
+      }
+    }
+    expiration= (uint32_t)item->exp;
+    flags= item->flags;
+
+    release_item(item);
+    delete_item(key, keylen);
+  }
+
+  item= create_item(key, keylen, NULL, sizeof(value), flags, (time_t)expiration);
+  if (item == NULL)
+  {
+    rval= PROTOCOL_BINARY_RESPONSE_ENOMEM;
+  }
+  else
+  {
+    memcpy(item->data, &value, sizeof(value));
+    put_item(item);
+  }
+
+  response.message.header.response.status= htons(rval);
+  if (rval == PROTOCOL_BINARY_RESPONSE_SUCCESS)
+  {
+    response.message.header.response.bodylen= ntohl(8);
+    response.message.body.value= example_ntohll((*(uint64_t*)item->data));
+    response.message.header.response.cas= example_ntohll(item->cas);
+
+    release_item(item);
+    if (header->request.opcode == PROTOCOL_BINARY_CMD_INCREMENTQ ||
+        header->request.opcode == PROTOCOL_BINARY_CMD_DECREMENTQ)
+    {
+      return PROTOCOL_BINARY_RESPONSE_SUCCESS;
+    }
+  }
+
+  return response_handler(cookie, header, (protocol_binary_response_header*)&response);
+}
+
+static protocol_binary_response_status version_command_handler(const void *cookie,
+                                                               protocol_binary_request_header *header,
+                                                               memcached_binary_protocol_raw_response_handler response_handler)
+{
+  const char *versionstring= "1.0.0";
+  union protocol_binary_response_header_un
+  {
+    protocol_binary_response_header packet;
+    char buffer[256];
+  };
+  
+  protocol_binary_response_header_un response;
+  memset(&response, 0, sizeof(protocol_binary_response_header_un));
+
+  response.packet.response.magic= PROTOCOL_BINARY_RES;
+  response.packet.response.opcode= PROTOCOL_BINARY_CMD_VERSION;
+  response.packet.response.status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS);
+  response.packet.response.opaque= header->request.opaque;
+  response.packet.response.cas= 0;
+  response.packet.response.bodylen= htonl((uint32_t)strlen(versionstring));
+
+  assert(sizeof(protocol_binary_response_header) +strlen(versionstring) <= 256);
+  memcpy(response.buffer + sizeof(protocol_binary_response_header), versionstring, strlen(versionstring));
+
+  return response_handler(cookie, header, (protocol_binary_response_header*)&response);
+}
+
+static protocol_binary_response_status concat_command_handler(const void *cookie,
+                                                              protocol_binary_request_header *header,
+                                                              memcached_binary_protocol_raw_response_handler response_handler)
+{
+  protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS;
+  uint16_t keylen= ntohs(header->request.keylen);
+  uint64_t cas= example_ntohll(header->request.cas);
+  void *key= header + 1;
+  uint32_t vallen= ntohl(header->request.bodylen) - keylen;
+  void *val= (char*)key + keylen;
+
+  struct item *item= get_item(key, keylen);
+  struct item *nitem= NULL;
+
+  if (item == NULL)
+  {
+    rval= PROTOCOL_BINARY_RESPONSE_KEY_ENOENT;
+  }
+  else if (cas != 0 && cas != item->cas)
+  {
+    rval= PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS;
+  }
+  else if ((nitem= create_item(key, keylen, NULL, item->size + vallen,
+                               item->flags, item->exp)) == NULL)
+  {
+    release_item(item);
+    rval= PROTOCOL_BINARY_RESPONSE_ENOMEM;
+  }
+  else
+  {
+    if (header->request.opcode == PROTOCOL_BINARY_CMD_APPEND ||
+        header->request.opcode == PROTOCOL_BINARY_CMD_APPENDQ)
+    {
+      memcpy(nitem->data, item->data, item->size);
+      memcpy(((char*)(nitem->data)) + item->size, val, vallen);
+    }
+    else
+    {
+      memcpy(nitem->data, val, vallen);
+      memcpy(((char*)(nitem->data)) + vallen, item->data, item->size);
+    }
+    release_item(item);
+    delete_item(key, keylen);
+    put_item(nitem);
+    cas= nitem->cas;
+    release_item(nitem);
+
+    if (header->request.opcode == PROTOCOL_BINARY_CMD_APPEND ||
+        header->request.opcode == PROTOCOL_BINARY_CMD_PREPEND)
+    {
+      protocol_binary_response_no_extras response;
+      memset(&response, 0, sizeof(protocol_binary_response_no_extras));
+
+      response.message.header.response.magic= PROTOCOL_BINARY_RES;
+      response.message.header.response.opcode= header->request.opcode;
+      response.message.header.response.status= htons(rval);
+      response.message.header.response.opaque= header->request.opaque;
+      response.message.header.response.cas= example_htonll(cas);
+
+      return response_handler(cookie, header, (protocol_binary_response_header*)&response);
+    }
+  }
+
+  return rval;
+}
+
+static protocol_binary_response_status set_command_handler(const void *cookie,
+                                                           protocol_binary_request_header *header,
+                                                           memcached_binary_protocol_raw_response_handler response_handler)
+{
+  size_t keylen= ntohs(header->request.keylen);
+  size_t datalen= ntohl(header->request.bodylen) - keylen - 8;
+  protocol_binary_request_replace *request= (protocol_binary_request_replace*)header;
+  uint32_t flags= ntohl(request->message.body.flags);
+  time_t timeout= (time_t)ntohl(request->message.body.expiration);
+  char *key= ((char*)header) + sizeof(*header) + 8;
+  char *data= key + keylen;
+
+  protocol_binary_response_no_extras response;
+  memset(&response, 0, sizeof(protocol_binary_response_no_extras));
+
+  response.message.header.response.magic= PROTOCOL_BINARY_RES;
+  response.message.header.response.opcode= header->request.opcode;
+  response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS);
+  response.message.header.response.opaque= header->request.opaque;
+
+  if (header->request.cas != 0)
+  {
+    /* validate cas */
+    struct item* item= get_item(key, keylen);
+    if (item != NULL)
+    {
+      if (item->cas != example_ntohll(header->request.cas))
+      {
+        release_item(item);
+        response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS);
+        return response_handler(cookie, header, (protocol_binary_response_header*)&response);
+      }
+      release_item(item);
+    }
+  }
+
+  delete_item(key, keylen);
+  struct item* item= create_item(key, keylen, data, datalen, flags, timeout);
+  if (item == NULL)
+  {
+    response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_ENOMEM);
+  }
+  else
+  {
+    put_item(item);
+    /* SETQ shouldn't return a message */
+    if (header->request.opcode == PROTOCOL_BINARY_CMD_SET)
+    {
+      response.message.header.response.cas= example_htonll(item->cas);
+      release_item(item);
+      return response_handler(cookie, header, (protocol_binary_response_header*)&response);
+    }
+    release_item(item);
+
+    return PROTOCOL_BINARY_RESPONSE_SUCCESS;
+  }
+
+  return response_handler(cookie, header, (protocol_binary_response_header*)&response);
+}
+
+static protocol_binary_response_status add_command_handler(const void *cookie,
+                                                           protocol_binary_request_header *header,
+                                                           memcached_binary_protocol_raw_response_handler response_handler)
+{
+  size_t keylen= ntohs(header->request.keylen);
+  size_t datalen= ntohl(header->request.bodylen) - keylen - 8;
+  protocol_binary_request_add *request= (protocol_binary_request_add*)header;
+  uint32_t flags= ntohl(request->message.body.flags);
+  time_t timeout= (time_t)ntohl(request->message.body.expiration);
+  char *key= ((char*)header) + sizeof(*header) + 8;
+  char *data= key + keylen;
+
+  protocol_binary_response_no_extras response;
+  memset(&response, 0, sizeof(protocol_binary_response_no_extras));
+
+  response.message.header.response.magic= PROTOCOL_BINARY_RES;
+  response.message.header.response.opcode= header->request.opcode;
+  response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS);
+  response.message.header.response.opaque= header->request.opaque;
+
+  struct item* item= get_item(key, keylen);
+  if (item == NULL)
+  {
+    item= create_item(key, keylen, data, datalen, flags, timeout);
+    if (item == NULL)
+      response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_ENOMEM);
+    else
+    {
+      put_item(item);
+      /* ADDQ shouldn't return a message */
+      if (header->request.opcode == PROTOCOL_BINARY_CMD_ADD)
+      {
+        response.message.header.response.cas= example_htonll(item->cas);
+        release_item(item);
+        return response_handler(cookie, header, (protocol_binary_response_header*)&response);
+      }
+      release_item(item);
+      return PROTOCOL_BINARY_RESPONSE_SUCCESS;
+    }
+  }
+  else
+  {
+    release_item(item);
+    response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS);
+  }
+
+  return response_handler(cookie, header, (protocol_binary_response_header*)&response);
+}
+
+static protocol_binary_response_status replace_command_handler(const void *cookie,
+                                                               protocol_binary_request_header *header,
+                                                               memcached_binary_protocol_raw_response_handler response_handler)
+{
+  size_t keylen= ntohs(header->request.keylen);
+  size_t datalen= ntohl(header->request.bodylen) - keylen - 8;
+  protocol_binary_request_replace *request= (protocol_binary_request_replace*)header;
+  uint32_t flags= ntohl(request->message.body.flags);
+  time_t timeout= (time_t)ntohl(request->message.body.expiration);
+  char *key= ((char*)header) + sizeof(*header) + 8;
+  char *data= key + keylen;
+
+  protocol_binary_response_no_extras response;
+  memset(&response, 0, sizeof(protocol_binary_response_no_extras));
+
+  response.message.header.response.magic= PROTOCOL_BINARY_RES;
+  response.message.header.response.opcode= header->request.opcode;
+  response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS);
+  response.message.header.response.opaque= header->request.opaque;
+
+  struct item* item= get_item(key, keylen);
+  if (item == NULL)
+  {
+    response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_KEY_ENOENT);
+  }
+  else if (header->request.cas == 0 || example_ntohll(header->request.cas) == item->cas)
+  {
+    release_item(item);
+    delete_item(key, keylen);
+    item= create_item(key, keylen, data, datalen, flags, timeout);
+
+    if (item == NULL)
+    {
+      response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_ENOMEM);
+    }
+    else
+    {
+      put_item(item);
+      /* REPLACEQ shouldn't return a message */
+      if (header->request.opcode == PROTOCOL_BINARY_CMD_REPLACE)
+      {
+        response.message.header.response.cas= example_htonll(item->cas);
+        release_item(item);
+        return response_handler(cookie, header, (protocol_binary_response_header*)&response);
+      }
+      release_item(item);
+      return PROTOCOL_BINARY_RESPONSE_SUCCESS;
+    }
+  }
+  else
+  {
+    response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS);
+    release_item(item);
+  }
+
+  return response_handler(cookie, header, (protocol_binary_response_header*)&response);
+}
+
+static protocol_binary_response_status stat_command_handler(const void *cookie,
+                                                            protocol_binary_request_header *header,
+                                                            memcached_binary_protocol_raw_response_handler response_handler)
+{
+  /* Just send the terminating packet*/
+  protocol_binary_response_no_extras response;
+  memset(&response, 0, sizeof(protocol_binary_response_no_extras));
+
+  response.message.header.response.magic= PROTOCOL_BINARY_RES;
+  response.message.header.response.opcode= PROTOCOL_BINARY_CMD_STAT;
+  response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS);
+  response.message.header.response.opaque= header->request.opaque;
+
+  return response_handler(cookie, header, (protocol_binary_response_header*)&response);
+}
+
+memcached_binary_protocol_callback_st interface_v0_impl;
+
+void initialize_interface_v0_handler(util::log_info_st& arg)
+{
+  log_file= &arg;
+
+  interface_v0_impl.interface_version= MEMCACHED_PROTOCOL_HANDLER_V0;
+  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_GET]= get_command_handler;
+  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_SET]= set_command_handler;
+  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_ADD]= add_command_handler;
+  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_REPLACE]= replace_command_handler;
+  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_DELETE]= delete_command_handler;
+  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_INCREMENT]= arithmetic_command_handler;
+  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_DECREMENT]= arithmetic_command_handler;
+  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_QUIT]= quit_command_handler;
+  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_FLUSH]= flush_command_handler;
+  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_GETQ]= get_command_handler;
+  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_NOOP]= noop_command_handler;
+  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_VERSION]= version_command_handler;
+  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_GETK]= get_command_handler;
+  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_GETKQ]= get_command_handler;
+  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_APPEND]= concat_command_handler;
+  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_PREPEND]= concat_command_handler;
+  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_STAT]= stat_command_handler;
+  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_SETQ]= set_command_handler;
+  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_ADDQ]= add_command_handler;
+  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_REPLACEQ]= replace_command_handler;
+  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_DELETEQ]= delete_command_handler;
+  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_INCREMENTQ]= arithmetic_command_handler;
+  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_DECREMENTQ]= arithmetic_command_handler;
+  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_QUITQ]= quit_command_handler;
+  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_FLUSHQ]= flush_command_handler;
+  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_APPENDQ]= concat_command_handler;
+  interface_v0_impl.interface.v0.comcode[PROTOCOL_BINARY_CMD_PREPENDQ]= concat_command_handler;
+}
diff --git a/example/interface_v1.c b/example/interface_v1.c
deleted file mode 100644 (file)
index d2b2071..0000000
+++ /dev/null
@@ -1,411 +0,0 @@
-/* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */
-/**
- * This file contains an implementation of the callback interface for level 1
- * in the protocol library. If you compare the implementation with the one
- * in interface_v0.c you will see that this implementation is much easier and
- * hides all of the protocol logic and let you focus on the application
- * logic. One "problem" with this layer is that it is synchronous, so that
- * you will not receive the next command before a answer to the previous
- * command is being sent.
- */
-#include "config.h"
-#include <assert.h>
-#include <sys/types.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <libmemcachedprotocol-0.0/handler.h>
-#include <example/byteorder.h>
-#include "storage.h"
-
-static protocol_binary_response_status add_handler(const void *cookie,
-                                                   const void *key,
-                                                   uint16_t keylen,
-                                                   const void *data,
-                                                   uint32_t datalen,
-                                                   uint32_t flags,
-                                                   uint32_t exptime,
-                                                   uint64_t *cas)
-{
-  (void)cookie;
-  protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS;
-  struct item* item= get_item(key, keylen);
-  if (item == NULL)
-  {
-    item= create_item(key, keylen, data, datalen, flags, (time_t)exptime);
-    if (item == 0)
-    {
-      rval= PROTOCOL_BINARY_RESPONSE_ENOMEM;
-    }
-    else
-    {
-      put_item(item);
-      *cas= item->cas;
-      release_item(item);
-    }
-  }
-  else
-  {
-    rval= PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS;
-  }
-
-  return rval;
-}
-
-static protocol_binary_response_status append_handler(const void *cookie,
-                                                      const void *key,
-                                                      uint16_t keylen,
-                                                      const void* val,
-                                                      uint32_t vallen,
-                                                      uint64_t cas,
-                                                      uint64_t *result_cas)
-{
-  (void)cookie;
-  protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS;
-
-  struct item *item= get_item(key, keylen);
-  struct item *nitem;
-
-  if (item == NULL)
-  {
-    rval= PROTOCOL_BINARY_RESPONSE_KEY_ENOENT;
-  }
-  else if (cas != 0 && cas != item->cas)
-  {
-    rval= PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS;
-  }
-  else if ((nitem= create_item(key, keylen, NULL, item->size + vallen,
-                               item->flags, item->exp)) == NULL)
-  {
-    release_item(item);
-    rval= PROTOCOL_BINARY_RESPONSE_ENOMEM;
-  }
-  else
-  {
-    memcpy(nitem->data, item->data, item->size);
-    memcpy(((char*)(nitem->data)) + item->size, val, vallen);
-    release_item(item);
-    delete_item(key, keylen);
-    put_item(nitem);
-    *result_cas= nitem->cas;
-    release_item(nitem);
-  }
-
-  return rval;
-}
-
-static protocol_binary_response_status decrement_handler(const void *cookie,
-                                                         const void *key,
-                                                         uint16_t keylen,
-                                                         uint64_t delta,
-                                                         uint64_t initial,
-                                                         uint32_t expiration,
-                                                         uint64_t *result,
-                                                         uint64_t *result_cas) {
-  (void)cookie;
-  protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS;
-  uint64_t val= initial;
-  struct item *item= get_item(key, keylen);
-
-  if (item != NULL)
-  {
-    if (delta > *(uint64_t*)item->data)
-      val= 0;
-    else
-      val= *(uint64_t*)item->data - delta;
-
-    expiration= (uint32_t)item->exp;
-    release_item(item);
-    delete_item(key, keylen);
-  }
-
-  item= create_item(key, keylen, NULL, sizeof(initial), 0, (time_t)expiration);
-  if (item == 0)
-  {
-    rval= PROTOCOL_BINARY_RESPONSE_ENOMEM;
-  }
-  else
-  {
-    memcpy(item->data, &val, sizeof(val));
-    put_item(item);
-    *result= val;
-    *result_cas= item->cas;
-    release_item(item);
-  }
-
-  return rval;
-}
-
-static protocol_binary_response_status delete_handler(const void *cookie,
-                                                      const void *key,
-                                                      uint16_t keylen,
-                                                      uint64_t cas) {
-  (void)cookie;
-  protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS;
-
-  if (cas != 0)
-  {
-    struct item *item= get_item(key, keylen);
-    if (item != NULL)
-    {
-      if (item->cas != cas)
-      {
-        release_item(item);
-        return PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS;
-      }
-      release_item(item);
-    }
-  }
-
-  if (!delete_item(key, keylen))
-  {
-    rval= PROTOCOL_BINARY_RESPONSE_KEY_ENOENT;
-  }
-
-  return rval;
-}
-
-
-static protocol_binary_response_status flush_handler(const void *cookie,
-                                                     uint32_t when) {
-
-  (void)cookie;
-  flush(when);
-  return PROTOCOL_BINARY_RESPONSE_SUCCESS;
-}
-
-static protocol_binary_response_status get_handler(const void *cookie,
-                                                   const void *key,
-                                                   uint16_t keylen,
-                                                   memcached_binary_protocol_get_response_handler response_handler) {
-  struct item *item= get_item(key, keylen);
-
-  if (item == NULL)
-  {
-    return PROTOCOL_BINARY_RESPONSE_KEY_ENOENT;
-  }
-
-  protocol_binary_response_status rc;
-  rc= response_handler(cookie, key, (uint16_t)keylen,
-                          item->data, (uint32_t)item->size, item->flags,
-                          item->cas);
-  release_item(item);
-  return rc;
-}
-
-static protocol_binary_response_status increment_handler(const void *cookie,
-                                                         const void *key,
-                                                         uint16_t keylen,
-                                                         uint64_t delta,
-                                                         uint64_t initial,
-                                                         uint32_t expiration,
-                                                         uint64_t *result,
-                                                         uint64_t *result_cas) {
-  (void)cookie;
-  protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS;
-  uint64_t val= initial;
-  struct item *item= get_item(key, keylen);
-
-  if (item != NULL)
-  {
-    val= (*(uint64_t*)item->data) + delta;
-    expiration= (uint32_t)item->exp;
-    release_item(item);
-    delete_item(key, keylen);
-  }
-
-  item= create_item(key, keylen, NULL, sizeof(initial), 0, (time_t)expiration);
-  if (item == NULL)
-  {
-    rval= PROTOCOL_BINARY_RESPONSE_ENOMEM;
-  }
-  else
-  {
-    char buffer[1024] = {0};
-    memcpy(buffer, key, keylen);
-    memcpy(item->data, &val, sizeof(val));
-    put_item(item);
-    *result= val;
-    *result_cas= item->cas;
-    release_item(item);
-  }
-
-  return rval;
-}
-
-static protocol_binary_response_status noop_handler(const void *cookie) {
-  (void)cookie;
-  return PROTOCOL_BINARY_RESPONSE_SUCCESS;
-}
-
-static protocol_binary_response_status prepend_handler(const void *cookie,
-                                                       const void *key,
-                                                       uint16_t keylen,
-                                                       const void* val,
-                                                       uint32_t vallen,
-                                                       uint64_t cas,
-                                                       uint64_t *result_cas) {
-  (void)cookie;
-  protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS;
-
-  struct item *item= get_item(key, keylen);
-  struct item *nitem= NULL;
-
-  if (item == NULL)
-  {
-    rval= PROTOCOL_BINARY_RESPONSE_KEY_ENOENT;
-  }
-  else if (cas != 0 && cas != item->cas)
-  {
-    rval= PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS;
-  }
-  else if ((nitem= create_item(key, keylen, NULL, item->size + vallen,
-                                 item->flags, item->exp)) == NULL)
-  {
-    rval= PROTOCOL_BINARY_RESPONSE_ENOMEM;
-  }
-  else
-  {
-    memcpy(nitem->data, val, vallen);
-    memcpy(((char*)(nitem->data)) + vallen, item->data, item->size);
-    release_item(item);
-    item= NULL;
-    delete_item(key, keylen);
-    put_item(nitem);
-    *result_cas= nitem->cas;
-  }
-
-  if (item)
-    release_item(item);
-
-  if (nitem)
-    release_item(nitem);
-
-  return rval;
-}
-
-static protocol_binary_response_status quit_handler(const void *cookie) {
-  (void)cookie;
-  return PROTOCOL_BINARY_RESPONSE_SUCCESS;
-}
-
-static protocol_binary_response_status replace_handler(const void *cookie,
-                                                       const void *key,
-                                                       uint16_t keylen,
-                                                       const void* data,
-                                                       uint32_t datalen,
-                                                       uint32_t flags,
-                                                       uint32_t exptime,
-                                                       uint64_t cas,
-                                                       uint64_t *result_cas) {
-  (void)cookie;
-  protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS;
-  struct item* item= get_item(key, keylen);
-
-  if (item == NULL)
-  {
-    rval= PROTOCOL_BINARY_RESPONSE_KEY_ENOENT;
-  }
-  else if (cas == 0 || cas == item->cas)
-  {
-    release_item(item);
-    delete_item(key, keylen);
-    item= create_item(key, keylen, data, datalen, flags, (time_t)exptime);
-    if (item == 0)
-    {
-      rval= PROTOCOL_BINARY_RESPONSE_ENOMEM;
-    }
-    else
-    {
-      put_item(item);
-      *result_cas= item->cas;
-      release_item(item);
-    }
-  }
-  else
-  {
-    rval= PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS;
-    release_item(item);
-  }
-
-  return rval;
-}
-
-static protocol_binary_response_status set_handler(const void *cookie,
-                                                   const void *key,
-                                                   uint16_t keylen,
-                                                   const void* data,
-                                                   uint32_t datalen,
-                                                   uint32_t flags,
-                                                   uint32_t exptime,
-                                                   uint64_t cas,
-                                                   uint64_t *result_cas) {
-  (void)cookie;
-  protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS;
-
-  if (cas != 0)
-  {
-    struct item* item= get_item(key, keylen);
-    if (item != NULL && cas != item->cas)
-    {
-      /* Invalid CAS value */
-      release_item(item);
-      return PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS;
-    }
-  }
-
-  delete_item(key, keylen);
-  struct item* item= create_item(key, keylen, data, datalen, flags, (time_t)exptime);
-  if (item == 0)
-  {
-    rval= PROTOCOL_BINARY_RESPONSE_ENOMEM;
-  }
-  else
-  {
-    put_item(item);
-    *result_cas= item->cas;
-    release_item(item);
-  }
-
-  return rval;
-}
-
-static protocol_binary_response_status stat_handler(const void *cookie,
-                                                    const void *key,
-                                                    uint16_t keylen,
-                                                    memcached_binary_protocol_stat_response_handler response_handler) {
-  (void)key;
-  (void)keylen;
-  /* Just return an empty packet */
-  return response_handler(cookie, NULL, 0, NULL, 0);
-}
-
-static protocol_binary_response_status version_handler(const void *cookie,
-                                                       memcached_binary_protocol_version_response_handler response_handler) {
-  const char *version= "0.1.1";
-  return response_handler(cookie, version, (uint32_t)strlen(version));
-}
-
-memcached_binary_protocol_callback_st interface_v1_impl= {
-  .interface_version= MEMCACHED_PROTOCOL_HANDLER_V1,
-  .interface.v1= {
-    .add= add_handler,
-    .append= append_handler,
-    .decrement= decrement_handler,
-    .delete= delete_handler,
-    .flush= flush_handler,
-    .get= get_handler,
-    .increment= increment_handler,
-    .noop= noop_handler,
-    .prepend= prepend_handler,
-    .quit= quit_handler,
-    .replace= replace_handler,
-    .set= set_handler,
-    .stat= stat_handler,
-    .version= version_handler
-  }
-};
diff --git a/example/interface_v1.cc b/example/interface_v1.cc
new file mode 100644 (file)
index 0000000..8afe12a
--- /dev/null
@@ -0,0 +1,417 @@
+/* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */
+/**
+ * This file contains an implementation of the callback interface for level 1
+ * in the protocol library. If you compare the implementation with the one
+ * in interface_v0.cc you will see that this implementation is much easier and
+ * hides all of the protocol logic and let you focus on the application
+ * logic. One "problem" with this layer is that it is synchronous, so that
+ * you will not receive the next command before a answer to the previous
+ * command is being sent.
+ */
+#include "config.h"
+
+#include <cassert>
+#include <cerrno>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <libmemcachedprotocol-0.0/handler.h>
+#include <example/byteorder.h>
+#include "example/memcached_light.h"
+#include "example/storage.h"
+#include "util/log.hpp"
+
+static datadifferential::util::log_info_st *log_file= NULL;
+
+static protocol_binary_response_status add_handler(const void *cookie,
+                                                   const void *key,
+                                                   uint16_t keylen,
+                                                   const void *data,
+                                                   uint32_t datalen,
+                                                   uint32_t flags,
+                                                   uint32_t exptime,
+                                                   uint64_t *cas)
+{
+  (void)cookie;
+  protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS;
+  struct item* item= get_item(key, keylen);
+  if (item == NULL)
+  {
+    item= create_item(key, keylen, data, datalen, flags, (time_t)exptime);
+    if (item == 0)
+    {
+      rval= PROTOCOL_BINARY_RESPONSE_ENOMEM;
+    }
+    else
+    {
+      put_item(item);
+      *cas= item->cas;
+      release_item(item);
+    }
+  }
+  else
+  {
+    rval= PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS;
+  }
+
+  return rval;
+}
+
+static protocol_binary_response_status append_handler(const void *cookie,
+                                                      const void *key,
+                                                      uint16_t keylen,
+                                                      const void* val,
+                                                      uint32_t vallen,
+                                                      uint64_t cas,
+                                                      uint64_t *result_cas)
+{
+  (void)cookie;
+  protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS;
+
+  struct item *item= get_item(key, keylen);
+  struct item *nitem;
+
+  if (item == NULL)
+  {
+    rval= PROTOCOL_BINARY_RESPONSE_KEY_ENOENT;
+  }
+  else if (cas != 0 && cas != item->cas)
+  {
+    rval= PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS;
+  }
+  else if ((nitem= create_item(key, keylen, NULL, item->size + vallen,
+                               item->flags, item->exp)) == NULL)
+  {
+    release_item(item);
+    rval= PROTOCOL_BINARY_RESPONSE_ENOMEM;
+  }
+  else
+  {
+    memcpy(nitem->data, item->data, item->size);
+    memcpy(((char*)(nitem->data)) + item->size, val, vallen);
+    release_item(item);
+    delete_item(key, keylen);
+    put_item(nitem);
+    *result_cas= nitem->cas;
+    release_item(nitem);
+  }
+
+  return rval;
+}
+
+static protocol_binary_response_status decrement_handler(const void *cookie,
+                                                         const void *key,
+                                                         uint16_t keylen,
+                                                         uint64_t delta,
+                                                         uint64_t initial,
+                                                         uint32_t expiration,
+                                                         uint64_t *result,
+                                                         uint64_t *result_cas) {
+  (void)cookie;
+  protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS;
+  uint64_t val= initial;
+  struct item *item= get_item(key, keylen);
+
+  if (item != NULL)
+  {
+    if (delta > *(uint64_t*)item->data)
+      val= 0;
+    else
+      val= *(uint64_t*)item->data - delta;
+
+    expiration= (uint32_t)item->exp;
+    release_item(item);
+    delete_item(key, keylen);
+  }
+
+  item= create_item(key, keylen, NULL, sizeof(initial), 0, (time_t)expiration);
+  if (item == 0)
+  {
+    rval= PROTOCOL_BINARY_RESPONSE_ENOMEM;
+  }
+  else
+  {
+    memcpy(item->data, &val, sizeof(val));
+    put_item(item);
+    *result= val;
+    *result_cas= item->cas;
+    release_item(item);
+  }
+
+  return rval;
+}
+
+static protocol_binary_response_status delete_handler(const void *, // cookie
+                                                      const void *key,
+                                                      uint16_t keylen,
+                                                      uint64_t cas)
+{
+  protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS;
+
+  if (cas != 0)
+  {
+    struct item *item= get_item(key, keylen);
+    if (item != NULL)
+    {
+      if (item->cas != cas)
+      {
+        release_item(item);
+        return PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS;
+      }
+      release_item(item);
+    }
+  }
+
+  if (!delete_item(key, keylen))
+  {
+    rval= PROTOCOL_BINARY_RESPONSE_KEY_ENOENT;
+  }
+
+  return rval;
+}
+
+
+static protocol_binary_response_status flush_handler(const void * /* cookie */, uint32_t /* when */)
+{
+  return PROTOCOL_BINARY_RESPONSE_SUCCESS;
+}
+
+static protocol_binary_response_status get_handler(const void *cookie,
+                                                   const void *key,
+                                                   uint16_t keylen,
+                                                   memcached_binary_protocol_get_response_handler response_handler) {
+  struct item *item= get_item(key, keylen);
+
+  if (item == NULL)
+  {
+    return PROTOCOL_BINARY_RESPONSE_KEY_ENOENT;
+  }
+
+  protocol_binary_response_status rc;
+  rc= response_handler(cookie, key, (uint16_t)keylen,
+                          item->data, (uint32_t)item->size, item->flags,
+                          item->cas);
+  release_item(item);
+  return rc;
+}
+
+static protocol_binary_response_status increment_handler(const void *cookie,
+                                                         const void *key,
+                                                         uint16_t keylen,
+                                                         uint64_t delta,
+                                                         uint64_t initial,
+                                                         uint32_t expiration,
+                                                         uint64_t *result,
+                                                         uint64_t *result_cas) {
+  (void)cookie;
+  protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS;
+  uint64_t val= initial;
+  struct item *item= get_item(key, keylen);
+
+  if (item != NULL)
+  {
+    val= (*(uint64_t*)item->data) + delta;
+    expiration= (uint32_t)item->exp;
+    release_item(item);
+    delete_item(key, keylen);
+  }
+
+  item= create_item(key, keylen, NULL, sizeof(initial), 0, (time_t)expiration);
+  if (item == NULL)
+  {
+    rval= PROTOCOL_BINARY_RESPONSE_ENOMEM;
+  }
+  else
+  {
+    char buffer[1024] = {0};
+    memcpy(buffer, key, keylen);
+    memcpy(item->data, &val, sizeof(val));
+    put_item(item);
+    *result= val;
+    *result_cas= item->cas;
+    release_item(item);
+  }
+
+  return rval;
+}
+
+static protocol_binary_response_status noop_handler(const void *cookie) {
+  (void)cookie;
+  return PROTOCOL_BINARY_RESPONSE_SUCCESS;
+}
+
+static protocol_binary_response_status prepend_handler(const void *cookie,
+                                                       const void *key,
+                                                       uint16_t keylen,
+                                                       const void* val,
+                                                       uint32_t vallen,
+                                                       uint64_t cas,
+                                                       uint64_t *result_cas) {
+  (void)cookie;
+  protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS;
+
+  struct item *item= get_item(key, keylen);
+  struct item *nitem= NULL;
+
+  if (item == NULL)
+  {
+    rval= PROTOCOL_BINARY_RESPONSE_KEY_ENOENT;
+  }
+  else if (cas != 0 && cas != item->cas)
+  {
+    rval= PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS;
+  }
+  else if ((nitem= create_item(key, keylen, NULL, item->size + vallen,
+                                 item->flags, item->exp)) == NULL)
+  {
+    rval= PROTOCOL_BINARY_RESPONSE_ENOMEM;
+  }
+  else
+  {
+    memcpy(nitem->data, val, vallen);
+    memcpy(((char*)(nitem->data)) + vallen, item->data, item->size);
+    release_item(item);
+    item= NULL;
+    delete_item(key, keylen);
+    put_item(nitem);
+    *result_cas= nitem->cas;
+  }
+
+  if (item)
+    release_item(item);
+
+  if (nitem)
+    release_item(nitem);
+
+  return rval;
+}
+
+static protocol_binary_response_status quit_handler(const void *) //cookie
+{
+  return PROTOCOL_BINARY_RESPONSE_SUCCESS;
+}
+
+static protocol_binary_response_status replace_handler(const void *, // cookie
+                                                       const void *key,
+                                                       uint16_t keylen,
+                                                       const void* data,
+                                                       uint32_t datalen,
+                                                       uint32_t flags,
+                                                       uint32_t exptime,
+                                                       uint64_t cas,
+                                                       uint64_t *result_cas)
+{
+  protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS;
+  struct item* item= get_item(key, keylen);
+
+  if (item == NULL)
+  {
+    rval= PROTOCOL_BINARY_RESPONSE_KEY_ENOENT;
+  }
+  else if (cas == 0 || cas == item->cas)
+  {
+    release_item(item);
+    delete_item(key, keylen);
+    item= create_item(key, keylen, data, datalen, flags, (time_t)exptime);
+    if (item == 0)
+    {
+      rval= PROTOCOL_BINARY_RESPONSE_ENOMEM;
+    }
+    else
+    {
+      put_item(item);
+      *result_cas= item->cas;
+      release_item(item);
+    }
+  }
+  else
+  {
+    rval= PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS;
+    release_item(item);
+  }
+
+  return rval;
+}
+
+static protocol_binary_response_status set_handler(const void *cookie,
+                                                   const void *key,
+                                                   uint16_t keylen,
+                                                   const void* data,
+                                                   uint32_t datalen,
+                                                   uint32_t flags,
+                                                   uint32_t exptime,
+                                                   uint64_t cas,
+                                                   uint64_t *result_cas) {
+  (void)cookie;
+  protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS;
+
+  if (cas != 0)
+  {
+    struct item* item= get_item(key, keylen);
+    if (item != NULL && cas != item->cas)
+    {
+      /* Invalid CAS value */
+      release_item(item);
+      return PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS;
+    }
+  }
+
+  delete_item(key, keylen);
+  struct item* item= create_item(key, keylen, data, datalen, flags, (time_t)exptime);
+  if (item == 0)
+  {
+    rval= PROTOCOL_BINARY_RESPONSE_ENOMEM;
+  }
+  else
+  {
+    put_item(item);
+    *result_cas= item->cas;
+    release_item(item);
+  }
+
+  return rval;
+}
+
+static protocol_binary_response_status stat_handler(const void *cookie,
+                                                    const void *, // key
+                                                    uint16_t, // keylen,
+                                                    memcached_binary_protocol_stat_response_handler response_handler)
+{
+  /* Just return an empty packet */
+  return response_handler(cookie, NULL, 0, NULL, 0);
+}
+
+static protocol_binary_response_status version_handler(const void *cookie,
+                                                       memcached_binary_protocol_version_response_handler response_handler)
+{
+  const char *version= "0.1.1";
+  return response_handler(cookie, version, (uint32_t)strlen(version));
+}
+
+memcached_binary_protocol_callback_st interface_v1_impl;
+
+void initialize_interface_v1_handler(datadifferential::util::log_info_st& arg)
+{
+  log_file= &arg;
+  memset(&interface_v1_impl, 0, sizeof(memcached_binary_protocol_callback_st));
+
+  interface_v1_impl.interface_version= MEMCACHED_PROTOCOL_HANDLER_V1;
+  interface_v1_impl.interface.v1.add= add_handler;
+  interface_v1_impl.interface.v1.append= append_handler;
+  interface_v1_impl.interface.v1.decrement= decrement_handler;
+  interface_v1_impl.interface.v1.delete_object= delete_handler;
+  interface_v1_impl.interface.v1.flush_object= flush_handler;
+  interface_v1_impl.interface.v1.get= get_handler;
+  interface_v1_impl.interface.v1.increment= increment_handler;
+  interface_v1_impl.interface.v1.noop= noop_handler;
+  interface_v1_impl.interface.v1.prepend= prepend_handler;
+  interface_v1_impl.interface.v1.quit= quit_handler;
+  interface_v1_impl.interface.v1.replace= replace_handler;
+  interface_v1_impl.interface.v1.set= set_handler;
+  interface_v1_impl.interface.v1.stat= stat_handler;
+  interface_v1_impl.interface.v1.version= version_handler;
+}
diff --git a/example/memcached_light.c b/example/memcached_light.c
deleted file mode 100644 (file)
index c064e51..0000000
+++ /dev/null
@@ -1,475 +0,0 @@
-/* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */
-/**
- * What is a library without an example to show you how to use the library?
- * This example use both interfaces to implement a small memcached server.
- * Please note that this is an exemple on how to use the library, not
- * an implementation of a scalable memcached server. If you look closely
- * at the example it isn't even multithreaded ;-)
- *
- * With that in mind, let me give you some pointers into the source:
- *   storage.c/h       - Implements the item store for this server and not really
- *                       interesting for this example.
- *   interface_v0.c    - Shows an implementation of the memcached server by using
- *                       the "raw" access to the packets as they arrive
- *   interface_v1.c    - Shows an implementation of the memcached server by using
- *                       the more "logical" interface.
- *   memcached_light.c - This file sets up all of the sockets and run the main
- *                       message loop.
- *
- *
- * config.h is included so that I can use the ntohll/htonll on platforms that
- * doesn't have that (this is a private function inside libmemcached, so you
- * cannot use it directly from libmemcached without special modifications to
- * the library)
- */
-
-#include "config.h"
-#include <assert.h>
-#include <sys/types.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <event.h>
-
-#include <libmemcachedprotocol-0.0/handler.h>
-#include <libmemcached/socket.hpp>
-#include <example/byteorder.h>
-#include "example/storage.h"
-#include "example/memcached_light.h"
-
-extern memcached_binary_protocol_callback_st interface_v0_impl;
-extern memcached_binary_protocol_callback_st interface_v1_impl;
-
-static memcached_socket_t server_sockets[1024];
-static int num_server_sockets= 0;
-
-struct connection
-{
-  void *userdata;
-  struct event event;
-};
-
-/* The default maximum number of connections... (change with -c) */
-static int maxconns = 1024;
-
-static struct connection *socket_userdata_map;
-static bool verbose= false;
-static struct event_base *event_base;
-
-struct options_st {
-  char *pid_file;
-  bool has_port;
-  in_port_t port;
-} global_options;
-
-typedef struct options_st options_st;
-
-/**
- * Callback for driving a client connection
- * @param fd the socket for the client socket
- * @param which identifying the event that occurred (not used)
- * @param arg the connection structure for the client
- */
-static void drive_client(memcached_socket_t fd, short which, void *arg)
-{
-  (void)which;
-  struct connection *client= arg;
-  struct memcached_protocol_client_st* c= client->userdata;
-  assert(c != NULL);
-
-  memcached_protocol_event_t events= memcached_protocol_client_work(c);
-  if (events & MEMCACHED_PROTOCOL_ERROR_EVENT)
-  {
-    memcached_protocol_client_destroy(c);
-    closesocket(fd);
-  } else {
-    short flags = 0;
-    if (events & MEMCACHED_PROTOCOL_WRITE_EVENT)
-    {
-      flags= EV_WRITE;
-    }
-
-    if (events & MEMCACHED_PROTOCOL_READ_EVENT)
-    {
-      flags|= EV_READ;
-    }
-
-    event_set(&client->event, (intptr_t)fd, flags, drive_client, client);
-    event_base_set(event_base, &client->event);
-
-    if (event_add(&client->event, 0) == -1)
-    {
-      (void)fprintf(stderr, "Failed to add event for %d\n", fd);
-      memcached_protocol_client_destroy(c);
-      closesocket(fd);
-    }
-  }
-}
-
-/**
- * Callback for accepting new connections
- * @param fd the socket for the server socket
- * @param which identifying the event that occurred (not used)
- * @param arg the connection structure for the server
- */
-static void accept_handler(memcached_socket_t fd, short which, void *arg)
-{
-  (void)which;
-  struct connection *server= arg;
-  /* accept new client */
-  struct sockaddr_storage addr;
-  socklen_t addrlen= sizeof(addr);
-  memcached_socket_t sock= accept(fd, (struct sockaddr *)&addr, &addrlen);
-
-  if (sock == INVALID_SOCKET)
-  {
-    perror("Failed to accept client");
-    return ;
-  }
-
-#ifndef WIN32
-  if (sock >= maxconns)
-  {
-    (void)fprintf(stderr, "Client outside socket range (specified with -c)\n");
-    closesocket(sock);
-    return ;
-  }
-#endif
-
-  struct memcached_protocol_client_st* c;
-  c= memcached_protocol_create_client(server->userdata, sock);
-  if (c == NULL)
-  {
-    (void)fprintf(stderr, "Failed to create client\n");
-    closesocket(sock);
-  }
-  else
-  {
-    struct connection *client = &socket_userdata_map[sock];
-    client->userdata= c;
-
-    event_set(&client->event, (intptr_t)sock, EV_READ, drive_client, client);
-    event_base_set(event_base, &client->event);
-    if (event_add(&client->event, 0) == -1)
-    {
-      (void)fprintf(stderr, "Failed to add event for %d\n", sock);
-      memcached_protocol_client_destroy(c);
-      closesocket(sock);
-    }
-  }
-}
-
-/**
- * Create a socket and bind it to a specific port number
- * @param port the port number to bind to
- */
-static int server_socket(const char *port)
-{
-  struct addrinfo *ai;
-  struct addrinfo hints= { .ai_flags= AI_PASSIVE,
-                           .ai_family= AF_UNSPEC,
-                           .ai_socktype= SOCK_STREAM };
-
-  int error= getaddrinfo("127.0.0.1", port, &hints, &ai);
-  if (error != 0)
-  {
-    if (error != EAI_SYSTEM)
-      fprintf(stderr, "getaddrinfo(): %s\n", gai_strerror(error));
-    else
-      perror("getaddrinfo()");
-
-    return 0;
-  }
-
-  struct linger ling= {0, 0};
-
-  for (struct addrinfo *next= ai; next; next= next->ai_next)
-  {
-    memcached_socket_t sock= socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
-    if (sock == INVALID_SOCKET)
-    {
-      perror("Failed to create socket");
-      continue;
-    }
-
-    int flags;
-#ifdef WIN32
-    u_long arg = 1;
-    if (ioctlsocket(sock, FIONBIO, &arg) == SOCKET_ERROR)
-    {
-      perror("Failed to set nonblocking io");
-      closesocket(sock);
-      continue;
-    }
-#else
-    flags= fcntl(sock, F_GETFL, 0);
-    if (flags == -1)
-    {
-      perror("Failed to get socket flags");
-      closesocket(sock);
-      continue;
-    }
-
-    if ((flags & O_NONBLOCK) != O_NONBLOCK)
-    {
-      if (fcntl(sock, F_SETFL, flags | O_NONBLOCK) == -1)
-      {
-        perror("Failed to set socket to nonblocking mode");
-        closesocket(sock);
-        continue;
-      }
-    }
-#endif
-
-    flags= 1;
-    if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&flags, sizeof(flags)) != 0)
-      perror("Failed to set SO_REUSEADDR");
-
-    if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (void *)&flags, sizeof(flags)) != 0)
-      perror("Failed to set SO_KEEPALIVE");
-
-    if (setsockopt(sock, SOL_SOCKET, SO_LINGER, (void *)&ling, sizeof(ling)) != 0)
-      perror("Failed to set SO_LINGER");
-
-    if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (void *)&flags, sizeof(flags)) != 0)
-      perror("Failed to set TCP_NODELAY");
-
-    if (bind(sock, next->ai_addr, next->ai_addrlen) == SOCKET_ERROR)
-    {
-      if (get_socket_errno() != EADDRINUSE)
-      {
-        perror("bind()");
-        freeaddrinfo(ai);
-      }
-      closesocket(sock);
-      continue;
-    }
-
-    if (listen(sock, 1024) == SOCKET_ERROR)
-    {
-      perror("listen()");
-      closesocket(sock);
-      continue;
-    }
-
-    server_sockets[num_server_sockets++]= sock;
-  }
-
-  freeaddrinfo(ai);
-
-  return (num_server_sockets > 0) ? 0 : 1;
-}
-
-/**
- * Convert a command code to a textual string
- * @param cmd the comcode to convert
- * @return a textual string with the command or NULL for unknown commands
- */
-static const char* comcode2str(uint8_t cmd)
-{
-  static const char * const text[] = {
-    "GET", "SET", "ADD", "REPLACE", "DELETE",
-    "INCREMENT", "DECREMENT", "QUIT", "FLUSH",
-    "GETQ", "NOOP", "VERSION", "GETK", "GETKQ",
-    "APPEND", "PREPEND", "STAT", "SETQ", "ADDQ",
-    "REPLACEQ", "DELETEQ", "INCREMENTQ", "DECREMENTQ",
-    "QUITQ", "FLUSHQ", "APPENDQ", "PREPENDQ"
-  };
-
-  if (cmd <= PROTOCOL_BINARY_CMD_PREPENDQ)
-    return text[cmd];
-
-  return NULL;
-}
-
-/**
- * Print out the command we are about to execute
- */
-static void pre_execute(const void *cookie,
-                        protocol_binary_request_header *header)
-{
-  if (verbose)
-  {
-    const char *cmd= comcode2str(header->request.opcode);
-    if (cmd != NULL)
-      fprintf(stderr, "pre_execute from %p: %s\n", cookie, cmd);
-    else
-      fprintf(stderr, "pre_execute from %p: 0x%02x\n", cookie, header->request.opcode);
-  }
-}
-
-/**
- * Print out the command we just executed
- */
-static void post_execute(const void *cookie,
-                         protocol_binary_request_header *header)
-{
-  if (verbose)
-  {
-    const char *cmd= comcode2str(header->request.opcode);
-    if (cmd != NULL)
-      fprintf(stderr, "post_execute from %p: %s\n", cookie, cmd);
-    else
-      fprintf(stderr, "post_execute from %p: 0x%02x\n", cookie, header->request.opcode);
-  }
-}
-
-/**
- * Callback handler for all unknown commands.
- * Send an unknown command back to the client
- */
-static protocol_binary_response_status unknown(const void *cookie,
-                                               protocol_binary_request_header *header,
-                                               memcached_binary_protocol_raw_response_handler response_handler)
-{
-  protocol_binary_response_no_extras response= {
-    .message= {
-      .header.response= {
-        .magic= PROTOCOL_BINARY_RES,
-        .opcode= header->request.opcode,
-        .status= htons(PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND),
-        .opaque= header->request.opaque
-      }
-    }
-  };
-
-  return response_handler(cookie, header, (void*)&response);
-}
-
-/**
- * Program entry point. Bind to the specified port(s) and serve clients
- *
- * @param argc number of items in the argument vector
- * @param argv argument vector
- * @return EXIT_SUCCESS on success, 1 otherwise
- */
-int main(int argc, char **argv)
-{
-  int cmd;
-  memcached_binary_protocol_callback_st *interface= &interface_v0_impl;
-
-  memset(&global_options, 0, sizeof(global_options));
-
-  event_base= event_init();
-  if (event_base == NULL)
-  {
-    fprintf(stderr, "Failed to create an instance of libevent\n");
-    return EXIT_FAILURE;
-  }
-
-  /*
-   * We need to initialize the handlers manually due to a bug in the
-   * warnings generated by struct initialization in gcc (all the way up to 4.4)
-   */
-  initialize_interface_v0_handler();
-
-  while ((cmd= getopt(argc, argv, "v1p:P:?hc:")) != EOF)
-  {
-    switch (cmd) {
-    case '1':
-      interface= &interface_v1_impl;
-      break;
-    case 'P':
-      global_options.pid_file= strdup(optarg);
-      break;
-    case 'p':
-      global_options.has_port= true;
-      (void)server_socket(optarg);
-      break;
-    case 'v':
-      verbose= true;
-      break;
-    case 'c':
-      maxconns= atoi(optarg);
-      break;
-    case 'h':  /* FALLTHROUGH */
-    case '?':  /* FALLTHROUGH */
-    default:
-      (void)fprintf(stderr, "Usage: %s [-p port] [-v] [-1] [-c #clients] [-P pidfile]\n",
-                    argv[0]);
-      return EXIT_FAILURE;
-    }
-  }
-
-  if (! initialize_storage())
-  {
-    /* Error message already printed */
-    return EXIT_FAILURE;
-  }
-
-  if (! global_options.has_port)
-    (void)server_socket("9999");
-
-  if (global_options.pid_file)
-  {
-    FILE *pid_file;
-    uint32_t pid;
-
-    pid_file= fopen(global_options.pid_file, "w+");
-
-    if (pid_file == NULL)
-    {
-      perror(strerror(get_socket_errno()));
-      abort();
-    }
-
-    pid= (uint32_t)getpid();
-    fprintf(pid_file, "%u\n", pid);
-    fclose(pid_file);
-  }
-
-  if (num_server_sockets == 0)
-  {
-    fprintf(stderr, "I don't have any server sockets\n");
-    return EXIT_FAILURE;
-  }
-
-  /*
-   * Create and initialize the handles to the protocol handlers. I want
-   * to be able to trace the traffic throught the pre/post handlers, and
-   * set up a common handler for unknown messages
-   */
-  interface->pre_execute= pre_execute;
-  interface->post_execute= post_execute;
-  interface->unknown= unknown;
-
-  struct memcached_protocol_st *protocol_handle;
-  if ((protocol_handle= memcached_protocol_create_instance()) == NULL)
-  {
-    fprintf(stderr, "Failed to allocate protocol handle\n");
-    return EXIT_FAILURE;
-  }
-
-  socket_userdata_map= calloc((size_t)(maxconns), sizeof(struct connection));
-  if (socket_userdata_map == NULL)
-  {
-    fprintf(stderr, "Failed to allocate room for connections\n");
-    return EXIT_FAILURE;
-  }
-
-  memcached_binary_protocol_set_callbacks(protocol_handle, interface);
-  memcached_binary_protocol_set_pedantic(protocol_handle, true);
-
-  for (int xx= 0; xx < num_server_sockets; ++xx)
-  {
-    struct connection *conn= &socket_userdata_map[server_sockets[xx]];
-    conn->userdata= protocol_handle;
-    event_set(&conn->event, (intptr_t)server_sockets[xx], EV_READ | EV_PERSIST,
-              accept_handler, conn);
-    event_base_set(event_base, &conn->event);
-    if (event_add(&conn->event, 0) == -1)
-    {
-      fprintf(stderr, "Failed to add event for %d\n", server_sockets[xx]);
-      closesocket(server_sockets[xx]);
-    }
-  }
-
-  /* Serve all of the clients */
-  event_base_loop(event_base, 0);
-
-  /* NOTREACHED */
-  return EXIT_SUCCESS;
-}
diff --git a/example/memcached_light.cc b/example/memcached_light.cc
new file mode 100644 (file)
index 0000000..c92e5ea
--- /dev/null
@@ -0,0 +1,645 @@
+/* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */
+/**
+ * What is a library without an example to show you how to use the library?
+ * This example use both interfaces to implement a small memcached server.
+ * Please note that this is an exemple on how to use the library, not
+ * an implementation of a scalable memcached server. If you look closely
+ * at the example it isn't even multithreaded ;-)
+ *
+ * With that in mind, let me give you some pointers into the source:
+ *   storage.c/h       - Implements the item store for this server and not really
+ *                       interesting for this example.
+ *   interface_v0.cc   - Shows an implementation of the memcached server by using
+ *                       the "raw" access to the packets as they arrive
+ *   interface_v1.cc   - Shows an implementation of the memcached server by using
+ *                       the more "logical" interface.
+ *   memcached_light.cc- This file sets up all of the sockets and run the main
+ *                       message loop.
+ *
+ *
+ * config.h is included so that I can use the ntohll/htonll on platforms that
+ * doesn't have that (this is a private function inside libmemcached, so you
+ * cannot use it directly from libmemcached without special modifications to
+ * the library)
+ */
+
+#include <config.h>
+
+#include <libmemcachedprotocol-0.0/handler.h>
+#include <libmemcached/socket.hpp>
+#include <example/byteorder.h>
+#include "example/storage.h"
+#include "example/memcached_light.h"
+
+#include "util/daemon.hpp"
+#include "util/log.hpp"
+#include "util/pidfile.hpp"
+
+using namespace datadifferential;
+
+#include <event.h>
+
+#include <cassert>
+#include <cerrno>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <fcntl.h>
+#include <getopt.h>
+#include <iostream>
+#include <sys/types.h>
+#include <unistd.h>
+
+extern memcached_binary_protocol_callback_st interface_v0_impl;
+extern memcached_binary_protocol_callback_st interface_v1_impl;
+
+static memcached_socket_t server_sockets[1024];
+static int num_server_sockets= 0;
+
+struct connection
+{
+  void *userdata;
+  struct event event;
+};
+
+/* The default maximum number of connections... (change with -c) */
+static int maxconns= 1024;
+
+static struct connection *socket_userdata_map;
+static struct event_base *event_base= NULL;
+
+struct options_st {
+  std::string pid_file;
+  std::string service;
+  std::string log_file;
+  bool is_verbose;
+  bool opt_daemon;
+
+  options_st() :
+    service("9999"),
+    is_verbose(false)
+  {
+  }
+};
+
+static options_st global_options;
+
+/**
+ * Callback for driving a client connection
+ * @param fd the socket for the client socket
+ * @param which identifying the event that occurred (not used)
+ * @param arg the connection structure for the client
+ */
+static void drive_client(memcached_socket_t fd, short, void *arg)
+{
+  struct connection *client= (struct connection*)arg;
+  struct memcached_protocol_client_st* c= (struct memcached_protocol_client_st*)client->userdata;
+  assert(c != NULL);
+
+  memcached_protocol_event_t events= memcached_protocol_client_work(c);
+  if (events & MEMCACHED_PROTOCOL_ERROR_EVENT)
+  {
+    if (global_options.is_verbose)
+    {
+      struct sockaddr_in sin;
+      socklen_t addrlen= sizeof(sin);
+
+      if (getsockname(fd, (struct sockaddr *)&sin, &addrlen) != -1)
+      {
+        std::cout << __FILE__ << ":" << __LINE__
+          << " close(MEMCACHED_PROTOCOL_ERROR_EVENT)"
+          << " " << inet_ntoa(sin.sin_addr) << ":" << sin.sin_port
+          << " fd:" << fd
+          << std::endl;
+      }
+      else
+      {
+        std::cout << __FILE__ << ":" << __LINE__ << "close() MEMCACHED_PROTOCOL_ERROR_EVENT" << std::endl;
+      }
+    }
+
+    memcached_protocol_client_destroy(c);
+    closesocket(fd);
+  }
+  else
+  {
+    short flags = 0;
+    if (events & MEMCACHED_PROTOCOL_WRITE_EVENT)
+    {
+      flags= EV_WRITE;
+    }
+
+    if (events & MEMCACHED_PROTOCOL_READ_EVENT)
+    {
+      flags|= EV_READ;
+    }
+
+    event_set(&client->event, (intptr_t)fd, flags, drive_client, client);
+    event_base_set(event_base, &client->event);
+
+    if (event_add(&client->event, 0) == -1)
+    {
+      memcached_protocol_client_destroy(c);
+      closesocket(fd);
+    }
+  }
+}
+
+/**
+ * Callback for accepting new connections
+ * @param fd the socket for the server socket
+ * @param which identifying the event that occurred (not used)
+ * @param arg the connection structure for the server
+ */
+static void accept_handler(memcached_socket_t fd, short, void *arg)
+{
+  struct connection *server= (struct connection *)arg;
+  /* accept new client */
+  struct sockaddr_storage addr;
+  socklen_t addrlen= sizeof(addr);
+  memcached_socket_t sock= accept(fd, (struct sockaddr *)&addr, &addrlen);
+
+  if (sock == INVALID_SOCKET)
+  {
+    perror("Failed to accept client");
+  }
+
+#ifndef WIN32
+  if (sock >= maxconns)
+  {
+    closesocket(sock);
+    return ;
+  }
+#endif
+
+  struct memcached_protocol_client_st* c= memcached_protocol_create_client((memcached_protocol_st*)server->userdata, sock);
+  if (c == NULL)
+  {
+    closesocket(sock);
+  }
+  else
+  {
+    memcached_protocol_client_set_verbose(c, global_options.is_verbose);
+    struct connection *client = &socket_userdata_map[sock];
+    client->userdata= c;
+
+    event_set(&client->event, (intptr_t)sock, EV_READ, drive_client, client);
+    event_base_set(event_base, &client->event);
+    if (event_add(&client->event, 0) == -1)
+    {
+      std::cerr << "Failed to add event for " << sock << std::endl;
+      memcached_protocol_client_destroy(c);
+      closesocket(sock);
+    }
+  }
+}
+
+static bool server_socket(util::log_info_st& log_file, const std::string& service)
+{
+  struct addrinfo *ai;
+  struct addrinfo hints;
+  memset(&hints, 0, sizeof(struct addrinfo));
+
+  hints.ai_flags= AI_PASSIVE;
+  hints.ai_family= AF_UNSPEC;
+  hints.ai_socktype= SOCK_STREAM;
+
+  int error= getaddrinfo("127.0.0.1", service.c_str(), &hints, &ai);
+  if (error != 0)
+  {
+    if (error != EAI_SYSTEM)
+    {
+      std::string buffer("getaddrinfo: ");
+      buffer+= gai_strerror(error);
+      log_file.write(util::VERBOSE_ERROR, buffer.c_str());
+    }
+    else
+    {
+      std::string buffer("getaddrinfo: ");
+      buffer+= strerror(errno);
+      log_file.write(util::VERBOSE_ERROR, buffer.c_str());
+    }
+
+    return false;
+  }
+
+  struct linger ling= {0, 0};
+
+  for (struct addrinfo *next= ai; next; next= next->ai_next)
+  {
+    memcached_socket_t sock= socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
+    if (sock == INVALID_SOCKET)
+    {
+      std::string buffer("Failed to create socket: ");
+      buffer+= strerror(errno);
+      log_file.write(util::VERBOSE_ERROR, buffer.c_str());
+      continue;
+    }
+
+    int flags;
+#ifdef WIN32
+    u_long arg = 1;
+    if (ioctlsocket(sock, FIONBIO, &arg) == SOCKET_ERROR)
+    {
+      std::cerr << "Failed to set nonblocking io: " << strerror(errno) << std::endl;
+      closesocket(sock);
+      continue;
+    }
+#else
+    flags= fcntl(sock, F_GETFL, 0);
+    if (flags == -1)
+    {
+      std::string buffer("Failed to get socket flags: ");
+      buffer+= strerror(errno);
+      log_file.write(util::VERBOSE_ERROR, buffer.c_str());
+      closesocket(sock);
+      continue;
+    }
+
+    if ((flags & O_NONBLOCK) != O_NONBLOCK)
+    {
+      if (fcntl(sock, F_SETFL, flags | O_NONBLOCK) == -1)
+      {
+        std::string buffer("Failed to set socket to nonblocking mode: ");
+        buffer+= strerror(errno);
+        log_file.write(util::VERBOSE_ERROR, buffer.c_str());
+        closesocket(sock);
+        continue;
+      }
+    }
+#endif
+
+    flags= 1;
+    if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&flags, sizeof(flags)) != 0)
+    {
+      std::cerr << "Failed to set SO_REUSEADDR: " << strerror(errno) << std::endl;
+    }
+
+    if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (void *)&flags, sizeof(flags)) != 0)
+    {
+      std::cerr << "Failed to set SO_KEEPALIVE: " << strerror(errno) << std::endl;
+    }
+
+    if (setsockopt(sock, SOL_SOCKET, SO_LINGER, (void *)&ling, sizeof(ling)) != 0)
+    {
+      std::cerr << "Failed to set SO_LINGER: " << strerror(errno) << std::endl;
+    }
+
+    if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (void *)&flags, sizeof(flags)) != 0)
+    {
+      std::cerr << "Failed to set TCP_NODELAY: " << strerror(errno) << std::endl;
+    }
+
+    if (bind(sock, next->ai_addr, next->ai_addrlen) == SOCKET_ERROR)
+    {
+      if (get_socket_errno() != EADDRINUSE)
+      {
+        std::cerr << "bind(): " << strerror(errno) << std::endl;
+        freeaddrinfo(ai);
+      }
+      closesocket(sock);
+      continue;
+    }
+
+    if (listen(sock, 1024) == SOCKET_ERROR)
+    {
+      std::string buffer("listen(): ");
+      buffer+= strerror(errno);
+      log_file.write(util::VERBOSE_ERROR, buffer.c_str());
+      closesocket(sock);
+      continue;
+    }
+
+    if (global_options.is_verbose)
+    {
+      std::string buffer("Listening to: ");
+      buffer+= global_options.service;
+      log_file.write(util::VERBOSE_NOTICE, buffer.c_str());
+    }
+
+    server_sockets[num_server_sockets++]= sock;
+  }
+
+  freeaddrinfo(ai);
+
+  return (num_server_sockets > 0) ? true : false;
+}
+
+/**
+ * Convert a command code to a textual string
+ * @param cmd the comcode to convert
+ * @return a textual string with the command or NULL for unknown commands
+ */
+static const char* comcode2str(uint8_t cmd)
+{
+  static const char * const text[] = {
+    "GET", "SET", "ADD", "REPLACE", "DELETE",
+    "INCREMENT", "DECREMENT", "QUIT", "FLUSH",
+    "GETQ", "NOOP", "VERSION", "GETK", "GETKQ",
+    "APPEND", "PREPEND", "STAT", "SETQ", "ADDQ",
+    "REPLACEQ", "DELETEQ", "INCREMENTQ", "DECREMENTQ",
+    "QUITQ", "FLUSHQ", "APPENDQ", "PREPENDQ"
+  };
+
+  if (cmd <= PROTOCOL_BINARY_CMD_PREPENDQ)
+  {
+    return text[cmd];
+  }
+
+  return NULL;
+}
+
+/**
+ * Print out the command we are about to execute
+ */
+static void pre_execute(const void *cookie,
+                        protocol_binary_request_header *header)
+{
+  if (global_options.is_verbose)
+  {
+    if (header)
+    {
+      const char *cmd= comcode2str(header->request.opcode);
+      if (cmd != NULL)
+      {
+        std::cout << "pre_execute from " << cookie << ": " << cmd << std::endl;
+      }
+      else
+      {
+        std::cout << "pre_execute from " << cookie << ": " << header->request.opcode << std::endl;
+      }
+    }
+    else
+    {
+      std::cout << "pre_execute from " << cookie << std::endl;
+    }
+  }
+}
+
+/**
+ * Print out the command we just executed
+ */
+static void post_execute(const void *cookie,
+                         protocol_binary_request_header *header)
+{
+  if (global_options.is_verbose)
+  {
+    if (header)
+    {
+      const char *cmd= comcode2str(header->request.opcode);
+      if (cmd != NULL)
+      {
+        std::cout << "post_execute from " << cookie << ": " << cmd << std::endl;
+      }
+      else
+      {
+        std::cout << "post_execute from " << cookie << ": " << header->request.opcode << std::endl;
+      }
+    }
+    else
+    {
+      std::cout << "post_execute from " << cookie << std::endl;
+    }
+  }
+}
+
+/**
+ * Callback handler for all unknown commands.
+ * Send an unknown command back to the client
+ */
+static protocol_binary_response_status unknown(const void *cookie,
+                                               protocol_binary_request_header *header,
+                                               memcached_binary_protocol_raw_response_handler response_handler)
+{
+  protocol_binary_response_no_extras response;
+  memset(&response, 0, sizeof(protocol_binary_response_no_extras));
+
+  response.message.header.response.magic= PROTOCOL_BINARY_RES;
+  response.message.header.response.opcode= header->request.opcode;
+  response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND);
+  response.message.header.response.opaque= header->request.opaque;
+
+  return response_handler(cookie, header, (protocol_binary_response_header*)&response);
+}
+
+/**
+ * Program entry point. Bind to the specified port(s) and serve clients
+ *
+ * @param argc number of items in the argument vector
+ * @param argv argument vector
+ * @return EXIT_SUCCESS on success, 1 otherwise
+ */
+int main(int argc, char **argv)
+{
+  memcached_binary_protocol_callback_st *interface= &interface_v0_impl;
+
+  {
+    enum long_option_t {
+      OPT_HELP,
+      OPT_VERBOSE,
+      OPT_DAEMON,
+      OPT_PROTOCOL_VERSION,
+      OPT_VERSION,
+      OPT_PORT,
+      OPT_MAX_CONNECTIONS,
+      OPT_LOGFILE,
+      OPT_PIDFILE
+    };
+
+    static struct option long_options[]=
+    {
+      { "help", no_argument, NULL, OPT_HELP },
+      { "port", required_argument, NULL, OPT_PORT },
+      { "verbose", no_argument, NULL, OPT_VERBOSE },
+      { "daemon", no_argument, NULL, OPT_DAEMON },
+      { "protocol", no_argument, NULL, OPT_PROTOCOL_VERSION },
+      { "version", no_argument, NULL, OPT_VERSION },
+      { "max-connections", required_argument, NULL, OPT_MAX_CONNECTIONS },
+      { "pid-file", required_argument, NULL, OPT_PIDFILE },
+      { "log-file", required_argument, NULL, OPT_LOGFILE },
+      {0, 0, 0, 0}
+    };
+
+    bool opt_help= false;
+    int option_index;
+    bool done= false;
+    while (done == false)
+    {
+      switch (getopt_long(argc, argv, "", long_options, &option_index))
+      {
+      case -1:
+        done= true;
+        break;
+
+      case OPT_PROTOCOL_VERSION:
+        interface= &interface_v1_impl;
+        break;
+
+      case OPT_PIDFILE:
+        global_options.pid_file= optarg;
+        break;
+
+      case OPT_LOGFILE:
+        global_options.log_file= optarg;
+        break;
+
+      case OPT_VERBOSE:
+        global_options.is_verbose= true;
+        break;
+
+      case OPT_VERSION:
+        break;
+
+      case OPT_DAEMON:
+        global_options.opt_daemon= true;
+        break;
+
+      case OPT_PORT:
+        global_options.service= optarg;
+        break;
+
+      case OPT_MAX_CONNECTIONS:
+        maxconns= atoi(optarg);
+        break;
+
+      case OPT_HELP:  /* FALLTHROUGH */
+        opt_help= true;
+        break;
+
+      default:
+        {
+          std::cerr << "Unknown option: " << optarg << std::endl;
+          return EXIT_FAILURE;
+        }
+      }
+    }
+
+    if (opt_help)
+    {
+      std::cout << "Usage: " << argv[0] << std::endl;
+      for (struct option *ptr_option= long_options; ptr_option->name; ptr_option++)
+      {
+        std::cout << "\t" << ptr_option->name << std::endl;
+      }
+      return EXIT_SUCCESS;
+    }
+  }
+
+  if (global_options.opt_daemon)
+  {
+    util::daemonize(false, true);
+  }
+
+  if (initialize_storage() == false)
+  {
+    /* Error message already printed */
+    return EXIT_FAILURE;
+  }
+
+  util::Pidfile _pid_file(global_options.pid_file);
+
+  if (_pid_file.create() == false)
+  {
+    std::cerr << "Failed to create pid-file" <<  _pid_file.error_message() << std::endl;
+    return EXIT_FAILURE;
+  }
+
+  util::log_info_st log_file(argv[0], global_options.log_file, false);
+  log_file.write(util::VERBOSE_NOTICE, "starting log");
+
+  /*
+   * We need to initialize the handlers manually due to a bug in the
+   * warnings generated by struct initialization in gcc (all the way up to 4.4)
+   */
+  initialize_interface_v0_handler(log_file);
+  initialize_interface_v1_handler(log_file);
+
+
+  if (server_socket(log_file, global_options.service) == false)
+  {
+    return EXIT_FAILURE;
+  }
+
+  if (num_server_sockets == 0)
+  {
+    log_file.write(util::VERBOSE_ERROR, "No server sockets are available.");
+    return EXIT_FAILURE;
+  }
+
+  /*
+   * Create and initialize the handles to the protocol handlers. I want
+   * to be able to trace the traffic throught the pre/post handlers, and
+   * set up a common handler for unknown messages
+   */
+  interface->pre_execute= pre_execute;
+  interface->post_execute= post_execute;
+  interface->unknown= unknown;
+
+  struct memcached_protocol_st *protocol_handle;
+  if ((protocol_handle= memcached_protocol_create_instance()) == NULL)
+  {
+    log_file.write(util::VERBOSE_ERROR, "No server sockets are available.");
+    return EXIT_FAILURE;
+  }
+
+  socket_userdata_map= (struct connection*)calloc((size_t)(maxconns), sizeof(struct connection));
+  if (socket_userdata_map == NULL)
+  {
+    log_file.write(util::VERBOSE_ERROR, "Failed to allocate room for connections");
+    return EXIT_FAILURE;
+  }
+
+  memcached_binary_protocol_set_callbacks(protocol_handle, interface);
+  memcached_binary_protocol_set_pedantic(protocol_handle, true);
+
+  event_base= event_init();
+  if (event_base == NULL)
+  {
+    std::cerr << "Failed to create an instance of libevent" << std::endl;
+    return EXIT_FAILURE;
+  }
+
+  for (int xx= 0; xx < num_server_sockets; ++xx)
+  {
+    struct connection *conn= &socket_userdata_map[server_sockets[xx]];
+    conn->userdata= protocol_handle;
+
+    event_set(&conn->event, (intptr_t)server_sockets[xx], EV_READ | EV_PERSIST, accept_handler, conn);
+
+    event_base_set(event_base, &conn->event);
+    if (event_add(&conn->event, 0) == -1)
+    {
+      log_file.write(util::VERBOSE_ERROR, "Failed to add event");
+      closesocket(server_sockets[xx]);
+    }
+  }
+
+  if (global_options.opt_daemon)
+  {
+    if (util::daemon_is_ready(true) == false)
+    {
+      log_file.write(util::VERBOSE_ERROR, "Failed for util::daemon_is_ready()");
+      return EXIT_FAILURE;
+    }
+  }
+
+
+  /* Serve all of the clients */
+  switch (event_base_loop(event_base, 0))
+  {
+  case -1:
+    log_file.write(util::VERBOSE_ERROR, "event_base_loop() failed");
+    break;
+
+  case 1:
+    log_file.write(util::VERBOSE_ERROR, "event_base_loop(), no events were registered");
+    break;
+
+  default:
+    break;
+  }
+  log_file.write(util::VERBOSE_NOTICE, "exiting");
+
+  /* NOTREACHED */
+  return EXIT_SUCCESS;
+}
index 529169393fefd2e92215bc68b516cafd6aa67094..6abb8744910a4726f9ad608320a7646b83b6880a 100644 (file)
@@ -1,7 +1,44 @@
+/*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ * 
+ *  Memcached Light interface definitions
+ *
+ *  Copyright (C) 2012 Data Differential, http://datadifferential.com/
+ *  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.
+ *
+ */
+
 /* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */
-#ifndef MEMCACHED_LIGHT_H
-#define MEMCACHED_LIGHT_H
+#pragma once
 
-extern void initialize_interface_v0_handler(void);
+#include "util/log.hpp"
 
-#endif
+void initialize_interface_v0_handler(datadifferential::util::log_info_st&);
+void initialize_interface_v1_handler(datadifferential::util::log_info_st&);
diff --git a/example/storage.c b/example/storage.c
deleted file mode 100644 (file)
index 1fb7973..0000000
+++ /dev/null
@@ -1,172 +0,0 @@
-/* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */
-#include "config.h"
-#include <stdlib.h>
-#include <inttypes.h>
-#include <time.h>
-#include <stdbool.h>
-#include <string.h>
-#include "storage.h"
-
-struct list_entry {
-  struct item item;
-  struct list_entry *next;
-  struct list_entry *prev;
-};
-
-static struct list_entry *root;
-static uint64_t cas;
-
-bool initialize_storage(void)
-{
-  return true;
-}
-
-void shutdown_storage(void)
-{
-  /* Do nothing */
-}
-
-void put_item(struct item* item)
-{
-  struct list_entry* entry= (void*)item;
-
-  update_cas(item);
-
-  if (root == NULL)
-  {
-    entry->next= entry->prev= entry;
-  }
-  else
-  {
-    entry->prev= root->prev;
-    entry->next= root;
-    entry->prev->next= entry;
-    entry->next->prev= entry;
-  }
-
-  root= entry;
-}
-
-struct item* get_item(const void* key, size_t nkey)
-{
-  struct list_entry *walker= root;
-
-  if (root == NULL)
-  {
-    return NULL;
-  }
-
-  do
-  {
-    if (((struct item*)walker)->nkey == nkey &&
-        memcmp(((struct item*)walker)->key, key, nkey) == 0)
-    {
-      return (struct item*)walker;
-    }
-    walker= walker->next;
-  } while (walker != root);
-
-  return NULL;
-}
-
-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(struct list_entry));
-
-  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;
-}
-
-bool delete_item(const void* key, size_t nkey)
-{
-  struct item* item= get_item(key, nkey);
-  bool ret= false;
-
-  if (item)
-  {
-    /* remove from linked list */
-    struct list_entry *entry= (void*)item;
-
-    if (entry->next == entry)
-    {
-      /* Only one object in the list */
-      root= NULL;
-    }
-    else
-    {
-      /* ensure that we don't loose track of the root, and this will
-       * change the start position for the next search ;-) */
-      root= entry->next;
-      entry->prev->next= entry->next;
-      entry->next->prev= entry->prev;
-    }
-
-    free(item->key);
-    free(item->data);
-    free(item);
-    ret= true;
-  }
-
-  return ret;
-}
-
-void flush(uint32_t when)
-{
-  /* FIXME */
-  (void)when;
-  /* remove the complete linked list */
-  if (root == NULL)
-  {
-    return;
-  }
-
-  root->prev->next= NULL;
-  while (root != NULL)
-  {
-    struct item* tmp= (void*)root;
-    root= root->next;
-
-    free(tmp->key);
-    free(tmp->data);
-    free(tmp);
-  }
-}
-
-void update_cas(struct item* item)
-{
-  item->cas= ++cas;
-}
-
-void release_item(struct item* item)
-{
-  (void)item;
-  /* EMPTY */
-}
diff --git a/example/storage.cc b/example/storage.cc
new file mode 100644 (file)
index 0000000..2e63a3e
--- /dev/null
@@ -0,0 +1,168 @@
+/* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */
+#include "config.h"
+#include <stdlib.h>
+#include <inttypes.h>
+#include <time.h>
+#include <stdbool.h>
+#include <string.h>
+#include "storage.h"
+
+struct list_entry {
+  struct item item;
+  struct list_entry *next;
+  struct list_entry *prev;
+};
+
+static struct list_entry *root;
+static uint64_t cas;
+
+bool initialize_storage(void)
+{
+  return true;
+}
+
+void shutdown_storage(void)
+{
+  /* Do nothing */
+}
+
+void put_item(struct item* item)
+{
+  struct list_entry* entry= (struct list_entry*)item;
+
+  update_cas(item);
+
+  if (root == NULL)
+  {
+    entry->next= entry->prev= entry;
+  }
+  else
+  {
+    entry->prev= root->prev;
+    entry->next= root;
+    entry->prev->next= entry;
+    entry->next->prev= entry;
+  }
+
+  root= entry;
+}
+
+struct item* get_item(const void* key, size_t nkey)
+{
+  struct list_entry *walker= root;
+
+  if (root == NULL)
+  {
+    return NULL;
+  }
+
+  do
+  {
+    if (((struct item*)walker)->nkey == nkey &&
+        memcmp(((struct item*)walker)->key, key, nkey) == 0)
+    {
+      return (struct item*)walker;
+    }
+    walker= walker->next;
+  } while (walker != root);
+
+  return NULL;
+}
+
+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= (struct item*)calloc(1, sizeof(struct list_entry));
+
+  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;
+}
+
+bool delete_item(const void* key, size_t nkey)
+{
+  struct item* item= get_item(key, nkey);
+  bool ret= false;
+
+  if (item)
+  {
+    /* remove from linked list */
+    struct list_entry *entry= (struct list_entry*)item;
+
+    if (entry->next == entry)
+    {
+      /* Only one object in the list */
+      root= NULL;
+    }
+    else
+    {
+      /* ensure that we don't loose track of the root, and this will
+       * change the start position for the next search ;-) */
+      root= entry->next;
+      entry->prev->next= entry->next;
+      entry->next->prev= entry->prev;
+    }
+
+    free(item->key);
+    free(item->data);
+    free(item);
+    ret= true;
+  }
+
+  return ret;
+}
+
+void flush(uint32_t /* when */)
+{
+  /* remove the complete linked list */
+  if (root == NULL)
+  {
+    return;
+  }
+
+  root->prev->next= NULL;
+  while (root != NULL)
+  {
+    struct item* tmp= (struct item*)root;
+    root= root->next;
+
+    free(tmp->key);
+    free(tmp->data);
+    free(tmp);
+  }
+}
+
+void update_cas(struct item* item)
+{
+  item->cas= ++cas;
+}
+
+void release_item(struct item* /* item */)
+{
+}
diff --git a/example/t/include.am b/example/t/include.am
new file mode 100644 (file)
index 0000000..b9b7556
--- /dev/null
@@ -0,0 +1,36 @@
+# vim:ft=automake
+# Copyright (C) 2012 Data Differential
+# All rights reserved.
+#
+# Use and distribution licensed under the BSD license.  See
+# the COPYING file in the parent directory for full text.
+#
+# included from Top Level Makefile.am
+# All paths should be given relative to the root
+
+MEMCACHED_LIGHT_TESTS_LDADDS= \
+                              libmemcached/libmemcached.la \
+                              libmemcached/libmemcachedutil.la \
+                              libtest/libtest.la
+
+example_t_memcached_light_SOURCES=
+example_t_memcached_light_LDADD=
+
+example_t_memcached_light_SOURCES+= example/t/memcached_light.cc
+example_t_memcached_light_SOURCES+= tests/libmemcached-1.0/memcached_get.cc
+example_t_memcached_light_SOURCES+= tests/libmemcached-1.0/setup_and_teardowns.cc
+example_t_memcached_light_CXXFLAGS = $(AM_CXXFLAGS)
+example_t_memcached_light_DEPENDENCIES= $(MEMCACHED_LIGHT_TESTS_LDADDS) example/memcached_light
+example_t_memcached_light_LDADD+= $(MEMCACHED_LIGHT_TESTS_LDADDS)
+example_t_memcached_light_LDADD+= $(LIBUUID_LDFLAGS)
+check_PROGRAMS+= example/t/memcached_light
+noinst_PROGRAMS+= example/t/memcached_light
+
+test-memcached_light: example/t/memcached_light example/memcached_light
+       @example/t/memcached_light
+
+gdb-memcached_light: example/t/memcached_light example/memcached_light
+       @$(DEBUG_COMMAND) example/t/memcached_light
+
+valgrind-memcached_light: example/t/memcached_light example/memcached_light
+       $(VALGRIND_COMMAND) example/t/memcached_light
diff --git a/example/t/memcached_light.cc b/example/t/memcached_light.cc
new file mode 100644 (file)
index 0000000..bcfce0a
--- /dev/null
@@ -0,0 +1,243 @@
+/*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ * 
+ *  Test memcat
+ *
+ *  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.
+ *
+ */
+
+
+/*
+  Test that we are cycling the servers we are creating during testing.
+*/
+
+#include <config.h>
+
+#include <libtest/test.hpp>
+#include <libmemcached/memcached.h>
+
+#include "tests/libmemcached-1.0/memcached_get.h"
+
+using namespace libtest;
+
+#ifndef __INTEL_COMPILER
+#pragma GCC diagnostic ignored "-Wstrict-aliasing"
+#endif
+
+static std::string executable("example/memcached_light");
+
+static test_return_t help_TEST(void *)
+{
+  const char *args[]= { "--help", 0 };
+
+  test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true));
+
+  return TEST_SUCCESS;
+}
+
+static test_return_t verbose_TEST(void *)
+{
+  const char *args[]= { "--help", "--verbose", 0 };
+
+  test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true));
+
+  return TEST_SUCCESS;
+}
+
+static test_return_t daemon_TEST(void *)
+{
+  const char *args[]= { "--help", "--daemon", 0 };
+
+  test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true));
+
+  return TEST_SUCCESS;
+}
+
+static test_return_t protocol_TEST(void *)
+{
+  const char *args[]= { "--help", "--protocol", 0 };
+
+  test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true));
+
+  return TEST_SUCCESS;
+}
+
+static test_return_t version_TEST(void *)
+{
+  const char *args[]= { "--help", "--version", 0 };
+
+  test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true));
+
+  return TEST_SUCCESS;
+}
+
+static test_return_t port_TEST(void *)
+{
+  const char *args[]= { "--help", "--port=9090", 0 };
+
+  test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true));
+
+  return TEST_SUCCESS;
+}
+
+static test_return_t pid_file_TEST(void *)
+{
+  const char *args[]= { "--help", "--pid-file=/tmp/foo.pid", 0 };
+
+  test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true));
+
+  return TEST_SUCCESS;
+}
+
+static test_return_t log_file_TEST(void *)
+{
+  const char *args[]= { "--help", "--log-file=/tmp/foo.log", 0 };
+
+  test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true));
+
+  return TEST_SUCCESS;
+}
+
+static test_return_t max_connections_file_TEST(void *)
+{
+  const char *args[]= { "--help", "--max-connections=/tmp/foo.max_connections", 0 };
+
+  test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true));
+
+  return TEST_SUCCESS;
+}
+
+typedef test_return_t (*libmemcached_test_callback_fn)(memcached_st *);
+
+static test_return_t _runner_default(libmemcached_test_callback_fn func, void *object)
+{
+  if (func)
+  {
+    test_true(object);
+    test_return_t ret;
+    try {
+      ret= func((memcached_st*)object);
+    }
+    catch (std::exception& e)
+    {
+      libtest::Error << e.what();
+      return TEST_FAILURE;
+    }
+
+    return ret;
+  }
+
+  return TEST_SUCCESS;
+}
+
+class MemcachedLightRunner : public libtest::Runner {
+public:
+  test_return_t run(test_callback_fn* func, void *object)
+  {
+    return _runner_default(libmemcached_test_callback_fn(func), object);
+  }
+};
+
+static MemcachedLightRunner defualt_libmemcached_runner;
+
+test_st cmdline_option_TESTS[] ={
+  {"--help", true, help_TEST },
+  {"--verbose", true, verbose_TEST },
+  {"--daemon", true, daemon_TEST },
+  {"--protocol", true, protocol_TEST },
+  {"--version", true, version_TEST },
+  {"--port", true, port_TEST },
+  {"--pid-file", true, pid_file_TEST },
+  {"--log-file", true, log_file_TEST },
+  {"--max-connections", true, max_connections_file_TEST },
+  {0, 0, 0}
+};
+
+/* Clean the server before beginning testing */
+test_st basic_TESTS[] ={
+#if 0
+  {"memcached_get()", true, (test_callback_fn*)get_test },
+  {"memcached_get() test 2", false, (test_callback_fn*)get_test2 },
+  {"memcached_get() test 3", false, (test_callback_fn*)get_test3 },
+  {"memcached_get() test 4", false, (test_callback_fn*)get_test4 },
+  {"memcached_get() test 5", false, (test_callback_fn*)get_test5 },
+#endif
+  {0, 0, 0}
+};
+
+collection_st collection[] ={
+  {"command line options", 0, 0, cmdline_option_TESTS },
+  {"basic", 0, 0, basic_TESTS },
+  {0, 0, 0, 0}
+};
+
+static void *world_create(server_startup_st& servers, test_return_t& error)
+{
+  if (HAVE_MEMCACHED_LIGHT_BINARY == 0)
+  {
+    error= TEST_SKIPPED;
+    return NULL;
+  }
+
+  if (server_startup(servers, "memcached-light", libtest::default_port(), 0, NULL) == 0)
+  {
+    error= TEST_FAILURE;
+  }
+
+
+  char buffer[1024];
+  int length= snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(libtest::default_port()));
+  fatal_assert(length > 0);
+
+  memcached_st *memc= memcached(buffer, length);
+
+  fatal_assert(memc);
+
+  return (void*)memc;
+}
+
+static bool world_destroy(void *object)
+{
+  memcached_st *memc= (memcached_st*)object;
+  memcached_free(memc);
+
+  return TEST_SUCCESS;
+}
+
+
+void get_world(Framework *world)
+{
+  world->_create= world_create;
+  world->_destroy= world_destroy;
+  world->collections= collection;
+  world->set_runner(&defualt_libmemcached_runner);
+}
+
index d5b2fc76de1d33847d272b0f5503b3a655cf5e57..7dcc4d9c5ebfcd88042e3f4219111730ee47988a 100644 (file)
@@ -133,7 +133,7 @@ SUFFIXES+= .d
 libmemcached/dtrace_probes.h: libmemcached/libmemcached_probes.d
        $(DTRACE) $(DTRACEFLAGS) -h -o ${top_srcdir}/libmemcached/dtrace_probes.h -s ${top_srcdir}/libmemcached/libmemcached_probes.d
 
-libmemcached/libmemcached_probes.o: libmemcached/libmemcached_probes.d ${libmemcached_libmemcached_la_OBJECTS} config.h
+libmemcached/libmemcached_probes.o: libmemcached/libmemcached_probes.d ${libmemcached_libmemcached_la_OBJECTS}
 
 .d.o:
        $(DTRACE) $(DTRACEFLAGS) -o $@ -G -s libmemcached/libmemcached_probes.d
index 0d18857a296f6db5099da79385d5fc63876c26af..fb589931eff09c5071f1313b08e288448b92ef02 100644 (file)
@@ -50,6 +50,7 @@
 #include "win32/wrappers.h"
 #define get_socket_errno() WSAGetLastError()
 #else
+#include <unistd.h>
 #define INVALID_SOCKET -1
 #define SOCKET_ERROR -1
 #define closesocket(a) close(a)
index 90204113d6d2f170653a01b1814bddb407fecf62..638536c8e0bf2543a15ef8015b447d3d9d5e2545 100644 (file)
@@ -168,14 +168,14 @@ typedef struct {
     * Delete an existing key
     *
     * @param cookie id of the client receiving the command
-    * @param key the key to delete
+    * @param key the key to delete_object
     * @param len the length of the key
     * @param cas the CAS in the request
     */
-   protocol_binary_response_status (*delete)(const void *cookie,
-                                             const void *key,
-                                             uint16_t keylen,
-                                             uint64_t cas);
+   protocol_binary_response_status (*delete_object)(const void *cookie,
+                                                    const void *key,
+                                                    uint16_t keylen,
+                                                    uint64_t cas);
 
 
    /**
@@ -184,8 +184,8 @@ typedef struct {
     * @param cookie id of the client receiving the command
     * @param when when the cache should be flushed (0 == immediately)
     */
-   protocol_binary_response_status (*flush)(const void *cookie,
-                                            uint32_t when);
+   protocol_binary_response_status (*flush_object)(const void *cookie,
+                                                   uint32_t when);
 
 
 
@@ -349,7 +349,7 @@ typedef enum {
     * Version 1 abstracts more of the protocol details, and let you work at
     * a logical level
     */
-   MEMCACHED_PROTOCOL_HANDLER_V1= 1,
+   MEMCACHED_PROTOCOL_HANDLER_V1= 1
 } memcached_protocol_interface_version_t;
 
 /**
index f1cfdc03e88a9660ca751eff94612cbb6e45dbdb..113338dfb675a987a039d4211d27eaf421d94e63 100644 (file)
@@ -152,6 +152,9 @@ memcached_protocol_client_st *memcached_protocol_create_client(memcached_protoco
 LIBMEMCACHED_API
 void memcached_protocol_client_destroy(memcached_protocol_client_st *client);
 
+LIBMEMCACHED_API
+void memcached_protocol_client_set_verbose(struct memcached_protocol_client_st *client, bool arg);
+
 /**
  * Error event means that the client encountered an error with the
  * connection so you should shut it down
index f6134b3c31af29851e219cc60f1dcd664beabbf1..8cd29720bae5c7c681d95eb974793a12176ec6fc 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <errno.h>
+
+
+static void print_ascii_command(memcached_protocol_client_st *client)
+{
+  if (client->is_verbose)
+  {
+    switch (client->ascii_command)
+    {
+    case SET_CMD:
+      fprintf(stderr, "%s:%d SET_CMD\n", __FILE__, __LINE__);
+      break;
+
+    case ADD_CMD:
+      fprintf(stderr, "%s:%d ADD_CMD\n", __FILE__, __LINE__);
+      break;
+
+    case REPLACE_CMD:
+      fprintf(stderr, "%s:%d REPLACE_CMD\n", __FILE__, __LINE__);
+      break;
+
+    case CAS_CMD:
+      fprintf(stderr, "%s:%d CAS_CMD\n", __FILE__, __LINE__);
+      break;
+
+    case APPEND_CMD:
+      fprintf(stderr, "%s:%d APPEND_CMD\n", __FILE__, __LINE__);
+      break;
+
+    case PREPEND_CMD:
+      fprintf(stderr, "%s:%d PREPEND_CMD\n", __FILE__, __LINE__);
+      break;
+
+    case DELETE_CMD:
+      fprintf(stderr, "%s:%d DELETE_CMD\n", __FILE__, __LINE__);
+      break;
+
+    case INCR_CMD: /* FALLTHROUGH */
+      fprintf(stderr, "%s:%d INCR_CMD\n", __FILE__, __LINE__);
+      break;
+
+    case DECR_CMD:
+      fprintf(stderr, "%s:%d DECR_CMD\n", __FILE__, __LINE__);
+      break;
+
+    case STATS_CMD:
+      fprintf(stderr, "%s:%d STATS_CMD\n", __FILE__, __LINE__);
+      break;
+
+    case FLUSH_ALL_CMD:
+      fprintf(stderr, "%s:%d FLUSH_ALL_CMD\n", __FILE__, __LINE__);
+      break;
+
+    case VERSION_CMD:
+      fprintf(stderr, "%s:%d VERSION_CMD\n", __FILE__, __LINE__);
+      break;
+
+    case QUIT_CMD:
+      fprintf(stderr, "%s:%d QUIT_CMD\n", __FILE__, __LINE__);
+      break;
+
+    case VERBOSITY_CMD:
+      fprintf(stderr, "%s:%d VERBOSITY_CMD\n", __FILE__, __LINE__);
+      break;
+
+    case GET_CMD:
+      fprintf(stderr, "%s:%d GET_CMD\n", __FILE__, __LINE__);
+      break;
+
+    case GETS_CMD:
+      fprintf(stderr, "%s:%d GETS_CMD\n", __FILE__, __LINE__);
+      break;
+
+    default:
+    case UNKNOWN_CMD:
+      fprintf(stderr, "%s:%d UNKNOWN_CMD\n", __FILE__, __LINE__);
+      break;
+
+    }
+  }
+}
 
 /**
  * Try to parse a key from the string.
@@ -81,9 +162,50 @@ static uint16_t parse_ascii_key(char **start)
  * @param text the text to spool
  * @return status of the spool operation
  */
-static protocol_binary_response_status
-spool_string(memcached_protocol_client_st *client, const char *text)
+static protocol_binary_response_status raw_response_handler(memcached_protocol_client_st *client, const char *text)
 {
+  if (client->is_verbose)
+  {
+    fprintf(stderr, "%s:%d %s\n", __FILE__, __LINE__, text);
+  }
+
+  if (client->root->drain(client) == false)
+  {
+    return PROTOCOL_BINARY_RESPONSE_EINTERNAL;
+  }
+
+  assert(client->output != NULL);
+#if 0
+  if (client->output == NULL)
+  {
+    /* I can write directly to the socket.... */
+    do
+    {
+      size_t num_bytes= len -offset;
+      ssize_t nw= client->root->send(client,
+                                     client->sock,
+                                     ptr + offset,
+                                     num_bytes);
+      if (nw == -1)
+      {
+        if (get_socket_errno() == EWOULDBLOCK)
+        {
+          break;
+        }
+        else if (get_socket_errno() != EINTR)
+        {
+          client->error= errno;
+          return PROTOCOL_BINARY_RESPONSE_EINTERNAL;
+        }
+      }
+      else
+      {
+        offset += (size_t)nw;
+      }
+    } while (offset < len);
+  }
+#endif
+
   return client->root->spool(client, text, strlen(text));
 }
 
@@ -103,7 +225,7 @@ static void send_command_usage(memcached_protocol_client_st *client)
     [CAS_CMD]= "CLIENT_ERROR: Syntax error: cas <key> <flags> <exptime> <bytes> <casid> [noreply]\r\n",
     [APPEND_CMD]= "CLIENT_ERROR: Syntax error: append <key> <flags> <exptime> <bytes> [noreply]\r\n",
     [PREPEND_CMD]= "CLIENT_ERROR: Syntax error: prepend <key> <flags> <exptime> <bytes> [noreply]\r\n",
-    [DELETE_CMD]= "CLIENT_ERROR: Syntax error: delete <key> [noreply]\r\n",
+    [DELETE_CMD]= "CLIENT_ERROR: Syntax error: delete_object <key> [noreply]\r\n",
     [INCR_CMD]= "CLIENT_ERROR: Syntax error: incr <key> <value> [noreply]\r\n",
     [DECR_CMD]= "CLIENT_ERROR: Syntax error: decr <key> <value> [noreply]\r\n",
     [STATS_CMD]= "CLIENT_ERROR: Syntax error: stats [key]\r\n",
@@ -116,7 +238,7 @@ static void send_command_usage(memcached_protocol_client_st *client)
   };
 
   client->mute = false;
-  spool_string(client, errmsg[client->ascii_command]);
+  raw_response_handler(client, errmsg[client->ascii_command]);
 }
 
 /**
@@ -125,15 +247,14 @@ static void send_command_usage(memcached_protocol_client_st *client)
  * @param text the length of the body
  * @param textlen the length of the body
  */
-static protocol_binary_response_status
-ascii_version_response_handler(const void *cookie,
-                               const void *text,
-                               uint32_t textlen)
+static protocol_binary_response_status ascii_version_response_handler(const void *cookie,
+                                                                      const void *text,
+                                                                      uint32_t textlen)
 {
   memcached_protocol_client_st *client= (memcached_protocol_client_st*)cookie;
-  spool_string(client, "VERSION ");
+  raw_response_handler(client, "VERSION ");
   client->root->spool(client, text, textlen);
-  spool_string(client, "\r\n");
+  raw_response_handler(client, "\r\n");
   return PROTOCOL_BINARY_RESPONSE_SUCCESS;
 }
 
@@ -204,27 +325,26 @@ ascii_get_response_handler(const void *cookie,
  * @param body the length of the body
  * @param bodylen the length of the body
  */
-static protocol_binary_response_status
-ascii_stat_response_handler(const void *cookie,
-                     const void *key,
-                     uint16_t keylen,
-                     const void *body,
-                     uint32_t bodylen)
+static protocol_binary_response_status ascii_stat_response_handler(const void *cookie,
+                                                                   const void *key,
+                                                                   uint16_t keylen,
+                                                                   const void *body,
+                                                                   uint32_t bodylen)
 {
 
   memcached_protocol_client_st *client= (void*)cookie;
 
   if (key != NULL)
   {
-    spool_string(client, "STAT ");
+    raw_response_handler(client, "STAT ");
     client->root->spool(client, key, keylen);
-    spool_string(client, " ");
+    raw_response_handler(client, " ");
     client->root->spool(client, body, bodylen);
-    spool_string(client, "\r\n");
+    raw_response_handler(client, "\r\n");
   }
   else
   {
-    spool_string(client, "END\r\n");
+    raw_response_handler(client, "END\r\n");
   }
 
   return PROTOCOL_BINARY_RESPONSE_SUCCESS;
@@ -264,7 +384,9 @@ static void ascii_process_gets(memcached_protocol_client_st *client,
     send_command_usage(client);
   }
   else
+  {
     client->root->spool(client, "END\r\n", 5);
+  }
 }
 
 /**
@@ -353,7 +475,7 @@ static enum ascii_cmd ascii_to_cmd(char *start, size_t length)
     { .cmd= "cas", .len= 3, .cc= CAS_CMD },
     { .cmd= "append", .len= 6, .cc= APPEND_CMD },
     { .cmd= "prepend", .len= 7, .cc= PREPEND_CMD },
-    { .cmd= "delete", .len= 6, .cc= DELETE_CMD },
+    { .cmd= "delete_object", .len= 6, .cc= DELETE_CMD },
     { .cmd= "incr", .len= 4, .cc= INCR_CMD },
     { .cmd= "decr", .len= 4, .cc= DECR_CMD },
     { .cmd= "stats", .len= 5, .cc= STATS_CMD },
@@ -383,7 +505,7 @@ static enum ascii_cmd ascii_to_cmd(char *start, size_t length)
 }
 
 /**
- * Perform a delete operation.
+ * Perform a delete_object operation.
  *
  * @param client client requesting the deletion
  * @param tokens the command as a vector
@@ -401,28 +523,27 @@ static void process_delete(memcached_protocol_client_st *client,
     return;
   }
 
-  if (client->root->callback->interface.v1.delete == NULL)
+  if (client->root->callback->interface.v1.delete_object == NULL)
   {
-    spool_string(client, "SERVER_ERROR: callback not implemented\r\n");
+    raw_response_handler(client, "SERVER_ERROR: callback not implemented\r\n");
     return;
   }
 
-  protocol_binary_response_status rval;
-  rval= client->root->callback->interface.v1.delete(client, key, nkey, 0);
+  protocol_binary_response_status rval= client->root->callback->interface.v1.delete_object(client, key, nkey, 0);
 
   if (rval == PROTOCOL_BINARY_RESPONSE_SUCCESS)
   {
-    spool_string(client, "DELETED\r\n");
+    raw_response_handler(client, "DELETED\r\n");
   }
   else if (rval == PROTOCOL_BINARY_RESPONSE_KEY_ENOENT)
   {
-    spool_string(client, "NOT_FOUND\r\n");
+    raw_response_handler(client, "NOT_FOUND\r\n");
   }
   else
   {
     char msg[80];
-    snprintf(msg, sizeof(msg), "SERVER_ERROR: delete failed %u\r\n",(uint32_t)rval);
-    spool_string(client, msg);
+    snprintf(msg, sizeof(msg), "SERVER_ERROR: delete_object failed %u\r\n",(uint32_t)rval);
+    raw_response_handler(client, msg);
   }
 }
 
@@ -447,7 +568,7 @@ static void process_arithmetic(memcached_protocol_client_st *client,
   {
     if (client->root->callback->interface.v1.increment == NULL)
     {
-      spool_string(client, "SERVER_ERROR: callback not implemented\r\n");
+      raw_response_handler(client, "SERVER_ERROR: callback not implemented\r\n");
       return;
     }
     rval= client->root->callback->interface.v1.increment(client,
@@ -461,7 +582,7 @@ static void process_arithmetic(memcached_protocol_client_st *client,
   {
     if (client->root->callback->interface.v1.decrement == NULL)
     {
-      spool_string(client, "SERVER_ERROR: callback not implemented\r\n");
+      raw_response_handler(client, "SERVER_ERROR: callback not implemented\r\n");
       return;
     }
     rval= client->root->callback->interface.v1.decrement(client,
@@ -476,11 +597,11 @@ static void process_arithmetic(memcached_protocol_client_st *client,
   {
     char buffer[80];
     snprintf(buffer, sizeof(buffer), "%"PRIu64"\r\n", result);
-    spool_string(client, buffer);
+    raw_response_handler(client, buffer);
   }
   else
   {
-    spool_string(client, "NOT_FOUND\r\n");
+    raw_response_handler(client, "NOT_FOUND\r\n");
   }
 }
 
@@ -494,12 +615,14 @@ static void process_stats(memcached_protocol_client_st *client,
 {
   if (client->root->callback->interface.v1.stat == NULL)
   {
-    spool_string(client, "SERVER_ERROR: callback not implemented\r\n");
+    raw_response_handler(client, "SERVER_ERROR: callback not implemented\r\n");
     return;
   }
 
   while (isspace(*key))
+  {
     key++;
+  }
 
   uint16_t nkey= (uint16_t)(end - key);
   (void)client->root->callback->interface.v1.stat(client, key, nkey,
@@ -518,7 +641,7 @@ static void process_version(memcached_protocol_client_st *client,
 
   if (client->root->callback->interface.v1.version == NULL)
   {
-    spool_string(client, "SERVER_ERROR: callback not implemented\r\n");
+    raw_response_handler(client, "SERVER_ERROR: callback not implemented\r\n");
     return;
   }
 
@@ -535,9 +658,9 @@ static void process_flush(memcached_protocol_client_st *client,
     return;
   }
 
-  if (client->root->callback->interface.v1.flush == NULL)
+  if (client->root->callback->interface.v1.flush_object == NULL)
   {
-    spool_string(client, "SERVER_ERROR: callback not implemented\r\n");
+    raw_response_handler(client, "SERVER_ERROR: callback not implemented\r\n");
     return;
   }
 
@@ -548,11 +671,11 @@ static void process_flush(memcached_protocol_client_st *client,
   }
 
   protocol_binary_response_status rval;
-  rval= client->root->callback->interface.v1.flush(client, timeout);
+  rval= client->root->callback->interface.v1.flush_object(client, timeout);
   if (rval == PROTOCOL_BINARY_RESPONSE_SUCCESS)
-    spool_string(client, "OK\r\n");
+    raw_response_handler(client, "OK\r\n");
   else
-    spool_string(client, "SERVER_ERROR: internal error\r\n");
+    raw_response_handler(client, "SERVER_ERROR: internal error\r\n");
 }
 
 /**
@@ -570,8 +693,8 @@ static void process_flush(memcached_protocol_client_st *client,
  *         1 We need more data, so just go ahead and wait for more!
  */
 static inline int process_storage_command(memcached_protocol_client_st *client,
-                                     char **tokens, int ntokens, char *start,
-                                     char **end, ssize_t length)
+                                          char **tokens, int ntokens, char *start,
+                                          char **end, ssize_t length)
 {
   (void)ntokens; /* already checked */
   char *key= tokens[1];
@@ -579,7 +702,7 @@ static inline int process_storage_command(memcached_protocol_client_st *client,
   if (nkey == 0)
   {
     /* return error */
-    spool_string(client, "CLIENT_ERROR: bad key\r\n");
+    raw_response_handler(client, "CLIENT_ERROR: bad key\r\n");
     return -1;
   }
 
@@ -666,7 +789,7 @@ static inline int process_storage_command(memcached_protocol_client_st *client,
 
   if (rval == PROTOCOL_BINARY_RESPONSE_SUCCESS)
   {
-    spool_string(client, "STORED\r\n");
+    raw_response_handler(client, "STORED\r\n");
   }
   else
   {
@@ -674,20 +797,20 @@ static inline int process_storage_command(memcached_protocol_client_st *client,
     {
       if (rval == PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS)
       {
-        spool_string(client, "EXISTS\r\n");
+        raw_response_handler(client, "EXISTS\r\n");
       }
       else if (rval == PROTOCOL_BINARY_RESPONSE_KEY_ENOENT)
       {
-        spool_string(client, "NOT_FOUND\r\n");
+        raw_response_handler(client, "NOT_FOUND\r\n");
       }
       else
       {
-        spool_string(client, "NOT_STORED\r\n");
+        raw_response_handler(client, "NOT_STORED\r\n");
       }
     }
     else
     {
-      spool_string(client, "NOT_STORED\r\n");
+      raw_response_handler(client, "NOT_STORED\r\n");
     }
   }
 
@@ -708,7 +831,7 @@ static int process_cas_command(memcached_protocol_client_st *client,
 
   if (client->root->callback->interface.v1.replace == NULL)
   {
-    spool_string(client, "SERVER_ERROR: callback not implemented\r\n");
+    raw_response_handler(client, "SERVER_ERROR: callback not implemented\r\n");
     return false;
   }
 
@@ -727,7 +850,7 @@ static int process_set_command(memcached_protocol_client_st *client,
 
   if (client->root->callback->interface.v1.set == NULL)
   {
-    spool_string(client, "SERVER_ERROR: callback not implemented\r\n");
+    raw_response_handler(client, "SERVER_ERROR: callback not implemented\r\n");
     return false;
   }
 
@@ -746,7 +869,7 @@ static int process_add_command(memcached_protocol_client_st *client,
 
   if (client->root->callback->interface.v1.add == NULL)
   {
-    spool_string(client, "SERVER_ERROR: callback not implemented\r\n");
+    raw_response_handler(client, "SERVER_ERROR: callback not implemented\r\n");
     return false;
   }
 
@@ -765,7 +888,7 @@ static int process_replace_command(memcached_protocol_client_st *client,
 
   if (client->root->callback->interface.v1.replace == NULL)
   {
-    spool_string(client, "SERVER_ERROR: callback not implemented\r\n");
+    raw_response_handler(client, "SERVER_ERROR: callback not implemented\r\n");
     return false;
   }
 
@@ -784,7 +907,7 @@ static int process_append_command(memcached_protocol_client_st *client,
 
   if (client->root->callback->interface.v1.append == NULL)
   {
-    spool_string(client, "SERVER_ERROR: callback not implemented\r\n");
+    raw_response_handler(client, "SERVER_ERROR: callback not implemented\r\n");
     return false;
   }
 
@@ -803,7 +926,7 @@ static int process_prepend_command(memcached_protocol_client_st *client,
 
   if (client->root->callback->interface.v1.prepend == NULL)
   {
-    spool_string(client, "SERVER_ERROR: callback not implemented\r\n");
+    raw_response_handler(client, "SERVER_ERROR: callback not implemented\r\n");
     return false;
   }
 
@@ -831,20 +954,34 @@ memcached_protocol_event_t memcached_ascii_protocol_process_data(memcached_proto
 
     client->ascii_command= ascii_to_cmd(ptr, (size_t)(*length));
 
+    /* we got all data available, execute the callback! */
+    if (client->root->callback->pre_execute != NULL)
+    {
+      client->root->callback->pre_execute(client, NULL);
+    }
+
+
     /* A multiget lists all of the keys, and I don't want to have an
      * avector of let's say 512 pointers to tokenize all of them, so let's
      * just handle them immediately
      */
     if (client->ascii_command == GET_CMD ||
-        client->ascii_command == GETS_CMD) {
+        client->ascii_command == GETS_CMD)
+    {
       if (client->root->callback->interface.v1.get != NULL)
+      {
         ascii_process_gets(client, ptr, end);
+      }
       else
-        spool_string(client, "SERVER_ERROR: Command not implemented\n");
-    } else {
+      {
+        raw_response_handler(client, "SERVER_ERROR: Command not implemented\n");
+      }
+    }
+    else
+    {
       /* None of the defined commands takes 10 parameters, so lets just use
        * that as a maximum limit.
-       */
+     */
       char *tokens[10];
       int ntokens= ascii_tokenize_command(ptr, end, tokens, 10);
 
@@ -852,33 +989,40 @@ memcached_protocol_event_t memcached_ascii_protocol_process_data(memcached_proto
       {
         client->mute= strcmp(tokens[ntokens - 1], "noreply") == 0;
         if (client->mute)
+        {
           --ntokens; /* processed noreply token*/
+        }
       }
 
       int error= 0;
 
-      switch (client->ascii_command) {
+      print_ascii_command(client);
+      switch (client->ascii_command)
+      {
       case SET_CMD:
         error= process_set_command(client, tokens, ntokens, ptr, &end, *length);
         break;
+
       case ADD_CMD:
         error= process_add_command(client, tokens, ntokens, ptr, &end, *length);
         break;
+
       case REPLACE_CMD:
-        error= process_replace_command(client, tokens, ntokens,
-                                       ptr, &end, *length);
+        error= process_replace_command(client, tokens, ntokens, ptr, &end, *length);
         break;
+
       case CAS_CMD:
         error= process_cas_command(client, tokens, ntokens, ptr, &end, *length);
         break;
+
       case APPEND_CMD:
-        error= process_append_command(client, tokens, ntokens,
-                                      ptr, &end, *length);
+        error= process_append_command(client, tokens, ntokens, ptr, &end, *length);
         break;
+
       case PREPEND_CMD:
-        error= process_prepend_command(client, tokens, ntokens,
-                                       ptr, &end, *length);
-       break;
+        error= process_prepend_command(client, tokens, ntokens, ptr, &end, *length);
+        break;
+
       case DELETE_CMD:
         process_delete(client, tokens, ntokens);
         break;
@@ -887,6 +1031,7 @@ memcached_protocol_event_t memcached_ascii_protocol_process_data(memcached_proto
       case DECR_CMD:
         process_arithmetic(client, tokens, ntokens);
         break;
+
       case STATS_CMD:
         if (client->mute)
         {
@@ -898,9 +1043,11 @@ memcached_protocol_event_t memcached_ascii_protocol_process_data(memcached_proto
           process_stats(client, ptr + 6, end);
         }
         break;
+
       case FLUSH_ALL_CMD:
         process_flush(client, tokens, ntokens);
         break;
+
       case VERSION_CMD:
         if (client->mute)
         {
@@ -911,6 +1058,7 @@ memcached_protocol_event_t memcached_ascii_protocol_process_data(memcached_proto
           process_version(client, tokens, ntokens);
         }
         break;
+
       case QUIT_CMD:
         if (ntokens != 1 || client->mute)
         {
@@ -919,7 +1067,9 @@ memcached_protocol_event_t memcached_ascii_protocol_process_data(memcached_proto
         else
         {
           if (client->root->callback->interface.v1.quit != NULL)
+          {
             client->root->callback->interface.v1.quit(client);
+          }
 
           return MEMCACHED_PROTOCOL_ERROR_EVENT;
         }
@@ -927,9 +1077,13 @@ memcached_protocol_event_t memcached_ascii_protocol_process_data(memcached_proto
 
       case VERBOSITY_CMD:
         if (ntokens != 2)
+        {
           send_command_usage(client);
+        }
         else
-          spool_string(client, "OK\r\n");
+        {
+          raw_response_handler(client, "OK\r\n");
+        }
         break;
 
       case UNKNOWN_CMD:
@@ -944,9 +1098,18 @@ memcached_protocol_event_t memcached_ascii_protocol_process_data(memcached_proto
       }
 
       if (error == -1)
+      {
         return MEMCACHED_PROTOCOL_ERROR_EVENT;
+      }
       else if (error == 1)
+      {
         return MEMCACHED_PROTOCOL_READ_EVENT;
+      }
+    }
+
+    if (client->root->callback->post_execute != NULL)
+    {
+      client->root->callback->post_execute(client, NULL);
     }
 
     /* Move past \n */
index c2fd4414d8477df56c53b26098ded46bfba75da4..3778e344642390a12131af5cc23fa486ee566d6a 100644 (file)
  * @param response the packet to send
  * @return The status of the operation
  */
-static protocol_binary_response_status
-raw_response_handler(const void *cookie,
-                     protocol_binary_request_header *request,
-                     protocol_binary_response_header *response)
+static protocol_binary_response_status raw_response_handler(const void *cookie,
+                                                            protocol_binary_request_header *request,
+                                                            protocol_binary_response_header *response)
 {
   memcached_protocol_client_st *client= (void*)cookie;
 
@@ -72,12 +71,12 @@ raw_response_handler(const void *cookie,
     return PROTOCOL_BINARY_RESPONSE_EINVAL;
   }
 
-  if (!client->root->drain(client))
+  if (client->root->drain(client) == false)
   {
     return PROTOCOL_BINARY_RESPONSE_EINTERNAL;
   }
 
-  size_t len= sizeof(*response) + htonl(response->response.bodylen);
+  size_t len= sizeof(protocol_binary_response_header) + htonl(response->response.bodylen);
   size_t offset= 0;
   char *ptr= (void*)response;
 
@@ -113,6 +112,75 @@ raw_response_handler(const void *cookie,
   return client->root->spool(client, ptr, len - offset);
 }
 
+static void print_cmd(protocol_binary_command cmd)
+{
+  switch (cmd)
+  {
+  case PROTOCOL_BINARY_CMD_GET: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_GET\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_SET: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_SET\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_ADD: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_ADD\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_REPLACE: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_REPLACE\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_DELETE: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_DELETE\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_INCREMENT: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_INCREMENT\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_DECREMENT: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_DECREMENT\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_QUIT: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_QUIT\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_FLUSH: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_FLUSH\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_GETQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_GETQ\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_NOOP: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_NOOP\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_VERSION: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_VERSION\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_GETK: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_GETK\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_GETKQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_GETKQ\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_APPEND: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_APPEND\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_PREPEND: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_PREPEND\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_STAT: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_STAT\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_SETQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_SETQ\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_ADDQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_ADDQ\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_REPLACEQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_REPLACEQ\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_DELETEQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_DELETEQ\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_INCREMENTQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_INCREMENTQ\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_DECREMENTQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_DECREMENTQ\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_QUITQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_QUITQ\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_FLUSHQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_FLUSHQ\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_APPENDQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_APPENDQ\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_PREPENDQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_PREPENDQ\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_VERBOSITY: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_VERBOSITY\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_TOUCH: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_TOUCH\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_GAT: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_GAT\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_GATQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_GATQ\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_SASL_LIST_MECHS: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_SASL_LIST_MECHS\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_SASL_AUTH: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_SASL_AUTH\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_SASL_STEP: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_SASL_STEP\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_RGET: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_RGET\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_RSET: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_RSET\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_RSETQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_RSETQ\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_RAPPEND: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_RAPPEND\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_RAPPENDQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_RAPPENDQ\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_RPREPEND: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_RPREPEND\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_RPREPENDQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_RPREPENDQ\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_RDELETE: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_RDELETE\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_RDELETEQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_RDELETEQ\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_RINCR: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_RINCR\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_RINCRQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_RINCRQ\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_RDECR: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_RDECR\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_RDECRQ: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_RDECRQ\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_SET_VBUCKET: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_SET_VBUCKET\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_GET_VBUCKET: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_GET_VBUCKET\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_DEL_VBUCKET: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_DEL_VBUCKET\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_TAP_CONNECT: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_TAP_CONNECT\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_TAP_MUTATION: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_TAP_MUTATION\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_TAP_DELETE: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_TAP_DELETE\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_TAP_FLUSH: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_TAP_FLUSH\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_TAP_OPAQUE: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_TAP_OPAQUE\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_TAP_VBUCKET_SET: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_TAP_VBUCKET_SET\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_TAP_CHECKPOINT_START: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_TAP_CHECKPOINT_START\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_TAP_CHECKPOINT_END: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_TAP_CHECKPOINT_END\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_LAST_RESERVED: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_LAST_RESERVED\n", __FILE__, __LINE__); return;
+  case PROTOCOL_BINARY_CMD_SCRUB: fprintf(stderr, "%s:%d PROTOCOL_BINARY_CMD_SCRUB\n", __FILE__, __LINE__); return;
+  default:
+                                  abort();
+  }
+}
+
 /*
  * Version 0 of the interface is really low level and protocol specific,
  * while the version 1 of the interface is more API focused. We need a
@@ -131,15 +199,14 @@ raw_response_handler(const void *cookie,
  * @param flags the flags for the item
  * @param cas the CAS id for the item
  */
-static protocol_binary_response_status
-get_response_handler(const void *cookie,
-                     const void *key,
-                     uint16_t keylen,
-                     const void *body,
-                     uint32_t bodylen,
-                     uint32_t flags,
-                     uint64_t cas) {
-
+static protocol_binary_response_status get_response_handler(const void *cookie,
+                                                            const void *key,
+                                                            uint16_t keylen,
+                                                            const void *body,
+                                                            uint32_t bodylen,
+                                                            uint32_t flags,
+                                                            uint64_t cas)
+{
   memcached_protocol_client_st *client= (void*)cookie;
   uint8_t opcode= client->current_command->request.opcode;
 
@@ -222,10 +289,10 @@ static protocol_binary_response_status stat_response_handler(const void *cookie,
  * @param text the length of the body
  * @param textlen the length of the body
  */
-static protocol_binary_response_status
-version_response_handler(const void *cookie,
-                         const void *text,
-                         uint32_t textlen) {
+static protocol_binary_response_status version_response_handler(const void *cookie,
+                                                                const void *text,
+                                                                uint32_t textlen)
+{
 
   memcached_protocol_client_st *client= (void*)cookie;
 
@@ -372,21 +439,20 @@ decrement_command_handler(const void *cookie,
  * @param response_handler not used
  * @return the result of the operation
  */
-static protocol_binary_response_status
-delete_command_handler(const void *cookie,
-                       protocol_binary_request_header *header,
-                       memcached_binary_protocol_raw_response_handler response_handler)
+static protocol_binary_response_status delete_command_handler(const void *cookie,
+                                                              protocol_binary_request_header *header,
+                                                              memcached_binary_protocol_raw_response_handler response_handler)
 {
   (void)response_handler;
   protocol_binary_response_status rval;
 
   memcached_protocol_client_st *client= (void*)cookie;
-  if (client->root->callback->interface.v1.delete != NULL)
+  if (client->root->callback->interface.v1.delete_object != NULL)
   {
     uint16_t keylen= ntohs(header->request.keylen);
     void *key= (header +1);
     uint64_t cas= memcached_ntohll(header->request.cas);
-    rval= client->root->callback->interface.v1.delete(cookie, key, keylen, cas);
+    rval= client->root->callback->interface.v1.delete_object(cookie, key, keylen, cas);
     if (rval == PROTOCOL_BINARY_RESPONSE_SUCCESS &&
         header->request.opcode == PROTOCOL_BINARY_CMD_DELETE)
     {
@@ -428,16 +494,16 @@ flush_command_handler(const void *cookie,
   protocol_binary_response_status rval;
 
   memcached_protocol_client_st *client= (void*)cookie;
-  if (client->root->callback->interface.v1.flush != NULL)
+  if (client->root->callback->interface.v1.flush_object != NULL)
   {
-    protocol_binary_request_flush *flush= (void*)header;
+    protocol_binary_request_flush *flush_object= (void*)header;
     uint32_t timeout= 0;
     if (htonl(header->request.bodylen) == 4)
     {
-      timeout= ntohl(flush->message.body.expiration);
+      timeout= ntohl(flush_object->message.body.expiration);
     }
 
-    rval= client->root->callback->interface.v1.flush(cookie, timeout);
+    rval= client->root->callback->interface.v1.flush_object(cookie, timeout);
     if (rval == PROTOCOL_BINARY_RESPONSE_SUCCESS &&
         header->request.opcode == PROTOCOL_BINARY_CMD_FLUSH)
     {
@@ -805,10 +871,9 @@ replace_command_handler(const void *cookie,
  * @param response_handler not used
  * @return the result of the operation
  */
-static protocol_binary_response_status
-set_command_handler(const void *cookie,
-                    protocol_binary_request_header *header,
-                    memcached_binary_protocol_raw_response_handler response_handler)
+static protocol_binary_response_status set_command_handler(const void *cookie,
+                                                           protocol_binary_request_header *header,
+                                                           memcached_binary_protocol_raw_response_handler response_handler)
 {
   (void)response_handler;
   protocol_binary_response_status rval;
@@ -975,22 +1040,30 @@ static protocol_binary_response_status execute_command(memcached_protocol_client
     client->root->callback->pre_execute(client, header);
   }
 
-  protocol_binary_response_status rval;
-  rval= PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND;
+  protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND;
   uint8_t cc= header->request.opcode;
 
+  if (client->is_verbose)
+  {
+    print_cmd(cc);
+  }
+
   switch (client->root->callback->interface_version)
   {
   case 0:
-    if (client->root->callback->interface.v0.comcode[cc] != NULL) {
+    if (client->root->callback->interface.v0.comcode[cc] != NULL)
+    {
       rval= client->root->callback->interface.v0.comcode[cc](client, header, raw_response_handler);
     }
     break;
+
   case 1:
-    if (comcode_v0_v1_remap[cc] != NULL) {
+    if (comcode_v0_v1_remap[cc] != NULL)
+    {
       rval= comcode_v0_v1_remap[cc](client, header, raw_response_handler);
     }
     break;
+
   default:
     /* Unknown interface.
      * It should be impossible to get here so I'll just call abort
@@ -1060,8 +1133,11 @@ memcached_protocol_event_t memcached_binary_protocol_process_data(memcached_prot
       *length= len;
       *endptr= (void*)header;
       return MEMCACHED_PROTOCOL_ERROR_EVENT;
-    } else if (rv == PROTOCOL_BINARY_RESPONSE_NOT_SUPPORTED)
+    }
+    else if (rv == PROTOCOL_BINARY_RESPONSE_NOT_SUPPORTED)
+    {
       return MEMCACHED_PROTOCOL_PAUSE_EVENT;
+    }
 
     ssize_t total= (ssize_t)(sizeof(*header) + ntohl(header->request.bodylen));
     len -= total;
index ea94a8d7e281ff71c0a23f2a304c8658f56a7232..8453ccd8619b417c3a2bfbfa4e57785c02a88575 100644 (file)
@@ -124,6 +124,7 @@ enum ascii_cmd {
 };
 
 struct memcached_protocol_client_st {
+  bool is_verbose;
   memcached_protocol_st *root;
   memcached_socket_t sock;
   int error;
index 9ce927a6433664d601882ed87cc4b5b82831b3fc..59b461f6aa083b286c8e6e619ab8382e352437f5 100644 (file)
@@ -89,7 +89,7 @@ static ssize_t default_send(const void *cookie,
                             size_t nbytes)
 {
   (void)cookie;
-  return send(fd, buf, nbytes, 0);
+  return send(fd, buf, nbytes, MSG_NOSIGNAL);
 }
 
 /**
@@ -102,12 +102,17 @@ static ssize_t default_send(const void *cookie,
  */
 static bool drain_output(struct memcached_protocol_client_st *client)
 {
-  ssize_t len;
+  if (client->is_verbose)
+  {
+    fprintf(stderr, "%s:%d %s mute:%d output:%s length:%d\n", __FILE__, __LINE__, __func__, (int)client->mute,
+            client->output ? "yes" : "no",
+            client->output ? (int)(client->output->nbytes - client->output->offset) : 0);
+  }
 
   /* Do we have pending data to send? */
   while (client->output != NULL)
   {
-    len= client->root->send(client,
+    ssize_t len= client->root->send(client,
                             client->sock,
                             client->output->data + client->output->offset,
                             client->output->nbytes - client->output->offset);
@@ -189,6 +194,11 @@ static protocol_binary_response_status spool_output(struct memcached_protocol_cl
                                                     const void *data,
                                                     size_t length)
 {
+  if (client->is_verbose)
+  {
+    fprintf(stderr, "%s:%d %s mute:%d length:%d\n", __FILE__, __LINE__, __func__, (int)client->mute, (int)length);
+  }
+
   if (client->mute)
   {
     return PROTOCOL_BINARY_RESPONSE_SUCCESS;
@@ -233,10 +243,19 @@ static memcached_protocol_event_t determine_protocol(struct memcached_protocol_c
 {
   if (*client->root->input_buffer == (uint8_t)PROTOCOL_BINARY_REQ)
   {
+    if (client->is_verbose)
+    {
+      fprintf(stderr, "%s:%d PROTOCOL: memcached_binary_protocol_process_data\n", __FILE__, __LINE__);
+    }
     client->work= memcached_binary_protocol_process_data;
   }
   else if (client->root->callback->interface_version == 1)
   {
+    if (client->is_verbose)
+    {
+      fprintf(stderr, "%s:%d PROTOCOL: memcached_ascii_protocol_process_data\n", __FILE__, __LINE__);
+    }
+
     /*
      * The ASCII protocol can only be used if the implementors provide
      * an implementation for the version 1 of the interface..
@@ -249,12 +268,18 @@ static memcached_protocol_event_t determine_protocol(struct memcached_protocol_c
   }
   else
   {
+    if (client->is_verbose)
+    {
+      fprintf(stderr, "%s:%d PROTOCOL: Unsupported protocol\n", __FILE__, __LINE__);
+    }
+
     /* Let's just output a warning the way it is supposed to look like
      * in the ASCII protocol...
      */
     const char *err= "CLIENT_ERROR: Unsupported protocol\r\n";
     client->root->spool(client, err, strlen(err));
     client->root->drain(client);
+
     return MEMCACHED_PROTOCOL_ERROR_EVENT; /* Unsupported protocol */
   }
 
@@ -282,6 +307,7 @@ struct memcached_protocol_st *memcached_protocol_create_instance(void)
     {
       free(ret);
       ret= NULL;
+
       return NULL;
     }
 
@@ -307,7 +333,7 @@ void memcached_protocol_destroy_instance(struct memcached_protocol_st *instance)
 
 struct memcached_protocol_client_st *memcached_protocol_create_client(struct memcached_protocol_st *instance, memcached_socket_t sock)
 {
-  struct memcached_protocol_client_st *ret= calloc(1, sizeof(*ret));
+  struct memcached_protocol_client_st *ret= calloc(1, sizeof(memcached_protocol_client_st));
   if (ret != NULL)
   {
     ret->root= instance;
@@ -323,6 +349,14 @@ void memcached_protocol_client_destroy(struct memcached_protocol_client_st *clie
   free(client);
 }
 
+void memcached_protocol_client_set_verbose(struct memcached_protocol_client_st *client, bool arg)
+{
+  if (client)
+  {
+    client->is_verbose= arg;
+  }
+}
+
 memcached_protocol_event_t memcached_protocol_client_work(struct memcached_protocol_client_st *client)
 {
   /* Try to send data and read from the socket */
@@ -395,7 +429,9 @@ memcached_protocol_event_t memcached_protocol_client_work(struct memcached_proto
 
   memcached_protocol_event_t ret= MEMCACHED_PROTOCOL_READ_EVENT;
   if (client->output)
+  {
     ret|= MEMCACHED_PROTOCOL_READ_EVENT;
+  }
 
   return ret;
 }
diff --git a/libtest/abort.cc b/libtest/abort.cc
new file mode 100644 (file)
index 0000000..05dfa26
--- /dev/null
@@ -0,0 +1,11 @@
+#include <cstdlib>
+
+int main(void)
+{
+  if (1)
+  {
+    abort();
+  }
+
+  return 0;
+}
index 8bbd073857ce8d2bdb1430725e603f6221bdefa5..fe1cdce31baeaa6f75b72fd1b5bd1596dbf93cc0 100644 (file)
@@ -122,24 +122,19 @@ public:
     return "benchmark/blobslap_worker";
   }
 
-  const char *pid_file_option()
-  {
-    return "--pid-file=";
-  }
-
   const char *daemon_file_option()
   {
     return "--daemon";
   }
 
-  const char *log_file_option()
+  bool has_port_option() const
   {
-    return "--log-file=";
+    return true;
   }
 
-  const char *port_option()
+  bool has_log_file_option() const
   {
-    return "--port=";
+    return true;
   }
 
   bool is_libtool()
@@ -147,23 +142,21 @@ public:
     return true;
   }
 
-  bool build(int argc, const char *argv[]);
+  bool build(size_t argc, const char *argv[]);
 };
 
 
 #include <sstream>
 
-bool BlobslapWorker::build(int argc, const char *argv[])
+bool BlobslapWorker::build(size_t argc, const char *argv[])
 {
   std::stringstream arg_buffer;
 
-  for (int x= 1 ; x < argc ; x++)
+  for (size_t x= 0 ; x < argc ; x++)
   {
-    arg_buffer << " " << argv[x] << " ";
+    add_option(argv[x]);
   }
 
-  set_extra_args(arg_buffer.str());
-
   return true;
 }
 
index 7c2f5f442662748bfabd8e0a70fad4878e08f5bd..efe03040e5088f1742ba95059830433ba077b305 100644 (file)
@@ -26,6 +26,7 @@ using namespace libtest;
 #include <cstdlib>
 #include <cstring>
 #include <fcntl.h>
+#include <fstream>
 #include <memory>
 #include <spawn.h>
 #include <sstream>
@@ -56,7 +57,7 @@ extern "C" {
 
 namespace {
 
-  std::string print_argv(char * * & built_argv, const size_t& argc, const pid_t& pid)
+  std::string print_argv(char * * & built_argv, const size_t& argc)
   {
     std::stringstream arg_buffer;
 
@@ -68,12 +69,41 @@ namespace {
     return arg_buffer.str();
   }
 
+  std::string print_argv(char** argv)
+  {
+    std::stringstream arg_buffer;
+
+    for (char** ptr= argv; *ptr; ptr++)
+    {
+      arg_buffer << *ptr << " ";
+    }
+
+    return arg_buffer.str();
+  }
+
+  static Application::error_t int_to_error_t(int arg)
+  {
+    switch (arg)
+    {
+    case 127:
+      return Application::INVALID;
+
+    case 0:
+      return Application::SUCCESS;
+
+    default:
+    case 1:
+      return Application::FAILURE;
+    }
+  }
 }
 
 namespace libtest {
 
 Application::Application(const std::string& arg, const bool _use_libtool_arg) :
   _use_libtool(_use_libtool_arg),
+  _use_valgrind(false),
+  _use_gdb(false),
   _argc(0),
   _exectuble(arg),
   built_argv(NULL),
@@ -87,6 +117,19 @@ Application::Application(const std::string& arg, const bool _use_libtool_arg) :
       }
     }
 
+    // Find just the name of the application with no path
+    {
+      size_t found= arg.find_last_of("/\\");
+      if (found)
+      {
+        _exectuble_name= arg.substr(found +1);
+      }
+      else
+      {
+        _exectuble_name= arg;
+      }
+    }
+
     if (_use_libtool and getenv("PWD"))
     {
       _exectuble_with_path+= getenv("PWD");
@@ -118,13 +161,66 @@ Application::error_t Application::run(const char *args[])
   create_argv(args);
 
   int spawn_ret;
-  if (_use_libtool)
+  if (_use_gdb)
   {
-    spawn_ret= posix_spawn(&_pid, built_argv[0], &file_actions, NULL, built_argv, NULL);
+    std::string gdb_run_file= create_tmpfile(_exectuble_name);
+    std::fstream file_stream;
+    file_stream.open(gdb_run_file.c_str(), std::fstream::out | std::fstream::trunc);
+
+    _gdb_filename= create_tmpfile(_exectuble_name);
+    file_stream 
+      << "set logging redirect on" << std::endl
+      << "set logging file " << _gdb_filename << std::endl
+      << "set logging overwrite on" << std::endl
+      << "set logging on" << std::endl
+      << "set environment LIBTEST_IN_GDB=1" << std::endl
+      << "run " << arguments() << std::endl
+      << "thread apply all bt" << std::endl
+      << "quit" << std::endl;
+
+    fatal_assert(file_stream.good());
+    file_stream.close();
+
+    if (_use_libtool)
+    {
+      // libtool --mode=execute gdb -f -x binary
+      char *argv[]= {
+        const_cast<char *>(libtool()),
+        const_cast<char *>("--mode=execute"),
+        const_cast<char *>("gdb"),
+        const_cast<char *>("-batch"),
+        const_cast<char *>("-f"),
+        const_cast<char *>("-x"),
+        const_cast<char *>(gdb_run_file.c_str()), 
+        const_cast<char *>(_exectuble_with_path.c_str()), 
+        0};
+
+      spawn_ret= posix_spawnp(&_pid, libtool(), &file_actions, NULL, argv, NULL);
+    }
+    else
+    {
+      // gdb binary
+      char *argv[]= {
+        const_cast<char *>("gdb"),
+        const_cast<char *>("-batch"),
+        const_cast<char *>("-f"),
+        const_cast<char *>("-x"),
+        const_cast<char *>(gdb_run_file.c_str()), 
+        const_cast<char *>(_exectuble_with_path.c_str()), 
+        0};
+      spawn_ret= posix_spawnp(&_pid, "gdb", &file_actions, NULL, argv, NULL);
+    }
   }
   else
   {
-    spawn_ret= posix_spawnp(&_pid, built_argv[0], &file_actions, NULL, built_argv, NULL);
+    if (_use_libtool)
+    {
+      spawn_ret= posix_spawn(&_pid, built_argv[0], &file_actions, NULL, built_argv, NULL);
+    }
+    else
+    {
+      spawn_ret= posix_spawnp(&_pid, built_argv[0], &file_actions, NULL, built_argv, NULL);
+    }
   }
 
   posix_spawn_file_actions_destroy(&file_actions);
@@ -135,7 +231,6 @@ Application::error_t Application::run(const char *args[])
 
   if (spawn_ret)
   {
-    Error << print();
     return Application::INVALID;
   }
 
@@ -214,17 +309,20 @@ Application::error_t Application::wait()
     }
     else
     {
-      assert(waited_pid == _pid);
-      exit_code= error_t(exited_successfully(status));
+      if (waited_pid != _pid)
+      {
+        throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "Pid mismatch, %d != %d", int(waited_pid), int(_pid));
+      }
+      exit_code= int_to_error_t(exited_successfully(status));
     }
   }
 
+#if 0
   if (exit_code == Application::INVALID)
   {
-#if 0
-    Error << print_argv(built_argv, _argc, _pid);
-#endif
+    Error << print_argv(built_argv, _argc);
   }
+#endif
 
   return exit_code;
 }
@@ -325,6 +423,18 @@ void Application::create_argv(const char *args[])
     _argc+= 2; // +2 for libtool --mode=execute
   }
 
+  /*
+    valgrind --error-exitcode=1 --leak-check=yes --show-reachable=yes --track-fds=yes --malloc-fill=A5 --free-fill=DE
+  */
+  if (_use_valgrind)
+  {
+    _argc+= 7;
+  }
+  else if (_use_gdb) // gdb
+  {
+    _argc+= 1;
+  }
+
   for (Options::const_iterator iter= _options.begin(); iter != _options.end(); iter++)
   {
     _argc++;
@@ -352,6 +462,25 @@ void Application::create_argv(const char *args[])
     built_argv[x++]= strdup(libtool());
     built_argv[x++]= strdup("--mode=execute");
   }
+
+  if (_use_valgrind)
+  {
+    /*
+      valgrind --error-exitcode=1 --leak-check=yes --show-reachable=yes --track-fds=yes --malloc-fill=A5 --free-fill=DE
+    */
+    built_argv[x++]= strdup("valgrind");
+    built_argv[x++]= strdup("--error-exitcode=1");
+    built_argv[x++]= strdup("--leak-check=yes");
+    built_argv[x++]= strdup("--show-reachable=yes");
+    built_argv[x++]= strdup("--track-fds=yes");
+    built_argv[x++]= strdup("--malloc-fill=A5");
+    built_argv[x++]= strdup("--free-fill=DE");
+  }
+  else if (_use_gdb)
+  {
+    built_argv[x++]= strdup("gdb");
+  }
+
   built_argv[x++]= strdup(_exectuble_with_path.c_str());
 
   for (Options::const_iterator iter= _options.begin(); iter != _options.end(); iter++)
@@ -375,7 +504,21 @@ void Application::create_argv(const char *args[])
 
 std::string Application::print()
 {
-  return print_argv(built_argv, _argc, _pid);
+  return print_argv(built_argv, _argc);
+}
+
+std::string Application::arguments()
+{
+  std::stringstream arg_buffer;
+
+  for (size_t x= 1 + _use_libtool ? 2 : 0;
+       x < _argc and built_argv[x];
+       x++)
+  {
+    arg_buffer << built_argv[x] << " ";
+  }
+
+  return arg_buffer.str();
 }
 
 void Application::delete_argv()
@@ -408,9 +551,8 @@ int exec_cmdline(const std::string& command, const char *args[], bool use_libtoo
   {
     return int(ret);
   }
-  ret= app.wait();
 
-  return int(ret);
+  return int(app.wait());
 }
 
 const char *gearmand_binary() 
index d1019d548a6b65a98d54bd495e929e8e274a3553..f6da62bea260d02aeae9f1bdddff693cb09588c0 100644 (file)
@@ -95,15 +95,36 @@ public:
 
   std::string print();
 
+  void use_valgrind(bool arg= true)
+  {
+    _use_valgrind= arg;
+  }
+
+  void use_gdb(bool arg= true)
+  {
+    _use_gdb= arg;
+  }
+
+  std::string arguments();
+
+  std::string gdb_filename()
+  {
+    return  _gdb_filename;
+  }
+
 private:
   void create_argv(const char *args[]);
   void delete_argv();
 
 private:
   const bool _use_libtool;
+  bool _use_valgrind;
+  bool _use_gdb;
   size_t _argc;
+  std::string _exectuble_name;
   std::string _exectuble;
   std::string _exectuble_with_path;
+  std::string _gdb_filename;
   Options _options;
   Pipe stdin_fd;
   Pipe stdout_fd;
@@ -129,6 +150,9 @@ static inline std::ostream& operator<<(std::ostream& output, const enum Applicat
     case Application::INVALID:
       output << "127";
       break;
+
+    default:
+      output << "EXIT_UNKNOWN";
   }
 
   return output;
diff --git a/libtest/cpu.cc b/libtest/cpu.cc
new file mode 100644 (file)
index 0000000..d75df95
--- /dev/null
@@ -0,0 +1,65 @@
+/*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ * 
+ *  libtest
+ *
+ *  Copyright (C) 2012 Data Differential, http://datadifferential.com/
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 3 of the License, or (at your option) any later version.
+ *
+ *  This library 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
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include <libtest/common.h>
+
+#include <unistd.h>
+
+#if defined(HAVE_SYS_SYSCTL_H) && HAVE_SYS_SYSCTL_H
+#include <sys/sysctl.h>
+#endif
+
+namespace libtest {
+
+size_t number_of_cpus()
+{
+  size_t number_of_cpu= 1;
+#if TARGET_OS_LINUX
+  number_of_cpu= sysconf(_SC_NPROCESSORS_ONLN);
+#elif defined(HAVE_SYS_SYSCTL_H) && defined(CTL_HW) && defined(HW_NCPU) && defined(HW_AVAILCPU) && defined(HW_NCPU)
+  int mib[4];
+  size_t len= sizeof(number_of_cpu); 
+
+  /* set the mib for hw.ncpu */
+  mib[0] = CTL_HW;
+  mib[1] = HW_AVAILCPU;  // alternatively, try HW_NCPU;
+
+  /* get the number of CPUs from the system */
+  sysctl(mib, 2, &number_of_cpu, &len, NULL, 0);
+
+  if (number_of_cpu < 1) 
+  {
+    mib[1]= HW_NCPU;
+    sysctl(mib, 2, &number_of_cpu, &len, NULL, 0 );
+
+    if (number_of_cpu < 1 )
+    {
+      number_of_cpu = 1;
+    }
+  }
+#else
+  fprintf(stderr, "Going with guessing\n");
+#endif
+
+  return number_of_cpu;
+}
+
+} // namespace libtest
diff --git a/libtest/cpu.hpp b/libtest/cpu.hpp
new file mode 100644 (file)
index 0000000..78dabc3
--- /dev/null
@@ -0,0 +1,28 @@
+/*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ * 
+ *  libtest
+ *
+ *  Copyright (C) 2012 Data Differential, http://datadifferential.com/
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 3 of the License, or (at your option) any later version.
+ *
+ *  This library 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
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#pragma once
+
+namespace libtest {
+
+size_t number_of_cpus();
+
+} // namespace libtest
index 3fa5bfa21faab584b5df0eed8b4bfe7228e00480..7e34227620552cf291799b873dfc0195699948cd 100644 (file)
@@ -25,9 +25,7 @@
 enum test_return_t {
   TEST_SUCCESS,
   TEST_FAILURE,
-  TEST_MEMORY_ALLOCATION_FAILURE,
-  TEST_SKIPPED,
-  TEST_FATAL // Collection should not be continued
+  TEST_SKIPPED
 };
 
 
index b64b3606e8da253770e183ba6efce2d9566be054..23f47bd9d65b9decad8286ee03ad864160a0be98 100644 (file)
@@ -56,3 +56,4 @@ private:
 } // namespace libtest
 
 #define fatal_message(__mesg) libtest::fatal(LIBYATL_DEFAULT_PARAM, __mesg)
+#define fatal_assert(__assert) if((__assert)) {} else { libtest::fatal(LIBYATL_DEFAULT_PARAM, #__assert); }
index bcb7f8aaba2d7bcd7d033d4bf534b14b5ece03d2..4a544f10b9671eeb35b5263e2ee4b069c40e440b 100644 (file)
@@ -164,24 +164,25 @@ public:
     return GEARMAND_BINARY;
   }
 
-  const char *pid_file_option()
-  {
-    return "--pid-file=";
-  }
-
   const char *daemon_file_option()
   {
     return "--daemon";
   }
 
-  const char *log_file_option()
+  void log_file_option(Application& app, const std::string& arg)
   {
-    return "--verbose=DEBUG --log-file=";
+    if (arg.empty() == false)
+    {
+      std::string buffer("--log-file=");
+      buffer+= arg;
+      app.add_option("--verbose=DEBUG");
+      app.add_option(buffer);
+    }
   }
 
-  const char *port_option()
+  bool has_log_file_option() const
   {
-    return "--port=";
+    return true;
   }
 
   bool is_libtool()
@@ -194,27 +195,30 @@ public:
     return true;
   }
 
-  bool build(int argc, const char *argv[]);
+  bool has_port_option() const
+  {
+    return true;
+  }
+
+  bool build(size_t argc, const char *argv[]);
 };
 
-bool Gearmand::build(int argc, const char *argv[])
+bool Gearmand::build(size_t argc, const char *argv[])
 {
   std::stringstream arg_buffer;
 
   if (getuid() == 0 or geteuid() == 0)
   {
-    arg_buffer << " -u root ";
+    add_option("-u", "root");
   }
 
-  arg_buffer << " --listen=localhost ";
+  add_option("--listen=localhost");
 
-  for (int x= 1 ; x < argc ; x++)
+  for (size_t x= 0 ; x < argc ; x++)
   {
-    arg_buffer << " " << argv[x] << " ";
+    add_option(argv[x]);
   }
 
-  set_extra_args(arg_buffer.str());
-
   return true;
 }
 
index 257b1f7f587f08d3eb28a2e00f0a334f8be86583..92dc7d2776f61744852faafaf682619929a5b09d 100644 (file)
@@ -57,6 +57,7 @@ distclean-libtest-check:
 
 noinst_HEADERS+= \
                 libtest/binaries.h \
+                libtest/cpu.hpp \
                 libtest/blobslap_worker.h \
                 libtest/callbacks.h \
                 libtest/cmdline.h \
@@ -78,8 +79,8 @@ noinst_HEADERS+= \
                 libtest/killpid.h \
                 libtest/libtool.hpp \
                 libtest/memcached.h \
-                libtest/runner.h \
                 libtest/port.h \
+                libtest/runner.h \
                 libtest/server.h \
                 libtest/server_container.h \
                 libtest/signal.h \
@@ -90,6 +91,7 @@ noinst_HEADERS+= \
                 libtest/string.hpp \
                 libtest/test.h \
                 libtest/test.hpp \
+                libtest/tmpfile.hpp \
                 libtest/vchar.hpp \
                 libtest/visibility.h \
                 libtest/wait.h
@@ -99,6 +101,7 @@ libtest_libtest_la_SOURCES= \
                            libtest/binaries.cc \
                            libtest/cmdline.cc \
                            libtest/core.cc \
+                           libtest/cpu.cc \
                            libtest/dream.cc \
                            libtest/fatal.cc \
                            libtest/framework.cc \
@@ -115,6 +118,7 @@ libtest_libtest_la_SOURCES= \
                            libtest/socket.cc \
                            libtest/strerror.cc \
                            libtest/test.cc \
+                           libtest/tmpfile.cc \
                            libtest/vchar.cc
 
 libtest_libtest_la_CXXFLAGS=
@@ -197,7 +201,7 @@ tmp_chroot/var/run: tmp_chroot/var
        @$(mkdir_p) tmp_chroot/var/run
 
 
-libtest_unittest_DEPENDENCIES+= libtest/libtest.la libtest_tmp_dir
+libtest_unittest_DEPENDENCIES+= libtest/libtest.la libtest_tmp_dir libtest/abort libtest/wait
 libtest_unittest_LDADD+= libtest/libtest.la
 libtest_unittest_SOURCES= libtest/unittest.cc
 check_PROGRAMS+= libtest/unittest
@@ -224,3 +228,6 @@ noinst_PROGRAMS+= libtest/skiptest
 
 libtest_wait_SOURCES= libtest/wait.cc
 noinst_PROGRAMS+= libtest/wait
+
+libtest_abort_SOURCES= libtest/abort.cc
+noinst_PROGRAMS+= libtest/abort
index 7d25153fb078c783734bdaa314ce4862f1f51b70..c5358bf53fa5da4bdf4b6b7c68f777bddd87c873 100644 (file)
@@ -85,7 +85,7 @@ public:
   pid_t get_pid(bool error_is_ok)
   {
     // Memcached is slow to start, so we need to do this
-    if (not pid_file().empty())
+    if (pid_file().empty() == false)
     {
       if (error_is_ok and not wait_for_pidfile())
       {
@@ -123,7 +123,7 @@ public:
     // Memcached is slow to start, so we need to do this
     if (not pid_file().empty())
     {
-      if (not wait_for_pidfile())
+      if (wait_for_pidfile() == false)
       {
         Error << "Pidfile was not found:" << pid_file();
         return -1;
@@ -160,9 +160,12 @@ public:
     return MEMCACHED_BINARY;
   }
 
-  const char *pid_file_option()
+  virtual void pid_file_option(Application& app, const std::string& arg)
   {
-    return "-P ";
+    if (arg.empty() == false)
+    {
+      app.add_option("-P", arg);
+    }
   }
 
   const char *socket_file_option() const
@@ -175,14 +178,29 @@ public:
     return "-d";
   }
 
-  const char *log_file_option()
+  virtual void port_option(Application& app, in_port_t arg)
   {
-    return NULL;
+    char buffer[30];
+    snprintf(buffer, sizeof(buffer), "%d", int(arg));
+    app.add_option("-p", buffer); 
+  }
+
+  bool has_port_option() const
+  {
+    return true;
   }
 
-  const char *port_option()
+  bool has_socket_file_option() const
   {
-    return "-p ";
+    return has_socket();
+  }
+
+  void socket_file_option(Application& app, const std::string& socket_arg)
+  {
+    if (socket_arg.empty() == false)
+    {
+      app.add_option("-s", socket_arg);
+    }
   }
 
   bool is_libtool()
@@ -201,7 +219,124 @@ public:
     return true;
   }
 
-  bool build(int argc, const char *argv[]);
+  bool build(size_t argc, const char *argv[]);
+};
+
+class MemcachedLight : public libtest::Server
+{
+
+public:
+  MemcachedLight(const std::string& host_arg, const in_port_t port_arg):
+    libtest::Server(host_arg, port_arg)
+  {
+    set_pid_file();
+  }
+
+  pid_t get_pid(bool error_is_ok)
+  {
+    // Memcached is slow to start, so we need to do this
+    if (not pid_file().empty())
+    {
+      if (error_is_ok and not wait_for_pidfile())
+      {
+        Error << "Pidfile was not found:" << pid_file();
+        return -1;
+      }
+    }
+
+    bool success= false;
+    std::stringstream error_message;
+    pid_t local_pid= get_pid_from_file(pid_file(), error_message);
+    if (local_pid > 0)
+    {
+      if (::kill(local_pid, 0) > 0)
+      {
+        success= true;
+      }
+    }
+
+    if (error_is_ok and ((success or not is_pid_valid(local_pid))))
+    {
+      Error << "kill(" << " pid: " << local_pid << " errno:" << strerror(errno) << " for:" << *this;
+    }
+
+    return local_pid;
+  }
+
+  bool ping()
+  {
+    // Memcached is slow to start, so we need to do this
+    if (not pid_file().empty())
+    {
+      if (not wait_for_pidfile())
+      {
+        Error << "Pidfile was not found:" << pid_file();
+        return false;
+      }
+    }
+
+    std::stringstream error_message;
+    pid_t local_pid= get_pid_from_file(pid_file(), error_message);
+    if (local_pid > 0)
+    {
+      if (::kill(local_pid, 0) == 0)
+      {
+        return true;
+      }
+    }
+
+    return false;
+  }
+
+  const char *name()
+  {
+    return "memcached_light";
+  };
+
+  const char *executable()
+  {
+    return MEMCACHED_LIGHT_BINARY;
+  }
+
+  const char *daemon_file_option()
+  {
+    return "--daemon";
+  }
+
+  virtual void port_option(Application& app, in_port_t arg)
+  {
+    char buffer[1024];
+    snprintf(buffer, sizeof(buffer), "--port=%d", int(arg));
+    app.add_option(buffer);
+  }
+
+  bool has_port_option() const
+  {
+    return true;
+  }
+
+  bool is_libtool()
+  {
+    return true;
+  }
+
+  void log_file_option(Application& app, const std::string& arg)
+  {
+    if (arg.empty() == false)
+    {
+      std::string buffer("--log-file=");
+      buffer+= arg;
+      app.add_option("--verbose");
+      app.add_option(buffer);
+    }
+  }
+
+  bool has_log_file_option() const
+  {
+    return true;
+  }
+
+  bool build(size_t argc, const char *argv[]);
 };
 
 class MemcachedSaSL : public Memcached
@@ -294,30 +429,38 @@ public:
 
 #include <sstream>
 
-bool Memcached::build(int argc, const char *argv[])
+bool Memcached::build(size_t argc, const char *argv[])
 {
   std::stringstream arg_buffer;
 
   if (getuid() == 0 or geteuid() == 0)
   {
-    arg_buffer << " -u root ";
+    add_option("-u", "root");
   }
 
-  arg_buffer << " -l localhost ";
-  arg_buffer << " -m 128 ";
-  arg_buffer << " -M ";
+  add_option("-l", "localhost");
+  add_option("-m", "128");
+  add_option("-M");
 
   if (sasl())
   {
-    arg_buffer << sasl();
+    add_option(sasl());
   }
 
-  for (int x= 1 ; x < argc ; x++)
+  for (int x= 0 ; x < argc ; x++)
   {
-    arg_buffer << " " << argv[x] << " ";
+    add_option(argv[x]);
   }
 
-  set_extra_args(arg_buffer.str());
+  return true;
+}
+
+bool MemcachedLight::build(size_t argc, const char *argv[])
+{
+  for (int x= 0 ; x < argc ; x++)
+  {
+    add_option(argv[x]);
+  }
 
   return true;
 }
@@ -334,6 +477,11 @@ libtest::Server *build_memcached_socket(const std::string& socket_file, const in
   return new Memcached(socket_file, try_port, true);
 }
 
+libtest::Server *build_memcached_light(const std::string& hostname, const in_port_t try_port)
+{
+  return new MemcachedLight(hostname, try_port);
+}
+
 
 libtest::Server *build_memcached_sasl(const std::string& hostname, const in_port_t try_port, const std::string& username, const std::string &password)
 {
index a08996140189c69648823700d6306faa5ad96125..4594d5b6abe44ca76defa5e9a21c9e85f185402c 100644 (file)
@@ -25,6 +25,8 @@ namespace libtest {
 
 libtest::Server *build_memcached(const std::string& hostname, const in_port_t try_port);
 
+libtest::Server *build_memcached_light(const std::string& socket_file, const in_port_t try_port);
+
 libtest::Server *build_memcached_socket(const std::string& socket_file, const in_port_t try_port);
 
 libtest::Server *build_memcached_sasl(const std::string& hostname, const in_port_t try_port, const std::string& username, const std::string& password);
index 320407a23012715afb8d63f03c3dcaae9fc67e03..86b5fe07a31abaf17d6c8f237383cc2e3e11eec5 100644 (file)
@@ -1,2 +1,6 @@
+set logging on
+set logging overwrite on
 set environment LIBTEST_IN_GDB=1
 run
+thread apply all bt
+quit
index 9d492b9b84aa1d902f6e8a30a8cddee6fbf6062d..e554039a1c523d8dea88c4c869f89f067af85ed8 100644 (file)
@@ -42,42 +42,6 @@ static inline std::string &rtrim(std::string &s)
 #include <libtest/stream.h>
 #include <libtest/killpid.h>
 
-extern "C" {
-  static bool exited_successfully(int status, const std::string &command)
-  {
-    if (status == 0)
-    {
-      return true;
-    }
-
-    if (WIFEXITED(status) == true)
-    {
-      int ret= WEXITSTATUS(status);
-
-      if (ret == 0)
-      {
-        return true;
-      }
-      else if (ret == EXIT_FAILURE)
-      {
-        libtest::Error << "Command executed, but returned EXIT_FAILURE: " << command;
-      }
-      else
-      {
-        libtest::Error << "Command executed, but returned " << ret;
-      }
-    }
-    else if (WIFSIGNALED(status) == true)
-    {
-      int ret_signal= WTERMSIG(status);
-      libtest::Error << "Died from signal " << strsignal(ret_signal);
-    }
-
-    return false;
-  }
-}
-
-
 namespace libtest {
 
 std::ostream& operator<<(std::ostream& output, const Server &arg)
@@ -106,7 +70,6 @@ std::ostream& operator<<(std::ostream& output, const Server &arg)
     output << " Exec:" <<  arg.running();
   }
 
-
   return output;  // for multiple << operators
 }
 
@@ -153,21 +116,6 @@ bool Server::cycle()
   return true;
 }
 
-// Grab a one off command
-bool Server::command(std::string& command_arg)
-{
-  rebuild_base_command();
-
-  command_arg+= _base_command;
-
-  if (args(command_arg))
-  {
-    return true;
-  }
-
-  return false;
-}
-
 bool Server::wait_for_pidfile() const
 {
   Wait wait(pid_file(), 4);
@@ -183,25 +131,43 @@ bool Server::start()
     Error << "Could not kill() existing server during start() pid:" << _pid;
     return false;
   }
-  assert(not has_pid());
 
-  _running.clear();
-  if (command(_running) == false)
+  if (has_pid() == false)
+  {
+    fatal_message("has_pid() failed, programer error");
+  }
+
+  Application app(executable(), is_libtool());
+
+  if (is_debug())
+  {
+    app.use_gdb();
+  }
+  else if (getenv("TESTS_ENVIRONMENT"))
+  {
+    if (strstr(getenv("TESTS_ENVIRONMENT"), "gdb"))
+    {
+      app.use_gdb();
+    }
+  }
+
+  if (args(app) == false)
   {
     Error << "Could not build command()";
     return false;
   }
 
-  if (is_valgrind() or is_helgrind())
+  Application::error_t ret;
+  if (Application::SUCCESS !=  (ret= app.run()))
   {
-    _running+= " &";
+    Error << "Application::run() " << ret;
+    return false;
   }
+  _running= app.print();
 
-  int ret= system(_running.c_str());
-  if (exited_successfully(ret, _running) == false)
+  if (Application::SUCCESS !=  (ret= app.wait()))
   {
-    Error << "system(" << _running << ") failed: " << strerror(errno);
-    _running.clear();
+    Error << "Application::wait() " << app.print() << " " << ret;
     return false;
   }
 
@@ -210,7 +176,7 @@ bool Server::start()
     dream(5, 50000);
   }
 
-  if (pid_file_option() and pid_file().empty() == false)
+  if (pid_file().empty() == false)
   {
     Wait wait(pid_file(), 8);
 
@@ -231,12 +197,18 @@ bool Server::start()
   if (pinged == false)
   {
     // If we happen to have a pid file, lets try to kill it
-    if (pid_file_option() and pid_file().empty() == false)
+    if (pid_file().empty() == false)
+    {
+      if (kill_file(pid_file()) == false)
+      {
+        fatal_message("Failed to kill off server after startup occurred, when pinging failed");
+      }
+      Error << "Failed to ping() server started, having pid_file. exec:" << _running;
+    }
+    else
     {
-      Error << "We are going to kill it off";
-      kill_file(pid_file());
+      Error << "Failed to ping() server started. exec:" << _running;
     }
-    Error << "Failed to ping() server started with:" << _running;
     _running.clear();
     return false;
   }
@@ -259,6 +231,16 @@ pid_t Server::pid()
   return _pid;
 }
 
+void Server::add_option(const std::string& arg)
+{
+  _options.push_back(std::make_pair(arg, std::string()));
+}
+
+void Server::add_option(const std::string& name, const std::string& value)
+{
+  _options.push_back(std::make_pair(name, value));
+}
+
 bool Server::set_socket_file()
 {
   char file_buffer[FILENAME_MAX];
@@ -324,8 +306,7 @@ bool Server::set_log_file()
   int fd;
   if ((fd= mkstemp(file_buffer)) == -1)
   {
-    perror(file_buffer);
-    return false;
+    libtest::fatal(LIBYATL_DEFAULT_PARAM, "mkstemp() failed on %s with %s", file_buffer, strerror(errno));
   }
   close(fd);
 
@@ -334,106 +315,62 @@ bool Server::set_log_file()
   return true;
 }
 
-void Server::rebuild_base_command()
-{
-  _base_command.clear();
-  if (is_libtool())
-  {
-    _base_command+= libtool();
-    _base_command+= " --mode=execute ";
-  }
-
-  if (is_debug() and getenv("GDB_COMMAND"))
-  {
-    _base_command+= getenv("GDB_COMMAND");
-    _base_command+= " ";
-  }
-  else if (is_valgrind() and getenv("VALGRIND_COMMAND"))
-  {
-    _base_command+= getenv("VALGRIND_COMMAND");
-    _base_command+= " ";
-  }
-  else if (is_helgrind() and getenv("HELGRIND_COMMAND"))
-  {
-    _base_command+= getenv("HELGRIND_COMMAND");
-    _base_command+= " ";
-  }
-
-  if (is_libtool())
-  {
-    if (getenv("PWD"))
-    {
-      _base_command+= getenv("PWD");
-      _base_command+= "/";
-    }
-  }
-
-  _base_command+= executable();
-}
-
-void Server::set_extra_args(const std::string &arg)
-{
-  _extra_args= arg;
-}
-
-bool Server::args(std::string& options)
+bool Server::args(Application& app)
 {
-  std::stringstream arg_buffer;
 
   // Set a log file if it was requested (and we can)
-  if (getenv("LIBTEST_LOG") and log_file_option())
+  if (has_log_file_option())
   {
-    if (not set_log_file())
-    {
-      return false;
-    }
-
-    arg_buffer << " " << log_file_option() << _log_file;
+    set_log_file();
+    log_file_option(app, _log_file);
   }
 
   if (getenv("LIBTEST_SYSLOG") and has_syslog())
   {
-    arg_buffer << " --syslog";
+    app.add_option("--syslog");
   }
 
   // Update pid_file
-  if (pid_file_option())
   {
     if (_pid_file.empty() and set_pid_file() == false)
     {
       return false;
     }
 
-    arg_buffer << " " << pid_file_option() << pid_file(); 
+    pid_file_option(app, pid_file());
   }
 
   assert(daemon_file_option());
   if (daemon_file_option() and not is_valgrind() and not is_helgrind())
   {
-    arg_buffer << " " << daemon_file_option();
+    app.add_option(daemon_file_option());
   }
 
-  if (_is_socket and socket_file_option())
+  if (has_socket_file_option())
   {
-    if (not set_socket_file())
+    if (set_socket_file() == false)
     {
       return false;
     }
 
-    arg_buffer << " " << socket_file_option() << "\"" <<  _socket << "\"";
+    socket_file_option(app, _socket);
   }
 
-  assert(port_option());
-  if (port_option() and _port > 0)
+  if (has_port_option())
   {
-    arg_buffer << " " << port_option() << _port;
+    port_option(app, _port);
   }
 
-  options+= arg_buffer.str();
-
-  if (not _extra_args.empty())
+  for (Options::const_iterator iter= _options.begin(); iter != _options.end(); iter++)
   {
-    options+= _extra_args;
+    if ((*iter).second.empty() == false)
+    {
+      app.add_option((*iter).first, (*iter).second);
+    }
+    else
+    {
+      app.add_option((*iter).first);
+    }
   }
 
   return true;
index b50b0b2e6fe516a125b679a614e2e14eba9af19c..df2bbee814774d9ceb8146e0d5e1d97859f3794f 100644 (file)
@@ -21,6 +21,8 @@
 
 #pragma once
 
+#include <libtest/cmdline.h>
+
 #include <cassert>
 #include <cstdio>
 #include <cstring>
@@ -33,6 +35,9 @@
 namespace libtest {
 
 struct Server {
+private:
+  typedef std::vector< std::pair<std::string, std::string> > Options;
+
 private:
   bool _is_socket;
   std::string _socket;
@@ -55,20 +60,67 @@ public:
 
   virtual const char *name()= 0;
   virtual const char *executable()= 0;
-  virtual const char *port_option()= 0;
-  virtual const char *pid_file_option()= 0;
   virtual const char *daemon_file_option()= 0;
-  virtual const char *log_file_option()= 0;
   virtual bool is_libtool()= 0;
 
-  virtual bool broken_socket_cleanup()
+  virtual bool has_socket_file_option() const
+  {
+    return false;
+  }
+
+  virtual void socket_file_option(Application& app, const std::string& socket_arg)
+  {
+    if (socket_arg.empty() == false)
+    {
+      std::string buffer("--socket=");
+      buffer+= socket_arg;
+      app.add_option(buffer);
+    }
+  }
+
+  virtual bool has_log_file_option() const
+  {
+    return false;
+  }
+
+  virtual void log_file_option(Application& app, const std::string& arg)
+  {
+    if (arg.empty() == false)
+    {
+      std::string buffer("--log-file=");
+      buffer+= arg;
+      app.add_option(buffer);
+    }
+  }
+
+  virtual void pid_file_option(Application& app, const std::string& arg)
+  {
+    if (arg.empty() == false)
+    {
+      std::string buffer("--pid-file=");
+      buffer+= arg;
+      app.add_option(buffer);
+    }
+  }
+
+  virtual bool has_port_option() const
   {
     return false;
   }
 
-  virtual const char *socket_file_option() const
+  virtual void port_option(Application& app, in_port_t arg)
   {
-    return NULL;
+    if (arg > 0)
+    {
+      char buffer[1024];
+      snprintf(buffer, sizeof(buffer), "--port=%d", int(arg));
+      app.add_option(buffer);
+    }
+  }
+
+  virtual bool broken_socket_cleanup()
+  {
+    return false;
   }
 
   virtual bool broken_pid_file()
@@ -112,7 +164,10 @@ public:
 
   virtual pid_t get_pid(bool error_is_ok= false)= 0;
 
-  virtual bool build(int argc, const char *argv[])= 0;
+  virtual bool build(size_t argc, const char *argv[])= 0;
+
+  void add_option(const std::string&);
+  void add_option(const std::string&, const std::string&);
 
   in_port_t port() const
   {
@@ -137,9 +192,7 @@ public:
     _log_file.clear();
   }
 
-  void set_extra_args(const std::string &arg);
-
-  bool args(std::string& options);
+  bool args(Application&);
 
   pid_t pid();
 
@@ -174,10 +227,11 @@ public:
 
   bool kill(pid_t pid_arg);
   bool start();
-  bool command(std::string& command_arg);
+  bool command(libtest::Application& app);
 
 protected:
   bool set_pid_file();
+  Options _options;
 
 private:
   bool is_helgrind() const;
@@ -185,7 +239,6 @@ private:
   bool is_debug() const;
   bool set_log_file();
   bool set_socket_file();
-  void rebuild_base_command();
   void reset_pid();
 };
 
index 528fcd1fab180e288f45f9e356051e428f85f1c0..6d0c785e7de5f20d5d2d06d549ed7545e5b749ff 100644 (file)
@@ -144,7 +144,10 @@ bool server_startup_st::is_helgrind() const
 bool server_startup(server_startup_st& construct, const std::string& server_type, in_port_t try_port, int argc, const char *argv[])
 {
   Outn();
-  (void)try_port;
+  if (try_port <= 0)
+  {
+    libtest::fatal(LIBYATL_DEFAULT_PARAM, "was passed the invalid port number %d", int(try_port));
+  }
 
   libtest::Server *server= NULL;
   if (0)
@@ -192,11 +195,20 @@ bool server_startup(server_startup_st& construct, const std::string& server_type
       }
     }
   }
+  else if (server_type.compare("memcached-light") == 0)
+  {
+    if (MEMCACHED_LIGHT_BINARY)
+    {
+      if (HAVE_LIBMEMCACHED)
+      {
+        server= build_memcached_light("localhost", try_port);
+      }
+    }
+  }
 
   if (server == NULL)
   {
-    Error << "Failure occured while creating server: " <<  server_type;
-    return false;
+    fatal_message("Launching of an unknown server was attempted");
   }
 
   /*
@@ -216,7 +228,9 @@ bool server_startup(server_startup_st& construct, const std::string& server_type
     Out << "Pausing for startup, hit return when ready.";
     std::string gdb_command= server->base_command();
     std::string options;
+#if 0
     Out << "run " << server->args(options);
+#endif
     getchar();
   }
   else if (server->start() == false)
@@ -313,7 +327,9 @@ bool server_startup_st::start_socket_server(const std::string& server_type, cons
     Out << "Pausing for startup, hit return when ready.";
     std::string gdb_command= server->base_command();
     std::string options;
+#if 0
     Out << "run " << server->args(options);
+#endif
     getchar();
   }
   else if (not server->start())
index e4f0cf5089bc6e6af3f860b1dd5a14586c61a002..d081bafcd2d433af39afedb4d1ee399e5d16df32 100644 (file)
@@ -32,17 +32,11 @@ const char *test_strerror(test_return_t code)
   case TEST_FAILURE:
     return "failed";
 
-  case TEST_MEMORY_ALLOCATION_FAILURE:
-    return "memory allocation";
-
   case TEST_SKIPPED:
     return "skipped";
-
-  case TEST_FATAL:
-    break;
   }
 
-  return "failed";
+  throw fatal_message("No port could be found");
 }
 
 } // namespace libtest
index 92c1226b24ffca5e7b686926b99753c20051200c..66d258a0b009094430793e268598203ee8a836b9 100644 (file)
@@ -226,9 +226,7 @@ int main(int argc, char *argv[])
         delete world;
         return EXIT_SUCCESS;
 
-      case TEST_FATAL:
       case TEST_FAILURE:
-      case TEST_MEMORY_ALLOCATION_FAILURE:
         delete world;
         return EXIT_FAILURE;
       }
@@ -276,7 +274,6 @@ int main(int argc, char *argv[])
         case TEST_SUCCESS:
           break;
 
-        case TEST_FATAL:
         case TEST_FAILURE:
           Out << next->name << " [ failed ]";
           failed= true;
@@ -288,8 +285,8 @@ int main(int argc, char *argv[])
           skipped= true;
           goto cleanup;
 
-        case TEST_MEMORY_ALLOCATION_FAILURE:
-          test_assert(0, "Allocation failure, or unknown return");
+        default:
+          throw fatal_message("invalid return code");
         }
 
         Out << "Collection: " << next->name;
@@ -381,7 +378,6 @@ int main(int argc, char *argv[])
             stats.success++;
             break;
 
-          case TEST_FATAL:
           case TEST_FAILURE:
             stats.failed++;
             failed= true;
@@ -394,8 +390,8 @@ int main(int argc, char *argv[])
             Out << "\tTesting " << run->name <<  "\t\t\t\t\t" << "[ " << test_strerror(return_code) << " ]";
             break;
 
-          case TEST_MEMORY_ALLOCATION_FAILURE:
-            test_assert(0, "Memory Allocation Error");
+          default:
+            throw fatal_message("invalid return code");
           }
 
           if (test_failed(world->on_error(return_code, creators_ptr)))
@@ -464,6 +460,10 @@ cleanup:
   {
     std::cerr << e.what() << std::endl;
   }
+  catch (std::bad_alloc& e)
+  {
+    std::cerr << e.what() << std::endl;
+  }
   catch (...)
   {
     std::cerr << "Unknown exception halted execution" << std::endl;
index b77cd214e66a46723a8f8bdcee11df8eba0b05a6..eb1b56c079415e50b8d572262af380fdd5e235e3 100644 (file)
@@ -26,7 +26,6 @@
 
 #include <cstdio>
 #include <cstdlib>
-#include <stdint.h>
 #include <arpa/inet.h>
 
 #include <libtest/visibility.h>
@@ -60,3 +59,5 @@
 #include <libtest/string.hpp>
 #include <libtest/binaries.h>
 #include <libtest/http.hpp>
+#include <libtest/cpu.hpp>
+#include <libtest/tmpfile.hpp>
diff --git a/libtest/tmpfile.cc b/libtest/tmpfile.cc
new file mode 100644 (file)
index 0000000..1bbacda
--- /dev/null
@@ -0,0 +1,46 @@
+/*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ * 
+ *  libtest
+ *
+ *  Copyright (C) 2012 Data Differential, http://datadifferential.com/
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 3 of the License, or (at your option) any later version.
+ *
+ *  This library 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
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+
+#include <libtest/common.h>
+
+namespace libtest {
+
+std::string create_tmpfile(const std::string& name)
+{
+  char file_buffer[FILENAME_MAX];
+  file_buffer[0]= 0;
+
+  int length= snprintf(file_buffer, sizeof(file_buffer), "var/tmp/%s.XXXXXX", name.c_str());
+  fatal_assert(length > 0);
+
+  int fd;
+  if ((fd= mkstemp(file_buffer)) == -1)
+  {
+    libtest::fatal(LIBYATL_DEFAULT_PARAM, "mkstemp() failed on %s with %s", file_buffer, strerror(errno));
+  }
+  close(fd);
+  unlink(file_buffer);
+
+  return file_buffer;
+}
+
+} // namespace libtest
diff --git a/libtest/tmpfile.hpp b/libtest/tmpfile.hpp
new file mode 100644 (file)
index 0000000..5ab50c4
--- /dev/null
@@ -0,0 +1,31 @@
+/*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ * 
+ *  libtest
+ *
+ *  Copyright (C) 2012 Data Differential, http://datadifferential.com/
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 3 of the License, or (at your option) any later version.
+ *
+ *  This library 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
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#pragma once
+
+#include <libtest/common.h>
+
+namespace libtest {
+
+std::string create_tmpfile(const std::string&);
+
+} // namespace libtest
+
index 484b444393d5e0adeb254c597a26966999eed95c..7f0c7404fc2d5ca74997efaf1dc3a0bfcb281809 100644 (file)
@@ -236,8 +236,19 @@ static test_return_t gearmand_cycle_test(void *object)
   test_skip(true, has_gearmand_binary());
 #endif
 
-  const char *argv[1]= { "cycle_gearmand" };
-  test_true(server_startup(*servers, "gearmand", get_free_port(), 1, argv));
+  test_true(server_startup(*servers, "gearmand", get_free_port(), 0, NULL));
+
+  return TEST_SUCCESS;
+}
+
+static test_return_t memcached_light_cycle_TEST(void *object)
+{
+  server_startup_st *servers= (server_startup_st*)object;
+  test_true(servers);
+
+  test_skip(true, bool(HAVE_MEMCACHED_LIGHT_BINARY));
+
+  test_true(server_startup(*servers, "memcached-light", get_free_port(), 0, NULL));
 
   return TEST_SUCCESS;
 }
@@ -250,8 +261,7 @@ static test_return_t memcached_cycle_test(void *object)
   if (MEMCACHED_BINARY and HAVE_LIBMEMCACHED) 
   {
     test_true(has_memcached_binary());
-    const char *argv[1]= { "cycle_memcached" };
-    test_true(server_startup(*servers, "memcached", get_free_port(), 1, argv));
+    test_true(server_startup(*servers, "memcached", get_free_port(), 0, NULL));
 
     return TEST_SUCCESS;
   }
@@ -269,8 +279,7 @@ static test_return_t memcached_socket_cycle_test(void *object)
     if (HAVE_LIBMEMCACHED)
     {
       test_true(has_memcached_binary());
-      const char *argv[1]= { "cycle_memcached" };
-      test_true(servers->start_socket_server("memcached", get_free_port(), 1, argv));
+      test_true(servers->start_socket_server("memcached", get_free_port(), 0, NULL));
 
       return TEST_SUCCESS;
     }
@@ -294,8 +303,7 @@ static test_return_t memcached_sasl_test(void *object)
     if (HAVE_LIBMEMCACHED)
     {
       test_true(has_memcached_sasl_binary());
-      const char *argv[1]= { "cycle_memcached_sasl" };
-      test_true(server_startup(*servers, "memcached-sasl", get_free_port(), 1, argv));
+      test_true(server_startup(*servers, "memcached-sasl", get_free_port(), 0, NULL));
 
       return TEST_SUCCESS;
     }
@@ -314,6 +322,31 @@ static test_return_t application_true_BINARY(void *)
   return TEST_SUCCESS;
 }
 
+static test_return_t application_gdb_true_BINARY2(void *)
+{
+  test_skip(0, access("/usr/bin/gdb", X_OK ));
+  Application true_app("true");
+  true_app.use_gdb();
+
+  test_compare(Application::SUCCESS, true_app.run());
+  test_compare(Application::SUCCESS, true_app.wait());
+
+  return TEST_SUCCESS;
+}
+
+static test_return_t application_gdb_true_BINARY(void *)
+{
+  test_skip(0, access("/usr/bin/gdb", X_OK ));
+  Application true_app("true");
+  true_app.use_gdb();
+
+  const char *args[]= { "--fubar", 0 };
+  test_compare(Application::SUCCESS, true_app.run(args));
+  test_compare(Application::SUCCESS, true_app.wait());
+
+  return TEST_SUCCESS;
+}
+
 static test_return_t application_true_fubar_BINARY(void *)
 {
   Application true_app("true");
@@ -326,6 +359,34 @@ static test_return_t application_true_fubar_BINARY(void *)
   return TEST_SUCCESS;
 }
 
+static test_return_t application_doesnotexist_BINARY(void *)
+{
+  Application true_app("doesnotexist");
+
+  const char *args[]= { "--fubar", 0 };
+#if defined(TARGET_OS_OSX) && TARGET_OS_OSX
+  test_compare(Application::INVALID, true_app.run(args));
+#else
+  test_compare(Application::SUCCESS, true_app.run(args));
+#endif
+  // Behavior is different if we are running under valgrind
+  if (getenv("TESTS_ENVIRONMENT") and strstr(getenv("TESTS_ENVIRONMENT"), "valgrind"))
+  {
+    test_compare(Application::FAILURE, true_app.wait());
+  }
+  else
+  {
+#if defined(TARGET_OS_OSX) && TARGET_OS_OSX
+    test_compare(Application::FAILURE, true_app.wait());
+#else
+    test_compare(Application::INVALID, true_app.wait());
+#endif
+  }
+  test_compare(0, true_app.stdout_result().size());
+
+  return TEST_SUCCESS;
+}
+
 static test_return_t application_true_fubar_eq_doh_BINARY(void *)
 {
   Application true_app("true");
@@ -494,14 +555,61 @@ static test_return_t wait_services_BINARY2(void *)
   return TEST_SUCCESS;
 }
 
-static test_return_t application_wait_services_BINARY2(void *)
+static test_return_t wait_services_appliction_TEST(void *)
 {
+  test_skip(0, access("/usr/bin/gdb", X_OK ));
   test_skip(0, access("/etc/services", R_OK ));
 
-  libtest::Application("libtest/wait", true);
+  libtest::Application wait_app("libtest/wait", true);
+  wait_app.use_gdb();
+
   const char *args[]= { "/etc/services", 0 };
+  test_compare(Application::SUCCESS, wait_app.run(args));
+  test_compare(Application::SUCCESS, wait_app.wait());
 
-  test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
+  return TEST_SUCCESS;
+}
+
+static test_return_t gdb_wait_services_appliction_TEST(void *)
+{
+#if defined(TARGET_OS_OSX) && TARGET_OS_OSX
+  test_skip(0, TARGET_OS_OSX);
+#endif
+
+  test_skip(0, access("/usr/bin/gdb", X_OK ));
+  test_skip(0, access("/etc/services", R_OK ));
+
+  libtest::Application wait_app("libtest/wait", true);
+  wait_app.use_gdb();
+
+  const char *args[]= { "/etc/services", 0 };
+  test_compare(Application::SUCCESS, wait_app.run(args));
+  test_compare(Application::SUCCESS, wait_app.wait());
+
+  return TEST_SUCCESS;
+}
+
+static test_return_t gdb_abort_services_appliction_TEST(void *)
+{
+  test_skip(0, access("/usr/bin/gdb", X_OK ));
+
+#if defined(TARGET_OS_OSX) && TARGET_OS_OSX
+  test_skip(0, TARGET_OS_OSX);
+#endif
+
+  libtest::Application abort_app("libtest/abort", true);
+  abort_app.use_gdb();
+
+  test_compare(Application::SUCCESS, abort_app.run());
+  test_compare(Application::SUCCESS, abort_app.wait());
+
+  std::string gdb_filename= abort_app.gdb_filename();
+  const char *args[]= { "SIGABRT", gdb_filename.c_str(), 0 };
+  test_compare(EXIT_SUCCESS, exec_cmdline("grep", args));
+
+  // Sanity test
+  args[0]= "THIS_WILL_NOT_BE_FOUND";
+  test_compare(EXIT_FAILURE, exec_cmdline("grep", args));
 
   return TEST_SUCCESS;
 }
@@ -526,6 +634,28 @@ static test_return_t fatal_TEST(void *)
   return TEST_SUCCESS;
 }
 
+static test_return_t number_of_cpus_TEST(void *)
+{
+  test_true(number_of_cpus() >= 1);
+
+  return TEST_SUCCESS;
+}
+
+static test_return_t create_tmpfile_TEST(void *)
+{
+  std::string tmp= create_tmpfile(__func__);
+
+  Application touch_app("touch");
+  const char *args[]= { tmp.c_str(), 0 };
+  test_compare(Application::SUCCESS, touch_app.run(args));
+  test_compare(Application::SUCCESS, touch_app.wait());
+
+  test_compare_hint(0, access(tmp.c_str(), R_OK), strerror(errno));
+  test_compare_hint(0, unlink(tmp.c_str()), strerror(errno));
+
+  return TEST_SUCCESS;
+}
+
 static test_return_t fatal_message_TEST(void *)
 {
   test_compare(fatal_calls++, fatal::disabled_counter());
@@ -569,6 +699,7 @@ static test_return_t check_for_libmemcached(void *)
 
 test_st memcached_tests[] ={
   {"memcached startup-shutdown", 0, memcached_cycle_test },
+  {"memcached-light startup-shutdown", 0, memcached_light_cycle_TEST },
   {"memcached(socket file) startup-shutdown", 0, memcached_socket_cycle_test },
   {"memcached_sasl() startup-shutdown", 0, memcached_sasl_test },
   {"_compare(memcached_return_t)", 0, _compare_memcached_return_t_test },
@@ -624,6 +755,9 @@ test_st cmdline_tests[] ={
   {"wait --quiet --version", 0, wait_version_BINARY },
   {"wait --quiet /etc/services", 0, wait_services_BINARY },
   {"wait /etc/services", 0, wait_services_BINARY2 },
+  {"wait /etc/services", 0, wait_services_appliction_TEST },
+  {"gdb wait /etc/services", 0, gdb_wait_services_appliction_TEST },
+  {"gdb abort", 0, gdb_abort_services_appliction_TEST },
   {0, 0, 0}
 };
 
@@ -639,10 +773,23 @@ test_st fatal_message_TESTS[] ={
   {0, 0, 0}
 };
 
+test_st number_of_cpus_TESTS[] ={
+  {"libtest::number_of_cpus()", 0, number_of_cpus_TEST },
+  {0, 0, 0}
+};
+
+test_st create_tmpfile_TESTS[] ={
+  {"libtest::create_tmpfile()", 0, create_tmpfile_TEST },
+  {0, 0, 0}
+};
+
 test_st application_tests[] ={
   {"vchar_t", 0, vchar_t_TEST },
   {"true", 0, application_true_BINARY },
+  {"gbd true --fubar", 0, application_gdb_true_BINARY },
+  {"gbd true", 0, application_gdb_true_BINARY2 },
   {"true --fubar", 0, application_true_fubar_BINARY },
+  {"doesnotexist --fubar", 0, application_doesnotexist_BINARY },
   {"true --fubar=doh", 0, application_true_fubar_eq_doh_BINARY },
   {"true --fubar=doh add_option()", 0, application_true_fubar_eq_doh_option_BINARY },
   {"echo fubar", 0, application_echo_fubar_BINARY },
@@ -688,6 +835,8 @@ collection_st collection[] ={
   {"http", check_for_curl, 0, http_tests},
   {"get_free_port()", 0, 0, get_free_port_TESTS },
   {"fatal", disable_fatal_exception, enable_fatal_exception, fatal_message_TESTS },
+  {"number_of_cpus()", 0, 0, number_of_cpus_TESTS },
+  {"create_tmpfile()", 0, 0, create_tmpfile_TESTS },
   {0, 0, 0, 0}
 };
 
index 24af93c0b24fd6c6b93ee2d41ba20767e4b2facd..5998c792553253ee29987e069410d1d744046552 100644 (file)
@@ -90,6 +90,6 @@ AC_DEFUN([AX_CHECK_LIBRARY], [
 
   AS_IF([test "$]AS_TR_SH([ax_cv_have_]$1)[" = "yes"],
     AC_DEFINE([HAVE_]$1, [1], [Define to 1 if ]$1[ is found])
-      m4_ifnblank([$4], [$4]),
-    m4_ifnblank([$5], [$5]))
+      m4_ifval( m4_normalize([$4]), [$4]),
+    m4_ifval( m4_normalize([$5]), [$5]))
 ])
index 5cfa47ddbfd9553ad50b208d522a1f8228c10159..b34a8a7785a29089622fa6afd21c5fcdd08ebd71 100644 (file)
@@ -30,7 +30,6 @@ AC_DEFUN([AX_SASL_OPTION],[
 
     AS_IF([test "x$ac_enable_sasl" = "xyes"], [
       ac_enable_sasl="no"
-      ], [
       ])
 
     AS_IF([test "x$ac_enable_sasl" = "xyes"], [
index e1ef743393f95d1b1ca764516132ab8f3d9952a6..f3338131d6e0cfc01f2aa710707a9f49e502496e 100644 (file)
@@ -76,7 +76,7 @@ AC_DEFUN([PANDORA_WARNINGS],[
         
     AS_IF([test "$ac_cv_warnings_as_errors" = "yes"],[
       W_FAIL="-Werror"
-      SPHINX_WARNINGS="-W"
+      SPHINX_WARNINGS="-W -n"
       INTLTOOL_WARNINGS="yes"
     ])
 
index 689c5c52f08f0d9d83237413491f02c489b2beeb..b42d394f608bf85ac7a2f25db2427bd322971bc6 100644 (file)
@@ -86,67 +86,17 @@ tests_memdump_LDADD=  libtest/libtest.la $(TESTS_LDADDS)
 check_PROGRAMS+= tests/memdump
 noinst_PROGRAMS+= tests/memdump
 
-test-memerror: clients/memerror
+test-memstat: tests/memstat
+       tests/memstat
+
+test-memerror: tests/memerror
        tests/memerror
 
-valgrind-memerror: clients/memerror
-        @$(VALGRIND_COMMAND) tests/memerror
+test-memtouch: tests/memtouch
+       tests/memtouch
 
-test-memcp: clients/memcp
-       @echo "Testing memcp"
-       @@MEMC_BINARY@ -d -u root -P `pwd`/tests/Xumemc.pid -p 12555
-       @clients/memcp --servers="localhost:12555" clients/memcp clients/memcat clients/memstat
-       @cat tests/Xumemc.pid | xargs kill || echo "Failed to kill memcached server"
-       @rm tests/Xumemc.pid
-
-valgrind-memcp: clients/memcat clients/memcp
-       @echo "Testing memcp"
-       @@MEMC_BINARY@ -d -u root -P `pwd`/tests/Xumemc.pid -p 12555
-       @$(VALGRIND_COMMAND) clients/memcp --servers="localhost:12555" clients/memcp clients/memcat clients/memstat
-       @cat tests/Xumemc.pid | xargs kill || echo "Failed to kill memcached server"
-       @rm tests/Xumemc.pid
-
-test-memflush: clients/memflush
-       @echo "Testing memflush"
-       @$(MEMC_BINARY) -d -u root -P `pwd`/tests/Xumemc.pid -p 12555
-       @clients/memflush --servers="localhost:12555"
-       @cat tests/Xumemc.pid | xargs kill || echo "Failed to kill memcached server"
-       @rm tests/Xumemc.pid
-
-valgrind-memflush: clients/memflush
-       @echo "Testing memflush"
-       @$(MEMC_BINARY) -d -u root -P `pwd`/tests/Xumemc.pid -p 12555
-       @$(VALGRIND_COMMAND) clients/memflush --servers="localhost:12555"
-       @cat tests/Xumemc.pid | xargs kill || echo "Failed to kill memcached server"
-       @rm tests/Xumemc.pid
-
-test-memdump: clients/memdump clients/memcp
-       @echo "Testing memdump"
-       @$(MEMC_BINARY) -d -u root -P `pwd`/tests/Xumemc.pid -p 12555
-       @clients/memcp --servers="localhost:12555" clients/memcat
-       @clients/memdump --servers="localhost:12555" > /dev/null
-       @cat tests/Xumemc.pid | xargs kill || echo "Failed to kill memcached server"
-       @rm tests/Xumemc.pid
-
-valgrind-memdump: clients/memcat clients/memcp
-       @echo "Testing memdump"
-       @$(MEMC_BINARY) -d -u root -P `pwd`/tests/Xumemc.pid -p 12555
-       @clients/memcp --servers="localhost:12555" clients/memcat
-       @$(VALGRIND_COMMAND) clients/memdump --servers="localhost:12555" > /dev/null
-       @cat tests/Xumemc.pid | xargs kill || echo "Failed to kill memcached server"
-       @rm tests/Xumemc.pid
-
-test-memstat: clients/memstat
-       @echo "Testing memstat"
-       @$(MEMC_BINARY) -d -u root -P `pwd`/tests/Xumemc.pid -p 12555
-       @clients/memstat --servers="localhost:12555" > /dev/null
-       @cat tests/Xumemc.pid | xargs kill || echo "Failed to kill memcached server"
-       @rm tests/Xumemc.pid
-
-valgrind-memstat: clients/memstat
-       @echo "Testing memstat"
-       @$(MEMC_BINARY) -d -u root -P `pwd`/tests/Xumemc.pid -p 12555
-       @$(VALGRIND_COMMAND) clients/memstat --servers="localhost:12555" > /dev/null
-       @cat tests/Xumemc.pid | xargs kill || echo "Failed to kill memcached server"
-       @rm tests/Xumemc.pid
+valgrind-memerror: tests/memerror
+        @$(VALGRIND_COMMAND) tests/memerror
 
+valgrind-memtouch: tests/memtouch
+        @$(VALGRIND_COMMAND) tests/memtouch
index 908ad9605cc247ddc75f302654875b6fed3cd9f9..e13a854b794435c881d92d7ee26876ad983403cb 100644 (file)
@@ -40,7 +40,6 @@
 
 using namespace libtest;
 
-#include <cassert>
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
index 41ea2ec33332f7cdcb6abf67a1f40e46316f6e55..7bc9e60b99dcddf2f338ada4accedcb3759239f4 100644 (file)
@@ -67,9 +67,6 @@ test: check
 check-local: $(TEST_DOCS)
        @echo "Tests completed"
 
-test-x: test-plus test-memcp test-memdump test-memflush test-memstat
-       @echo "Tests completed"
-
 test-mem: tests/var tests/libmemcached-1.0/testapp
        @tests/libmemcached-1.0/testapp
 
index 7fae6d31311bce55c6f4b5e7f34460ca88b4367d..b8f93fb562b039b339a331695d9510502f58f603 100644 (file)
@@ -73,7 +73,7 @@ void get_world(Framework *world)
   if (getenv("LIBMEMCACHED_SERVER_NUMBER"))
   {
     int set_count= atoi(getenv("LIBMEMCACHED_SERVER_NUMBER"));
-    assert(set_count >= 0);
+    fatal_assert(set_count >= 0);
     world->servers().set_count(set_count);
   }
   else
index 47db429d85e2b09112debd455d7d6d91d381ea92..c54a5071047d4b8ac7827c4260dede7b7e96c751 100644 (file)
@@ -37,6 +37,8 @@
 
 #pragma once
 
+#include <tests/libmemcached-1.0/memcached_get.h>
+
 
 /* Clean the server before beginning testing */
 test_st tests[] ={
index 206e60924db5358775fa5445f3136acb94115475..72b2f974a508d106ca082c2ef5a2fb099c065d2f 100644 (file)
@@ -50,8 +50,8 @@ static memcached_return_t delete_trigger(memcached_st *,
                                          const char *key,
                                          size_t key_length)
 {
-  assert(key);
-  assert(key_length);
+  fatal_assert(key);
+  fatal_assert(key_length);
 
   return MEMCACHED_SUCCESS;
 }
index e98faf406678464af49e6a0a80e4b4ebee5d82e6..d7ebdb0543371d2934b2ffabe1932abeb7e7a790 100644 (file)
@@ -38,8 +38,6 @@
 #include <config.h>
 #include <libtest/test.hpp>
 
-#include <cassert>
-
 #include <libmemcached/memcached.h>
 #include <tests/deprecated.h>
 
@@ -68,7 +66,7 @@ test_return_t server_list_null_test(memcached_st *ptr)
 test_return_t regression_bug_728286(memcached_st *)
 {
   memcached_server_st *servers= memcached_servers_parse("1.2.3.4:99");
-  assert(servers);
+  fatal_assert(servers);
   memcached_server_free(servers);
 
   return TEST_SUCCESS;
index 48a03695468003e5b58ddb85a3226144cd987111..a320a9a511cae0111e77167d31cb4e5ce26f1ad6 100644 (file)
@@ -25,6 +25,7 @@ noinst_HEADERS+= \
                 tests/libmemcached-1.0/generate.h \
                 tests/libmemcached-1.0/haldenbrand.h \
                 tests/libmemcached-1.0/mem_functions.h \
+                tests/libmemcached-1.0/memcached_get.h \
                 tests/libmemcached-1.0/setup_and_teardowns.h \
                 tests/libmemcached-1.0/stat.h \
                 tests/namespace.h \
@@ -67,6 +68,7 @@ tests_libmemcached_1_0_testapp_SOURCES= \
                                        tests/libmemcached-1.0/haldenbrand.cc \
                                        tests/libmemcached-1.0/ketama.cc \
                                        tests/libmemcached-1.0/mem_functions.cc \
+                                       tests/libmemcached-1.0/memcached_get.cc \
                                        tests/libmemcached-1.0/namespace.cc \
                                        tests/libmemcached-1.0/parser.cc \
                                        tests/libmemcached-1.0/pool.cc \
@@ -113,6 +115,7 @@ tests_libmemcached_1_0_testsocket_SOURCES= \
                                           tests/libmemcached-1.0/haldenbrand.cc \
                                           tests/libmemcached-1.0/ketama.cc \
                                           tests/libmemcached-1.0/mem_functions.cc \
+                                          tests/libmemcached-1.0/memcached_get.cc \
                                           tests/libmemcached-1.0/namespace.cc \
                                           tests/libmemcached-1.0/parser.cc \
                                           tests/libmemcached-1.0/pool.cc \
index d44b5561262be58e5dfc83b52a130b7f208b2b49..8a1951e66ac62cd47ed4377935b03c710632e1d4 100644 (file)
@@ -52,7 +52,6 @@
 
 #include <libhashkit-1.0/hashkit.h>
 
-#include <cassert>
 #include <cerrno>
 #include <memory>
 #include <pthread.h>
@@ -193,16 +192,6 @@ private:
     std::vector<size_t> _lengths;
 };
 
-static memcached_return_t return_value_based_on_buffering(memcached_st *memc)
-{
-  if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS))
-  {
-    return MEMCACHED_BUFFERED;
-  }
-
-  return MEMCACHED_SUCCESS;
-}
-
 static memcached_st * create_single_instance_memcached(const memcached_st *original_memc, const char *options)
 {
   /*
@@ -290,7 +279,7 @@ static memcached_return_t server_display_function(const memcached_st *ptr,
   /* Do Nothing */
   size_t bigger= *((size_t *)(context));
   (void)ptr;
-  assert(bigger <= memcached_server_port(server));
+  fatal_assert(bigger <= memcached_server_port(server));
   *((size_t *)(context))= memcached_server_port(server);
 
   return MEMCACHED_SUCCESS;
@@ -1186,62 +1175,6 @@ test_return_t read_through(memcached_st *memc)
   return TEST_SUCCESS;
 }
 
-test_return_t get_test(memcached_st *memc)
-{
-  uint64_t query_id= memcached_query_id(memc);
-  memcached_return_t rc= memcached_delete(memc,
-                                          test_literal_param(__func__),
-                                          time_t(0));
-  test_true_hint(rc == MEMCACHED_BUFFERED or rc == MEMCACHED_NOTFOUND, memcached_last_error_message(memc));
-  test_compare(query_id +1, memcached_query_id(memc));
-
-  size_t string_length;
-  uint32_t flags;
-  char *string= memcached_get(memc,
-                        test_literal_param(__func__),
-                        &string_length, &flags, &rc);
-
-  test_compare_got(MEMCACHED_NOTFOUND, rc, memcached_last_error_message(memc));
-  test_false(string_length);
-  test_false(string);
-
-  return TEST_SUCCESS;
-}
-
-test_return_t get_test2(memcached_st *memc)
-{
-  const char *value= "when we sanitize";
-
-  uint64_t query_id= memcached_query_id(memc);
-  test_compare(return_value_based_on_buffering(memc),
-               memcached_set(memc,
-                             test_literal_param(__func__),
-                             value, strlen(value),
-                             time_t(0), uint32_t(0)));
-  test_compare(query_id +1, memcached_query_id(memc));
-
-  query_id= memcached_query_id(memc);
-  test_true(query_id);
-
-  uint32_t flags;
-  size_t string_length;
-  memcached_return_t rc;
-  char *string= memcached_get(memc,
-                              test_literal_param(__func__),
-                              &string_length, &flags, &rc);
-  test_compare(query_id +1, memcached_query_id(memc));
-
-  test_compare_got(MEMCACHED_SUCCESS, rc, memcached_strerror(NULL, rc));
-  test_compare_got(MEMCACHED_SUCCESS, memcached_last_error(memc), memcached_last_error_message(memc));
-  test_true(string);
-  test_compare(strlen(value), string_length);
-  test_memcmp(string, value, string_length);
-
-  free(string);
-
-  return TEST_SUCCESS;
-}
-
 test_return_t set_test2(memcached_st *memc)
 {
   for (uint32_t x= 0; x < 10; x++)
@@ -1286,126 +1219,6 @@ test_return_t set_test3(memcached_st *memc)
   return TEST_SUCCESS;
 }
 
-test_return_t get_test3(memcached_st *memc)
-{
-  size_t value_length= 8191;
-
-  libtest::vchar_t value;
-  value.reserve(value_length);
-  for (uint32_t x= 0; x < value_length; x++)
-  {
-    value.push_back(char(x % 127));
-  }
-
-  test_compare_hint(return_value_based_on_buffering(memc),
-                    memcached_set(memc,
-                                  test_literal_param(__func__),
-                                  &value[0], value.size(),
-                                  time_t(0), uint32_t(0)),
-                    memcached_last_error_message(memc));
-
-  size_t string_length;
-  uint32_t flags;
-  memcached_return_t rc;
-  char *string= memcached_get(memc,
-                              test_literal_param(__func__),
-                              &string_length, &flags, &rc);
-
-  test_compare(MEMCACHED_SUCCESS, rc);
-  test_true(string);
-  test_compare(value.size(), string_length);
-  test_memcmp(string, &value[0], string_length);
-
-  free(string);
-
-  return TEST_SUCCESS;
-}
-
-test_return_t get_test4(memcached_st *memc)
-{
-  size_t value_length= 8191;
-
-  libtest::vchar_t value;
-  value.reserve(value_length);
-  for (uint32_t x= 0; x < value_length; x++)
-  {
-    value.push_back(char(x % 127));
-  }
-
-  test_compare_hint(return_value_based_on_buffering(memc),
-                    memcached_set(memc,
-                                  test_literal_param(__func__),
-                                  &value[0], value.size(),
-                                  time_t(0), uint32_t(0)),
-                    memcached_last_error_message(memc));
-
-  for (uint32_t x= 0; x < 10; x++)
-  {
-    uint32_t flags;
-    size_t string_length;
-    memcached_return_t rc;
-    char *string= memcached_get(memc,
-                                test_literal_param(__func__),
-                                &string_length, &flags, &rc);
-
-    test_compare(MEMCACHED_SUCCESS, rc);
-    test_true(string);
-    test_compare(value.size(), string_length);
-    test_memcmp(string, &value[0], string_length);
-    free(string);
-  }
-
-  return TEST_SUCCESS;
-}
-
-/*
- * This test verifies that memcached_read_one_response doesn't try to
- * dereference a NIL-pointer if you issue a multi-get and don't read out all
- * responses before you execute a storage command.
- */
-test_return_t get_test5(memcached_st *memc)
-{
-  /*
-  ** Request the same key twice, to ensure that we hash to the same server
-  ** (so that we have multiple response values queued up) ;-)
-  */
-  const char *keys[]= { "key", "key" };
-  size_t lengths[]= { 3, 3 };
-  uint32_t flags;
-  size_t rlen;
-
-  test_compare_hint(return_value_based_on_buffering(memc),
-                    memcached_set(memc, keys[0], lengths[0],
-                                  keys[0], lengths[0],
-                                  time_t(0), uint32_t(0)),
-                    memcached_last_error_message(memc));
-  test_compare(MEMCACHED_SUCCESS, memcached_mget(memc, keys, lengths, test_array_length(keys)));
-
-  memcached_result_st results_obj;
-  memcached_result_st *results= memcached_result_create(memc, &results_obj);
-  test_true(results);
-
-  memcached_return_t rc;
-  results= memcached_fetch_result(memc, &results_obj, &rc);
-  test_true(results);
-
-  memcached_result_free(&results_obj);
-
-  /* Don't read out the second result, but issue a set instead.. */
-  test_compare(MEMCACHED_SUCCESS, memcached_set(memc, keys[0], lengths[0], keys[0], lengths[0], 0, 0));
-
-  char *val= memcached_get_by_key(memc, keys[0], lengths[0], "yek", 3,
-                                  &rlen, &flags, &rc);
-  test_false(val);
-  test_compare(MEMCACHED_NOTFOUND, rc);
-  val= memcached_get(memc, keys[0], lengths[0], &rlen, &flags, &rc);
-  test_true(val);
-  test_compare(MEMCACHED_SUCCESS, rc);
-  free(val);
-
-  return TEST_SUCCESS;
-}
-
 test_return_t mget_end(memcached_st *memc)
 {
   const char *keys[]= { "foo", "foo2" };
@@ -2884,7 +2697,7 @@ test_return_t user_supplied_bug20(memcached_st *memc)
 /* sighandler_t function that always asserts false */
 static void fail(int)
 {
-  assert(0);
+  fatal_assert(0);
 }
 
 
index 7126f7fcb4b4ed9d36286ffa46d2b4fa7ec33480..d632dd4bb1d1ce88ce70675fa1d5322503333b48 100644 (file)
@@ -78,11 +78,6 @@ test_return_t fnv1a_32_run (memcached_st *);
 test_return_t fnv1a_64_run (memcached_st *);
 test_return_t get_stats(memcached_st *memc);
 test_return_t get_stats_keys(memcached_st *memc);
-test_return_t get_test(memcached_st *memc);
-test_return_t get_test2(memcached_st *memc);
-test_return_t get_test3(memcached_st *memc);
-test_return_t get_test4(memcached_st *memc);
-test_return_t get_test5(memcached_st *memc);
 test_return_t getpid_connection_failure_test(memcached_st *memc);
 test_return_t getpid_test(memcached_st *memc);
 test_return_t hash_sanity_test (memcached_st *memc);
diff --git a/tests/libmemcached-1.0/memcached_get.cc b/tests/libmemcached-1.0/memcached_get.cc
new file mode 100644 (file)
index 0000000..2636ecd
--- /dev/null
@@ -0,0 +1,222 @@
+/*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ * 
+ *  Libmemcached library
+ *
+ *  Copyright (C) 2012 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.
+ *
+ */
+
+#include <config.h>
+#include <libtest/test.hpp>
+
+/*
+  Test cases
+*/
+
+#include <libmemcached-1.0/memcached.h>
+#include "tests/libmemcached-1.0/memcached_get.h"
+#include "tests/libmemcached-1.0/setup_and_teardowns.h"
+
+test_return_t get_test(memcached_st *memc)
+{
+  uint64_t query_id= memcached_query_id(memc);
+  memcached_return_t rc= memcached_delete(memc,
+                                          test_literal_param(__func__),
+                                          time_t(0));
+  test_true_hint(rc == MEMCACHED_BUFFERED or rc == MEMCACHED_NOTFOUND, memcached_last_error_message(memc));
+  test_compare(query_id +1, memcached_query_id(memc));
+
+  size_t string_length;
+  uint32_t flags;
+  char *string= memcached_get(memc,
+                        test_literal_param(__func__),
+                        &string_length, &flags, &rc);
+
+  test_compare_got(MEMCACHED_NOTFOUND, rc, memcached_last_error_message(memc));
+  test_false(string_length);
+  test_false(string);
+
+  return TEST_SUCCESS;
+}
+
+test_return_t get_test2(memcached_st *memc)
+{
+  const char *value= "when we sanitize";
+
+  uint64_t query_id= memcached_query_id(memc);
+  test_compare(return_value_based_on_buffering(memc),
+               memcached_set(memc,
+                             test_literal_param(__func__),
+                             value, strlen(value),
+                             time_t(0), uint32_t(0)));
+  test_compare(query_id +1, memcached_query_id(memc));
+
+  query_id= memcached_query_id(memc);
+  test_true(query_id);
+
+  uint32_t flags;
+  size_t string_length;
+  memcached_return_t rc;
+  char *string= memcached_get(memc,
+                              test_literal_param(__func__),
+                              &string_length, &flags, &rc);
+  test_compare(query_id +1, memcached_query_id(memc));
+
+  test_compare_got(MEMCACHED_SUCCESS, rc, memcached_strerror(NULL, rc));
+  test_compare_got(MEMCACHED_SUCCESS, memcached_last_error(memc), memcached_last_error_message(memc));
+  test_true(string);
+  test_compare(strlen(value), string_length);
+  test_memcmp(string, value, string_length);
+
+  free(string);
+
+  return TEST_SUCCESS;
+}
+
+test_return_t get_test3(memcached_st *memc)
+{
+  size_t value_length= 8191;
+
+  libtest::vchar_t value;
+  value.reserve(value_length);
+  for (uint32_t x= 0; x < value_length; x++)
+  {
+    value.push_back(char(x % 127));
+  }
+
+  test_compare_hint(return_value_based_on_buffering(memc),
+                    memcached_set(memc,
+                                  test_literal_param(__func__),
+                                  &value[0], value.size(),
+                                  time_t(0), uint32_t(0)),
+                    memcached_last_error_message(memc));
+
+  size_t string_length;
+  uint32_t flags;
+  memcached_return_t rc;
+  char *string= memcached_get(memc,
+                              test_literal_param(__func__),
+                              &string_length, &flags, &rc);
+
+  test_compare(MEMCACHED_SUCCESS, rc);
+  test_true(string);
+  test_compare(value.size(), string_length);
+  test_memcmp(string, &value[0], string_length);
+
+  free(string);
+
+  return TEST_SUCCESS;
+}
+
+test_return_t get_test4(memcached_st *memc)
+{
+  size_t value_length= 8191;
+
+  libtest::vchar_t value;
+  value.reserve(value_length);
+  for (uint32_t x= 0; x < value_length; x++)
+  {
+    value.push_back(char(x % 127));
+  }
+
+  test_compare_hint(return_value_based_on_buffering(memc),
+                    memcached_set(memc,
+                                  test_literal_param(__func__),
+                                  &value[0], value.size(),
+                                  time_t(0), uint32_t(0)),
+                    memcached_last_error_message(memc));
+
+  for (uint32_t x= 0; x < 10; x++)
+  {
+    uint32_t flags;
+    size_t string_length;
+    memcached_return_t rc;
+    char *string= memcached_get(memc,
+                                test_literal_param(__func__),
+                                &string_length, &flags, &rc);
+
+    test_compare(MEMCACHED_SUCCESS, rc);
+    test_true(string);
+    test_compare(value.size(), string_length);
+    test_memcmp(string, &value[0], string_length);
+    free(string);
+  }
+
+  return TEST_SUCCESS;
+}
+
+/*
+ * This test verifies that memcached_read_one_response doesn't try to
+ * dereference a NIL-pointer if you issue a multi-get and don't read out all
+ * responses before you execute a storage command.
+ */
+test_return_t get_test5(memcached_st *memc)
+{
+  /*
+  ** Request the same key twice, to ensure that we hash to the same server
+  ** (so that we have multiple response values queued up) ;-)
+  */
+  const char *keys[]= { "key", "key" };
+  size_t lengths[]= { 3, 3 };
+  uint32_t flags;
+  size_t rlen;
+
+  test_compare_hint(return_value_based_on_buffering(memc),
+                    memcached_set(memc, keys[0], lengths[0],
+                                  keys[0], lengths[0],
+                                  time_t(0), uint32_t(0)),
+                    memcached_last_error_message(memc));
+  test_compare(MEMCACHED_SUCCESS, memcached_mget(memc, keys, lengths, test_array_length(keys)));
+
+  memcached_result_st results_obj;
+  memcached_result_st *results= memcached_result_create(memc, &results_obj);
+  test_true(results);
+
+  memcached_return_t rc;
+  results= memcached_fetch_result(memc, &results_obj, &rc);
+  test_true(results);
+
+  memcached_result_free(&results_obj);
+
+  /* Don't read out the second result, but issue a set instead.. */
+  test_compare(MEMCACHED_SUCCESS, memcached_set(memc, keys[0], lengths[0], keys[0], lengths[0], 0, 0));
+
+  char *val= memcached_get_by_key(memc, keys[0], lengths[0], "yek", 3,
+                                  &rlen, &flags, &rc);
+  test_false(val);
+  test_compare(MEMCACHED_NOTFOUND, rc);
+  val= memcached_get(memc, keys[0], lengths[0], &rlen, &flags, &rc);
+  test_true(val);
+  test_compare(MEMCACHED_SUCCESS, rc);
+  free(val);
+
+  return TEST_SUCCESS;
+}
diff --git a/tests/libmemcached-1.0/memcached_get.h b/tests/libmemcached-1.0/memcached_get.h
new file mode 100644 (file)
index 0000000..46e8def
--- /dev/null
@@ -0,0 +1,44 @@
+/*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ * 
+ *  Libmemcached library
+ *
+ *  Copyright (C) 2012 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.
+ *
+ */
+
+#pragma once
+
+test_return_t get_test(memcached_st*);
+test_return_t get_test2(memcached_st*);
+test_return_t get_test3(memcached_st*);
+test_return_t get_test4(memcached_st*);
+test_return_t get_test5(memcached_st*);
+
index 03da195a5c7afab2022bebce15c40362610b8feb..b8b4f47af080f237b75e31ae4c720396d62fbc5c 100644 (file)
@@ -43,7 +43,6 @@ using namespace libtest;
 #include <vector>
 #include <string>
 #include <cerrno>
-#include <cassert>
 
 #include <libmemcached/memcached.h>
 #include <libmemcached/util.h>
@@ -621,19 +620,19 @@ static memcached_return_t dump_server_information(const memcached_st *,
 {
   if (strcmp(memcached_server_name(instance), "localhost")) 
   {
-    assert(not memcached_server_name(instance));
+    fatal_assert(not memcached_server_name(instance));
     return MEMCACHED_FAILURE;
   }
 
   if (memcached_server_port(instance) < 8888 or memcached_server_port(instance) > 8892)
   {
-    assert(not memcached_server_port(instance));
+    fatal_assert(not memcached_server_port(instance));
     return MEMCACHED_FAILURE;
   }
 
   if (instance->weight > 5 or instance->weight < 2)
   {
-    assert(not instance->weight);
+    fatal_assert(not instance->weight);
     return MEMCACHED_FAILURE;
   }
 
index f6214e0d3b5b5f103de029d2d9f35d9bc7b2b1bf..5b22c94ec8394643ffa87b08c0e3365547442d88 100644 (file)
@@ -238,10 +238,9 @@ struct test_pool_context_st {
 static void* connection_release(void *arg)
 {
   test_pool_context_st *resource= static_cast<test_pool_context_st *>(arg);
-  assert(resource);
   if (resource == NULL)
   {
-    abort();
+    fatal_message("resource == NULL");
   }
 
   // Release all of the memc we are holding 
index 84f57abe2cc85b0c44218fe5d3353a314a4df8e1..9bf0e92a838fca9cbab14ac07fed51d20c322955 100644 (file)
 
 #include <sys/stat.h>
 
+
+memcached_return_t return_value_based_on_buffering(memcached_st *memc)
+{
+  if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS))
+  {
+    return MEMCACHED_BUFFERED;
+  }
+
+  return MEMCACHED_SUCCESS;
+}
+
 /**
   @note This should be testing to see if the server really supports the binary protocol.
 */
index e141685fff5e19be6a86c58a24867226c54af783..fa6fbdf2860fb8ad68c026cb673713f8f148339c 100644 (file)
@@ -37,6 +37,8 @@
 
 #pragma once
 
+memcached_return_t return_value_based_on_buffering(memcached_st*);
+
 test_return_t pre_behavior_ketama(memcached_st*);
 test_return_t pre_behavior_ketama_weighted(memcached_st*);
 test_return_t pre_binary(memcached_st*);
index 0d3b57dff1a24b1a5006ebe5fe33c59dd013aece..181379868be7b48abe6d34b93df7499219040002 100644 (file)
@@ -39,8 +39,6 @@
 
 #pragma once
 
-#include <cassert>
-
 /* The structure we use for the test system */
 struct libmemcached_test_container_st
 {
@@ -78,47 +76,25 @@ static void *world_create(libtest::server_startup_st& servers, test_return_t& er
 
   for (uint32_t x= 0; x < servers.count(); x++)
   {
-    char variable_buffer[1024];
-    snprintf(variable_buffer, sizeof(variable_buffer), "LIBMEMCACHED_PORT_%u", x);
+    in_port_t port= libtest::get_free_port();
 
-    in_port_t port;
-    char *var;
-    if ((var= getenv(variable_buffer)))
-    {
-      port= in_port_t(atoi(var));
-    }
-    else
-    {
-      port= in_port_t(libtest::get_free_port());
-    }
-
-    const char *argv[1]= { "memcached" };
     if (servers.sasl())
     {
-      if (not server_startup(servers, "memcached-sasl", port, 1, argv))
+      if (server_startup(servers, "memcached-sasl", port, 0, NULL) == false)
       {
-        error= TEST_FATAL;
-        return NULL;
+        fatal_message("Could not start memcached-sasl");
       }
     }
     else
     {
-      if (not server_startup(servers, "memcached", port, 1, argv))
+      if (server_startup(servers, "memcached", port, 0, NULL) == false)
       {
-        error= TEST_FATAL;
-        return NULL;
+        fatal_message("Could not start memcached");
       }
     }
   }
 
   libmemcached_test_container_st *global_container= new libmemcached_test_container_st(servers);
-  if (global_container == NULL)
-  {
-    error= TEST_MEMORY_ALLOCATION_FAILURE;
-    return NULL;
-  }
-
-  error= TEST_SUCCESS;
 
   return global_container;
 }
index 3e410084de3844340bcdc3eafe20490d79aa158e..d867ef88ef9c6a3f553890cd63442ba120627764 100644 (file)
@@ -68,18 +68,12 @@ static void *world_create(libtest::server_startup_st& servers, test_return_t& er
     const char *argv[1]= { "memcached" };
     if (not servers.start_socket_server("memcached", libtest::get_free_port(), 1, argv))
     {
-      error= TEST_FATAL;
-      return NULL;
+      fatal_message("Could not launch memcached");
     }
   }
 
 
   libmemcached_test_container_st *global_container= new libmemcached_test_container_st(servers);
-  if (global_container == NULL)
-  {
-    error= TEST_MEMORY_ALLOCATION_FAILURE;
-    return NULL;
-  }
 
   error= TEST_SUCCESS;
 
index ff631921351b3ad4e65885b95848ef99fa2a3965..713885fda2e39a3f714d765c5d67dddc77d6a08f 100644 (file)
@@ -51,7 +51,6 @@ using namespace libtest;
 #include <libmemcached/udp.hpp>
 #include <libmemcachedutil-1.0/util.h>
 
-#include <cassert>
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
index 75b93995e6e99214998d9d2b73f3fb1fbe51adc3..ae50fefaf95c212d972146c06943d51f31bc6225 100644 (file)
@@ -113,8 +113,7 @@ static void *world_create(server_startup_st& servers, test_return_t& error)
     return NULL;
   }
 
-  const char *argv[1]= { "memcapable" };
-  if (not server_startup(servers, "memcached", libtest::default_port(), 1, argv))
+  if (server_startup(servers, "memcached", libtest::default_port(), 0, NULL) == false)
   {
     error= TEST_FAILURE;
   }
index 23d59325d03bb82b5f36c93be65a3504e00eb97d..e51cdce1451e235e944b626a97cc269cd9d8dc0e 100644 (file)
@@ -50,16 +50,7 @@ using namespace libtest;
 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
 #endif
 
-static std::string executable;
-
-static test_return_t quiet_test(void *)
-{
-  const char *args[]= { "--quiet", 0 };
-
-  test_compare(EXIT_FAILURE, exec_cmdline(executable, args, true));
-
-  return TEST_SUCCESS;
-}
+static std::string executable("clients/memcat");
 
 static test_return_t help_test(void *)
 {
@@ -122,7 +113,6 @@ static test_return_t NOT_FOUND_test(void *)
 }
 
 test_st memcat_tests[] ={
-  {"--quiet", true, quiet_test },
   {"--help", true, help_test },
   {"cat(FOUND)", true, cat_test },
   {"cat(NOT_FOUND)", true, NOT_FOUND_test },
@@ -142,8 +132,7 @@ static void *world_create(server_startup_st& servers, test_return_t& error)
     return NULL;
   }
 
-  const char *argv[1]= { "memcat" };
-  if (not server_startup(servers, "memcached", libtest::default_port(), 1, argv))
+  if (not server_startup(servers, "memcached", libtest::default_port(), 0, NULL))
   {
     error= TEST_FAILURE;
   }
@@ -154,7 +143,6 @@ static void *world_create(server_startup_st& servers, test_return_t& error)
 
 void get_world(Framework *world)
 {
-  executable= "clients/memcat";
   world->collections= collection;
   world->_create= world_create;
 }
index 99f3e02df652d321f3d1164dcc8a9d14931e2537..eab8cfa58a7d946d9b0d9c229404300a89e0cbed 100644 (file)
@@ -50,16 +50,7 @@ using namespace libtest;
 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
 #endif
 
-static std::string executable;
-
-static test_return_t quiet_test(void *)
-{
-  const char *args[]= { "--quiet", 0 };
-
-  test_compare(EXIT_FAILURE, exec_cmdline(executable, args, true));
-
-  return TEST_SUCCESS;
-}
+static std::string executable("./clients/memcp");
 
 static test_return_t help_test(void *)
 {
@@ -82,7 +73,6 @@ static test_return_t server_test(void *)
 }
 
 test_st memcp_tests[] ={
-  {"--quiet", true, quiet_test },
   {"--help", true, help_test },
   {"--server_test", true, server_test },
   {0, 0, 0}
@@ -101,8 +91,7 @@ static void *world_create(server_startup_st& servers, test_return_t& error)
     return NULL;
   }
 
-  const char *argv[1]= { "memcp" };
-  if (not server_startup(servers, "memcached", libtest::default_port(), 1, argv))
+  if (server_startup(servers, "memcached", libtest::default_port(), 0, NULL) == false)
   {
     error= TEST_FAILURE;
   }
@@ -113,7 +102,6 @@ static void *world_create(server_startup_st& servers, test_return_t& error)
 
 void get_world(Framework *world)
 {
-  executable= "./clients/memcp";
   world->collections= collection;
   world->_create= world_create;
 }
index c1ff194000d2430c904dfe1df3d21d00a79b0204..4a30892138cbf7f3dade30185672ccedffeb7918 100644 (file)
@@ -50,16 +50,7 @@ using namespace libtest;
 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
 #endif
 
-static std::string executable;
-
-static test_return_t quiet_test(void *)
-{
-  const char *args[]= { "--quiet", 0 };
-
-  test_compare(EXIT_FAILURE, exec_cmdline(executable, args, true));
-
-  return TEST_SUCCESS;
-}
+static std::string executable("./clients/memdump");
 
 static test_return_t help_test(void *)
 {
@@ -108,7 +99,6 @@ static test_return_t FOUND_test(void *)
 }
 
 test_st memdump_tests[] ={
-  {"--quiet", true, quiet_test },
   {"--help", true, help_test },
   {"--server", true, server_test },
   {"FOUND", true, FOUND_test },
@@ -128,8 +118,7 @@ static void *world_create(server_startup_st& servers, test_return_t& error)
     return NULL;
   }
 
-  const char *argv[1]= { "memdump" };
-  if (not server_startup(servers, "memcached", libtest::default_port(), 1, argv))
+  if (server_startup(servers, "memcached", libtest::default_port(), 0, NULL) == false)
   {
     error= TEST_FAILURE;
   }
@@ -140,7 +129,6 @@ static void *world_create(server_startup_st& servers, test_return_t& error)
 
 void get_world(Framework *world)
 {
-  executable= "./clients/memdump";
   world->collections= collection;
   world->_create= world_create;
 }
index 00863475838620c3d9639029062737b566ebacb0..914d2a03b4df6ced19d0196503023c68579e161f 100644 (file)
@@ -50,7 +50,7 @@ using namespace libtest;
 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
 #endif
 
-static std::string executable;
+static std::string executable("./clients/memerror");
 
 static test_return_t help_TEST(void *)
 {
@@ -119,7 +119,6 @@ static void *world_create(server_startup_st&, test_return_t&)
 
 void get_world(Framework *world)
 {
-  executable= "./clients/memerror";
   world->collections= collection;
   world->_create= world_create;
 }
index ed2546d31f21c8adbfe3b7c11bb8482b6b6e3dc9..29ad50912ce64983599a94d63aa6d82b7fba6309 100644 (file)
@@ -43,6 +43,7 @@
 
 #include <libtest/test.hpp>
 #include <libmemcached/memcached.h>
+#include <libmemcached/util.h>
 
 using namespace libtest;
 
@@ -50,21 +51,13 @@ using namespace libtest;
 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
 #endif
 
-static std::string executable;
-
-static test_return_t quiet_test(void *)
-{
-  const char *args[]= { "--quiet", 0 };
-
-  test_true(exec_cmdline(executable, args));
-  return TEST_SUCCESS;
-}
+static std::string executable("./clients/memexist");
 
 static test_return_t help_test(void *)
 {
-  const char *args[]= { "--quiet", "--help", 0 };
+  const char *args[]= { "--help", 0 };
 
-  test_true(exec_cmdline(executable, args));
+  test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true));
   return TEST_SUCCESS;
 }
 
@@ -72,7 +65,7 @@ static test_return_t exist_test(void *)
 {
   char buffer[1024];
   snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port()));
-  const char *args[]= { "--quiet", buffer, "foo", 0 };
+  const char *args[]= { buffer, "foo", 0 };
 
   memcached_st *memc= memcached(buffer, strlen(buffer));
   test_true(memc);
@@ -84,7 +77,7 @@ static test_return_t exist_test(void *)
   test_null(memcached_get(memc, test_literal_param("foo"), 0, 0, &rc));
   test_compare(MEMCACHED_SUCCESS, rc);
 
-  test_true(exec_cmdline(executable, args));
+  test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true));
 
   test_null(memcached_get(memc, test_literal_param("foo"), 0, 0, &rc));
   test_compare(MEMCACHED_SUCCESS, rc);
@@ -98,7 +91,7 @@ static test_return_t NOT_FOUND_test(void *)
 {
   char buffer[1024];
   snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port()));
-  const char *args[]= { "--quiet", buffer, "foo", 0 };
+  const char *args[]= { buffer, "foo", 0 };
 
   memcached_st *memc= memcached(buffer, strlen(buffer));
   test_true(memc);
@@ -109,7 +102,7 @@ static test_return_t NOT_FOUND_test(void *)
   test_null(memcached_get(memc, test_literal_param("foo"), 0, 0, &rc));
   test_compare(MEMCACHED_NOTFOUND, rc);
 
-  test_true(exec_cmdline(executable, args));
+  test_compare(EXIT_FAILURE, exec_cmdline(executable, args, true));
 
   test_null(memcached_get(memc, test_literal_param("foo"), 0, 0, &rc));
   test_compare(MEMCACHED_NOTFOUND, rc);
@@ -119,8 +112,24 @@ static test_return_t NOT_FOUND_test(void *)
   return TEST_SUCCESS;
 }
 
+static test_return_t check_version(void*)
+{
+  char buffer[1024];
+  snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port()));
+  memcached_st *memc= memcached(buffer, strlen(buffer));
+  test_true(memc);
+  
+  test_return_t result= TEST_SUCCESS;
+  if (libmemcached_util_version_check(memc, 1, 4, 8) == false)
+  {
+    result= TEST_SKIPPED;
+  }
+  memcached_free(memc);
+
+  return result;
+}
+
 test_st memexist_tests[] ={
-  {"--quiet", true, quiet_test },
   {"--help", true, help_test },
   {"exist(FOUND)", true, exist_test },
   {"exist(NOT_FOUND)", true, NOT_FOUND_test },
@@ -128,7 +137,7 @@ test_st memexist_tests[] ={
 };
 
 collection_st collection[] ={
-  {"memexist", 0, 0, memexist_tests },
+  {"memexist", check_version, 0, memexist_tests },
   {0, 0, 0, 0}
 };
 
@@ -140,8 +149,7 @@ static void *world_create(server_startup_st& servers, test_return_t& error)
     return NULL;
   }
 
-  const char *argv[1]= { "memexist" };
-  if (not server_startup(servers, "memcached", libtest::default_port(), 1, argv))
+  if (server_startup(servers, "memcached", libtest::default_port(), 0, NULL) == false)
   {
     error= TEST_FAILURE;
   }
@@ -152,7 +160,6 @@ static void *world_create(server_startup_st& servers, test_return_t& error)
 
 void get_world(Framework *world)
 {
-  executable= "./clients/memexist";
   world->collections= collection;
   world->_create= world_create;
 }
index d1184722c64f4749e4ba0ab001f653d9f4e67247..f14b5b727d884f6171d44b89920fd8f4b0cf6abc 100644 (file)
@@ -101,8 +101,7 @@ static void *world_create(server_startup_st& servers, test_return_t& error)
     return NULL;
   }
 
-  const char *argv[1]= { "memflush" };
-  if (not server_startup(servers, "memcached", libtest::default_port(), 1, argv))
+  if (server_startup(servers, "memcached", libtest::default_port(), 0, NULL) == 0)
   {
     error= TEST_FAILURE;
   }
index 8ca4445e2a586b7b8e131184f39f6d6b25310b11..8d6109c0ac679084e66662df942d57ce4bd20929 100644 (file)
@@ -50,7 +50,7 @@ using namespace libtest;
 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
 #endif
 
-static std::string executable;
+static std::string executable("./clients/memrm");
 
 static test_return_t quiet_test(void *)
 {
@@ -95,7 +95,7 @@ static test_return_t rm_test(void *)
   return TEST_SUCCESS;
 }
 
-static test_return_t NOT_FOUND_test(void *)
+static test_return_t NOT_FOUND_TEST(void *)
 {
   char buffer[1024];
   snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port()));
@@ -118,11 +118,24 @@ static test_return_t NOT_FOUND_test(void *)
   return TEST_SUCCESS;
 }
 
+static test_return_t multiple_NOT_FOUND_TEST(void *)
+{
+  char buffer[1024];
+  snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port()));
+  const char *args[]= { buffer, "protocols", "foo", "mine", "bar", "dog", "cat", "foo", "mine",
+    "eye", "for", "the", "to", "not", "know", "what", "I", "should", "be", "doing", 0 };
+
+  test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true));
+
+  return TEST_SUCCESS;
+}
+
 test_st memrm_tests[] ={
   {"--quiet", true, quiet_test },
   {"--help", true, help_test },
   {"rm(FOUND)", true, rm_test },
-  {"rm(NOT_FOUND)", true, NOT_FOUND_test },
+  {"rm(NOT_FOUND)", true, NOT_FOUND_TEST },
+  {"multiple rm(NOT_FOUND)", true, multiple_NOT_FOUND_TEST },
   {0, 0, 0}
 };
 
@@ -139,8 +152,7 @@ static void *world_create(server_startup_st& servers, test_return_t& error)
     return NULL;
   }
 
-  const char *argv[1]= { "memrm" };
-  if (not server_startup(servers, "memcached", libtest::default_port(), 1, argv))
+  if (server_startup(servers, "memcached", libtest::default_port(), 0, NULL) == false)
   {
     error= TEST_FAILURE;
   }
@@ -151,7 +163,6 @@ static void *world_create(server_startup_st& servers, test_return_t& error)
 
 void get_world(Framework *world)
 {
-  executable= "./clients/memrm";
   world->collections= collection;
   world->_create= world_create;
 }
index 2ffb26bded821fbb126baa4f0bdbf0cba5ed01ca..ae8679fb13d47bc30fd8f63336e9b7cdd8ede2ee 100644 (file)
@@ -50,22 +50,13 @@ using namespace libtest;
 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
 #endif
 
-static std::string executable;
-
-static test_return_t quiet_test(void *)
-{
-  const char *args[]= { "--quiet", 0 };
-
-  test_true(exec_cmdline(executable, args));
-  return TEST_SUCCESS;
-}
-
+static std::string executable("./clients/memstat");
 
 static test_return_t help_test(void *)
 {
-  const char *args[]= { "--help", "--quiet", 0 };
+  const char *args[]= { "--help", 0 };
 
-  test_true(exec_cmdline(executable, args));
+  test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true));
 
   return TEST_SUCCESS;
 }
@@ -74,9 +65,9 @@ static test_return_t binary_TEST(void *)
 {
   char buffer[1024];
   snprintf(buffer, sizeof(buffer), "--servers=localhost:%d", int(libtest::default_port()));
-  const char *args[]= { "--quiet", buffer, " --binary ", 0 };
+  const char *args[]= { buffer, " --binary ", 0 };
 
-  test_true(exec_cmdline(executable, args));
+  test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true));
   return TEST_SUCCESS;
 }
 
@@ -84,9 +75,9 @@ static test_return_t server_version_TEST(void *)
 {
   char buffer[1024];
   snprintf(buffer, sizeof(buffer), "--servers=localhost:%d", int(libtest::default_port()));
-  const char *args[]= { "--quiet", buffer, " --server-version", 0 };
+  const char *args[]= { buffer, " --server-version", 0 };
 
-  test_true(exec_cmdline(executable, args));
+  test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true));
   return TEST_SUCCESS;
 }
 
@@ -94,14 +85,14 @@ static test_return_t binary_server_version_TEST(void *)
 {
   char buffer[1024];
   snprintf(buffer, sizeof(buffer), "--servers=localhost:%d", int(libtest::default_port()));
-  const char *args[]= { "--quiet", buffer, " --binary --server-version", 0 };
+  const char *args[]= { buffer, " --binary --server-version", 0 };
+
+  test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true));
 
-  test_true(exec_cmdline(executable, args));
   return TEST_SUCCESS;
 }
 
 test_st memstat_tests[] ={
-  {"--quiet", 0, quiet_test},
   {"--help", 0, help_test},
   {"--binary", 0, binary_TEST},
   {"--server-version", 0, server_version_TEST},
@@ -122,8 +113,7 @@ static void *world_create(server_startup_st& servers, test_return_t& error)
     return NULL;
   }
 
-  const char *argv[1]= { "memstat" };
-  if (server_startup(servers, "memcached", libtest::default_port(), 1, argv) == false)
+  if (server_startup(servers, "memcached", libtest::default_port(), 0, NULL) == false)
   {
     error= TEST_FAILURE;
   }
@@ -134,7 +124,6 @@ static void *world_create(server_startup_st& servers, test_return_t& error)
 
 void get_world(Framework *world)
 {
-  executable= "./clients/memstat";
   world->collections= collection;
   world->_create= world_create;
 }
index 6813eb8deefdce3554eec47c509398222c9cc7ea..fa65e8b413ff85c25437eb5efbc249cda6435fe2 100644 (file)
@@ -43,6 +43,7 @@
 
 #include <libtest/test.hpp>
 #include <libmemcached/memcached.h>
+#include <libmemcached/util.h>
 
 using namespace libtest;
 
@@ -52,19 +53,12 @@ using namespace libtest;
 
 static std::string executable;
 
-static test_return_t quiet_test(void *)
-{
-  const char *args[]= { "--quiet", 0 };
-
-  test_true(exec_cmdline(executable, args));
-  return TEST_SUCCESS;
-}
-
 static test_return_t help_test(void *)
 {
-  const char *args[]= { "--quiet", "--help", 0 };
+  const char *args[]= { "--help", 0 };
+
+  test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true));
 
-  test_true(exec_cmdline(executable, args));
   return TEST_SUCCESS;
 }
 
@@ -72,7 +66,6 @@ static test_return_t touch_test(void *)
 {
   char buffer[1024];
   snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port()));
-  const char *args[]= { "--quiet", "--expire=30", buffer, "foo", 0 };
 
   memcached_st *memc= memcached(buffer, strlen(buffer));
   test_true(memc);
@@ -82,7 +75,9 @@ static test_return_t touch_test(void *)
 
   test_compare(MEMCACHED_SUCCESS, memcached_exist(memc, test_literal_param("foo")));
 
-  test_true(exec_cmdline(executable, args));
+  snprintf(buffer, sizeof(buffer), "--servers=localhost:%d", int(default_port()));
+  const char *args[]= { "--expire=30", buffer, "foo", 0 };
+  test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true));
 
   test_compare(MEMCACHED_SUCCESS, memcached_exist(memc, test_literal_param("foo")));
 
@@ -95,8 +90,6 @@ static test_return_t NOT_FOUND_test(void *)
 {
   char buffer[1024];
   snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port()));
-  const char *args[]= { "--quiet", "--expire=30", buffer, "foo", 0 };
-
   memcached_st *memc= memcached(buffer, strlen(buffer));
   test_true(memc);
 
@@ -104,7 +97,9 @@ static test_return_t NOT_FOUND_test(void *)
 
   test_compare(MEMCACHED_NOTFOUND, memcached_exist(memc, test_literal_param("foo")));
 
-  test_true(exec_cmdline(executable, args));
+  snprintf(buffer, sizeof(buffer), "--servers=localhost:%d", int(default_port()));
+  const char *args[]= { "--expire=30", buffer, "foo", 0 };
+  test_compare(EXIT_FAILURE, exec_cmdline(executable, args, true));
 
   test_compare(MEMCACHED_NOTFOUND, memcached_exist(memc, test_literal_param("foo")));
 
@@ -113,8 +108,24 @@ static test_return_t NOT_FOUND_test(void *)
   return TEST_SUCCESS;
 }
 
+static test_return_t check_version(void*)
+{
+  char buffer[1024];
+  snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port()));
+  memcached_st *memc= memcached(buffer, strlen(buffer));
+  test_true(memc);
+  
+  test_return_t result= TEST_SUCCESS;
+  if (libmemcached_util_version_check(memc, 1, 4, 8) == false)
+  {
+    result= TEST_SKIPPED;
+  }
+  memcached_free(memc);
+
+  return result;
+}
+
 test_st memtouch_tests[] ={
-  {"--quiet", true, quiet_test },
   {"--help", true, help_test },
   {"touch(FOUND)", true, touch_test },
   {"touch(NOT_FOUND)", true, NOT_FOUND_test },
@@ -122,7 +133,7 @@ test_st memtouch_tests[] ={
 };
 
 collection_st collection[] ={
-  {"memtouch", 0, 0, memtouch_tests },
+  {"memtouch", check_version, 0, memtouch_tests },
   {0, 0, 0, 0}
 };
 
@@ -134,8 +145,7 @@ static void *world_create(server_startup_st& servers, test_return_t& error)
     return NULL;
   }
 
-  const char *argv[1]= { "memtouch" };
-  if (not server_startup(servers, "memcached", libtest::default_port(), 1, argv))
+  if (server_startup(servers, "memcached", libtest::default_port(), 0, NULL) == false)
   {
     error= TEST_FAILURE;
   }
index 6f848f381ed9067c50ecca17bc6e4cf36a390c16..2dcf1c4347eecf49c1852920c389f4f3ccdccbc0 100644 (file)
@@ -14,6 +14,7 @@ noinst_HEADERS+= \
                 util/daemon.hpp \
                 util/instance.hpp \
                 util/logfile.hpp \
+                util/log.hpp \
                 util/operation.hpp \
                 util/signal.hpp \
                 util/string.hpp \
diff --git a/util/log.hpp b/util/log.hpp
new file mode 100644 (file)
index 0000000..1442faa
--- /dev/null
@@ -0,0 +1,208 @@
+/*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ * 
+ *  libtest
+ *
+ *  Copyright (C) 2011-2012 Data Differential, http://datadifferential.com/
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 3 of the License, or (at your option) any later version.
+ *
+ *  This library 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
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#pragma once
+
+#include <cerrno>
+#include <cstdarg>
+#include <cstdio>
+#include <fcntl.h>
+#include <iostream>
+#include <string>
+#include <syslog.h>
+
+#define UTIL_MAX_ERROR_SIZE 2048
+
+namespace datadifferential {
+namespace util {
+
+/** Verbosity levels.
+ */
+enum verbose_t
+{
+  // Logging this will cause shutdown
+  VERBOSE_FATAL= LOG_EMERG, // syslog:LOG_EMERG
+
+  VERBOSE_ALERT= LOG_ALERT, // syslog:LOG_ALERT
+  VERBOSE_CRITICAL= LOG_CRIT, //  syslog:LOG_CRIT
+
+  VERBOSE_ERROR= LOG_ERR, // syslog:LOG_ERR
+
+  VERBOSE_WARN= LOG_WARNING, // syslog:LOG_WARNING
+
+  VERBOSE_NOTICE= LOG_NOTICE, // syslog:LOG_NOTICE
+
+  VERBOSE_INFO= LOG_INFO, // syslog:LOG_INFO
+
+  VERBOSE_DEBUG= LOG_DEBUG // syslog:LOG_DEBUG
+};
+
+
+struct log_info_st
+{
+  std::string name;
+  std::string filename;
+  int fd;
+  bool opt_syslog;
+  bool opt_file;
+  bool init_success;
+
+  log_info_st(const std::string& name_arg, const std::string &filename_arg, bool syslog_arg) :
+    name(name_arg),
+    filename(filename_arg),
+    fd(-1),
+    opt_syslog(syslog_arg),
+    opt_file(false),
+    init_success(false)
+  {
+    if (opt_syslog)
+    {
+      openlog(name.c_str(), LOG_PID | LOG_NDELAY, LOG_USER);
+    }
+
+    init();
+  }
+
+  void init()
+  {
+    if (filename.size())
+    {
+      if (filename.compare("stderr") == 0)
+      {
+        fd= STDERR_FILENO;
+      }
+      else
+      {
+        fd= open(filename.c_str(), O_CREAT | O_WRONLY | O_APPEND, 0644);
+        if (fd == -1)
+        {
+          if (opt_syslog)
+          {
+            char buffer[1024];
+            char *getcwd_ret= getcwd(buffer, sizeof(buffer));
+            syslog(LOG_ERR, "Could not open log file \"%.*s\", from \"%s\", open failed with (%s)", 
+                   int(filename.size()), filename.c_str(), 
+                   getcwd_ret,
+                   strerror(errno));
+          }
+          std::cerr << "Could not open log file for writing, switching to stderr." << std::endl;
+
+          fd= STDERR_FILENO;
+        }
+      }
+
+      opt_file= true;
+    }
+
+    init_success= true;
+  }
+
+  bool initialized() const
+  {
+    return init_success;
+  }
+
+  int file() const
+  {
+    return fd;
+  }
+
+  void write(verbose_t verbose, const char *format, ...)
+  {
+    if (opt_file or opt_syslog)
+    {
+      va_list args;
+      va_start(args, format);
+      char mesg[BUFSIZ];
+      int mesg_length= vsnprintf(mesg, sizeof(mesg), format, args);
+      va_end(args);
+
+      if (opt_file)
+      {
+        char buffer[UTIL_MAX_ERROR_SIZE];
+        int buffer_length= snprintf(buffer, sizeof(buffer), "%7s %.*s\n", verbose_name(verbose), mesg_length, mesg);
+        if (::write(file(), buffer, buffer_length) == -1)
+        {
+          std::cerr << "Could not write to log file." << std::endl;
+          syslog(LOG_EMERG, "gearmand could not open log file %s, got error %s", filename.c_str(), strerror(errno));
+        }
+
+      }
+
+      if (opt_syslog)
+      {
+        syslog(int(verbose), "%7s %.*s", verbose_name(verbose), mesg_length, mesg);
+      }
+    }
+  }
+
+  ~log_info_st()
+  {
+    if (fd != -1 and fd != STDERR_FILENO)
+    {
+      close(fd);
+    }
+
+    if (opt_syslog)
+    {
+      closelog();
+    }
+  }
+
+private:
+  const char *verbose_name(verbose_t verbose)
+  {
+    switch (verbose)
+    {
+    case VERBOSE_FATAL:
+      return "FATAL";
+
+    case VERBOSE_ALERT:
+      return "ALERT";
+
+    case VERBOSE_CRITICAL:
+      return "CRITICAL";
+
+    case VERBOSE_ERROR:
+      return "ERROR";
+
+    case VERBOSE_WARN:
+      return "WARNING";
+
+    case VERBOSE_NOTICE:
+      return "NOTICE";
+
+    case VERBOSE_INFO:
+      return "INFO";
+
+    case VERBOSE_DEBUG:
+      return "DEBUG";
+
+    default:
+      break;
+    }
+
+    return "UNKNOWN";
+  }
+};
+
+} // namespace util
+} // namespace datadifferential