memcached 1.2.6 → 1.2.7
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/Manifest +206 -12
- data/Rakefile +32 -1
- data/ext/extconf.rb +10 -35
- data/ext/libmemcached-0.32/AUTHORS +7 -0
- data/ext/libmemcached-0.32/COPYING +32 -0
- data/ext/libmemcached-0.32/ChangeLog +303 -0
- data/ext/libmemcached-0.32/INSTALL +302 -0
- data/ext/libmemcached-0.32/Makefile.am +36 -0
- data/ext/libmemcached-0.32/Makefile.in +828 -0
- data/ext/libmemcached-0.32/NEWS +1 -0
- data/ext/libmemcached-0.32/README +33 -0
- data/ext/libmemcached-0.32/THANKS +14 -0
- data/ext/libmemcached-0.32/TODO +11 -0
- data/ext/libmemcached-0.32/aclocal.m4 +1852 -0
- data/ext/libmemcached-0.32/clients/Makefile.am +73 -0
- data/ext/libmemcached-0.32/clients/Makefile.in +770 -0
- data/ext/libmemcached-0.32/clients/client_options.h +32 -0
- data/ext/libmemcached-0.32/clients/execute.c +64 -0
- data/ext/libmemcached-0.32/clients/execute.h +5 -0
- data/ext/libmemcached-0.32/clients/generator.c +74 -0
- data/ext/libmemcached-0.32/clients/generator.h +20 -0
- data/ext/libmemcached-0.32/clients/memcat.c +178 -0
- data/ext/libmemcached-0.32/clients/memcp.c +251 -0
- data/ext/libmemcached-0.32/clients/memdump.c +170 -0
- data/ext/libmemcached-0.32/clients/memerror.c +80 -0
- data/ext/libmemcached-0.32/clients/memflush.c +143 -0
- data/ext/libmemcached-0.32/clients/memrm.c +160 -0
- data/ext/libmemcached-0.32/clients/memslap.c +441 -0
- data/ext/libmemcached-0.32/clients/memstat.c +326 -0
- data/ext/libmemcached-0.32/clients/utilities.c +207 -0
- data/ext/libmemcached-0.32/clients/utilities.h +41 -0
- data/ext/libmemcached-0.32/config.h.in +252 -0
- data/ext/libmemcached-0.32/config/compile +143 -0
- data/ext/libmemcached-0.32/config/config.guess +1561 -0
- data/ext/libmemcached-0.32/config/config.rpath +666 -0
- data/ext/libmemcached-0.32/config/config.sub +1686 -0
- data/ext/libmemcached-0.32/config/depcomp +630 -0
- data/ext/libmemcached-0.32/config/install-sh +520 -0
- data/ext/libmemcached-0.32/config/ltmain.sh +8406 -0
- data/ext/libmemcached-0.32/config/missing +376 -0
- data/ext/libmemcached-0.32/configure +23048 -0
- data/ext/libmemcached-0.32/configure.ac +122 -0
- data/ext/libmemcached-0.32/docs/Makefile.am +415 -0
- data/ext/libmemcached-0.32/docs/Makefile.in +918 -0
- data/ext/libmemcached-0.32/docs/libmemcached.pod +123 -0
- data/ext/libmemcached-0.32/docs/libmemcached_examples.pod +115 -0
- data/ext/libmemcached-0.32/docs/libmemcachedutil.pod +40 -0
- data/ext/libmemcached-0.32/docs/memcached_analyze.pod +52 -0
- data/ext/libmemcached-0.32/docs/memcached_auto.pod +97 -0
- data/ext/libmemcached-0.32/docs/memcached_behavior.pod +224 -0
- data/ext/libmemcached-0.32/docs/memcached_callback.pod +123 -0
- data/ext/libmemcached-0.32/docs/memcached_create.pod +61 -0
- data/ext/libmemcached-0.32/docs/memcached_delete.pod +54 -0
- data/ext/libmemcached-0.32/docs/memcached_dump.pod +53 -0
- data/ext/libmemcached-0.32/docs/memcached_flush.pod +46 -0
- data/ext/libmemcached-0.32/docs/memcached_flush_buffers.pod +42 -0
- data/ext/libmemcached-0.32/docs/memcached_generate_hash_value.pod +57 -0
- data/ext/libmemcached-0.32/docs/memcached_get.pod +161 -0
- data/ext/libmemcached-0.32/docs/memcached_memory_allocators.pod +73 -0
- data/ext/libmemcached-0.32/docs/memcached_pool.pod +77 -0
- data/ext/libmemcached-0.32/docs/memcached_quit.pod +47 -0
- data/ext/libmemcached-0.32/docs/memcached_sasl.pod +63 -0
- data/ext/libmemcached-0.32/docs/memcached_server_st.pod +75 -0
- data/ext/libmemcached-0.32/docs/memcached_servers.pod +102 -0
- data/ext/libmemcached-0.32/docs/memcached_set.pod +187 -0
- data/ext/libmemcached-0.32/docs/memcached_stats.pod +82 -0
- data/ext/libmemcached-0.32/docs/memcached_strerror.pod +46 -0
- data/ext/libmemcached-0.32/docs/memcached_user_data.pod +49 -0
- data/ext/libmemcached-0.32/docs/memcached_verbosity.pod +41 -0
- data/ext/libmemcached-0.32/docs/memcached_version.pod +56 -0
- data/ext/libmemcached-0.32/docs/memcat.pod +37 -0
- data/ext/libmemcached-0.32/docs/memcp.pod +40 -0
- data/ext/libmemcached-0.32/docs/memdump.pod +31 -0
- data/ext/libmemcached-0.32/docs/memerror.pod +30 -0
- data/ext/libmemcached-0.32/docs/memflush.pod +35 -0
- data/ext/libmemcached-0.32/docs/memrm.pod +34 -0
- data/ext/libmemcached-0.32/docs/memslap.pod +33 -0
- data/ext/libmemcached-0.32/docs/memstat.pod +35 -0
- data/ext/libmemcached-0.32/libmemcached/Makefile.am +107 -0
- data/ext/libmemcached-0.32/libmemcached/Makefile.in +1050 -0
- data/ext/libmemcached-0.32/libmemcached/byteorder.c +31 -0
- data/ext/libmemcached-0.32/libmemcached/common.h +183 -0
- data/ext/libmemcached-0.32/libmemcached/crc.c +86 -0
- data/ext/libmemcached-0.32/libmemcached/hsieh_hash.c +68 -0
- data/ext/libmemcached-0.32/libmemcached/jenkins_hash.c +213 -0
- data/ext/libmemcached-0.32/libmemcached/libmemcached.ver +1 -0
- data/ext/libmemcached-0.32/libmemcached/libmemcached_probes.d +28 -0
- data/ext/libmemcached-0.32/libmemcached/libmemcached_probes.h +78 -0
- data/ext/libmemcached-0.32/libmemcached/md5.c +354 -0
- data/ext/libmemcached-0.32/libmemcached/memcached.c +152 -0
- data/ext/libmemcached-0.32/libmemcached/memcached.h +302 -0
- data/ext/libmemcached-0.32/libmemcached/memcached.hpp +799 -0
- data/ext/libmemcached-0.32/libmemcached/memcached/README.txt +7 -0
- data/ext/libmemcached-0.32/libmemcached/memcached/protocol_binary.h +366 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_allocators.c +72 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_analyze.c +100 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_auto.c +207 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_behavior.c +285 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_callback.c +175 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_configure.h.in +23 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_connect.c +361 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_constants.h +145 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_delete.c +0 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_do.c +34 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_dump.c +79 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_fetch.c +102 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_flush.c +89 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_flush_buffers.c +22 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_get.c +495 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_get.h +87 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_hash.c +252 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_hosts.c +510 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_internal.h +31 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_io.c +547 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_io.h +59 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_key.c +28 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_parse.c +74 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_pool.h +38 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_purge.c +76 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_quit.c +75 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_response.c +528 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_result.c +57 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_result.h +59 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_sasl.c +225 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_sasl.h +44 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_server.c +159 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_server.h +93 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_stats.c +454 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_storage.c +514 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_storage.h +107 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_strerror.c +92 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_string.c +138 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_string.h +53 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_types.h +44 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_util.h +15 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_verbosity.c +36 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_version.c +112 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_watchpoint.h +38 -0
- data/ext/libmemcached-0.32/libmemcached/murmur_hash.c +76 -0
- data/ext/libmemcached-0.32/libmemcached/visibility.h +51 -0
- data/ext/libmemcached-0.32/libmemcachedutil/Makefile.am +11 -0
- data/ext/libmemcached-0.32/libmemcachedutil/Makefile.in +602 -0
- data/ext/libmemcached-0.32/libmemcachedutil/libmemcachedutil.ver +1 -0
- data/ext/libmemcached-0.32/libmemcachedutil/memcached_pool.c +170 -0
- data/ext/libmemcached-0.32/m4/ac_cxx_compile_stdcxx_0x.m4 +103 -0
- data/ext/libmemcached-0.32/m4/ac_cxx_header_stdcxx_98.m4 +67 -0
- data/ext/libmemcached-0.32/m4/acx_pthread.m4 +276 -0
- data/ext/libmemcached-0.32/m4/byteorder.m4 +40 -0
- data/ext/libmemcached-0.32/m4/deprecated.m4 +17 -0
- data/ext/libmemcached-0.32/m4/enable_utillib.m4 +16 -0
- data/ext/libmemcached-0.32/m4/extensions.m4 +94 -0
- data/ext/libmemcached-0.32/m4/hsieh.m4 +18 -0
- data/ext/libmemcached-0.32/m4/lib-prefix.m4 +221 -0
- data/ext/libmemcached-0.32/m4/libtool.m4 +7360 -0
- data/ext/libmemcached-0.32/m4/ltoptions.m4 +368 -0
- data/ext/libmemcached-0.32/m4/ltsugar.m4 +123 -0
- data/ext/libmemcached-0.32/m4/ltversion.m4 +23 -0
- data/ext/libmemcached-0.32/m4/lt~obsolete.m4 +92 -0
- data/ext/libmemcached-0.32/m4/memcached.m4 +30 -0
- data/ext/libmemcached-0.32/m4/pandora_64bit.m4 +55 -0
- data/ext/libmemcached-0.32/m4/pandora_canonical.m4 +151 -0
- data/ext/libmemcached-0.32/m4/pandora_check_compiler_version.m4 +37 -0
- data/ext/libmemcached-0.32/m4/pandora_check_cxx_standard.m4 +16 -0
- data/ext/libmemcached-0.32/m4/pandora_enable_dtrace.m4 +41 -0
- data/ext/libmemcached-0.32/m4/pandora_ensure_gcc_version.m4 +36 -0
- data/ext/libmemcached-0.32/m4/pandora_have_better_malloc.m4 +54 -0
- data/ext/libmemcached-0.32/m4/pandora_have_sasl.m4 +133 -0
- data/ext/libmemcached-0.32/m4/pandora_header_assert.m4 +23 -0
- data/ext/libmemcached-0.32/m4/pandora_libtool.m4 +15 -0
- data/ext/libmemcached-0.32/m4/pandora_optimize.m4 +79 -0
- data/ext/libmemcached-0.32/m4/pandora_shared_ptr.m4 +56 -0
- data/ext/libmemcached-0.32/m4/pandora_vc_build.m4 +32 -0
- data/ext/libmemcached-0.32/m4/pandora_warnings.m4 +262 -0
- data/ext/libmemcached-0.32/m4/pod2man.m4 +7 -0
- data/ext/libmemcached-0.32/m4/protocol_binary.m4 +23 -0
- data/ext/libmemcached-0.32/m4/setsockopt.m4 +57 -0
- data/ext/libmemcached-0.32/m4/visibility.m4 +52 -0
- data/ext/libmemcached-0.32/support/Makefile.am +4 -0
- data/ext/libmemcached-0.32/support/Makefile.in +485 -0
- data/ext/libmemcached-0.32/support/libmemcached-fc.spec.in +105 -0
- data/ext/libmemcached-0.32/support/libmemcached.pc.in +10 -0
- data/ext/libmemcached-0.32/support/libmemcached.spec +105 -0
- data/ext/libmemcached-0.32/support/libmemcached.spec.in +105 -0
- data/ext/libmemcached-0.32/support/set_benchmark.sh +5 -0
- data/ext/libmemcached-0.32/tests/Makefile.am +105 -0
- data/ext/libmemcached-0.32/tests/Makefile.in +748 -0
- data/ext/libmemcached-0.32/tests/atomsmasher.c +245 -0
- data/ext/libmemcached-0.32/tests/function.c +4781 -0
- data/ext/libmemcached-0.32/tests/ketama_test_cases.h +108 -0
- data/ext/libmemcached-0.32/tests/output.cmp +7 -0
- data/ext/libmemcached-0.32/tests/output.res +7 -0
- data/ext/libmemcached-0.32/tests/output2.res +46 -0
- data/ext/libmemcached-0.32/tests/plus.cpp +293 -0
- data/ext/libmemcached-0.32/tests/r/memcat.res +19 -0
- data/ext/libmemcached-0.32/tests/r/memcp.res +27 -0
- data/ext/libmemcached-0.32/tests/r/memrm.res +19 -0
- data/ext/libmemcached-0.32/tests/r/memslap.res +33 -0
- data/ext/libmemcached-0.32/tests/r/memstat.res +33 -0
- data/ext/libmemcached-0.32/tests/server.c +118 -0
- data/ext/libmemcached-0.32/tests/server.h +25 -0
- data/ext/libmemcached-0.32/tests/start.c +16 -0
- data/ext/libmemcached-0.32/tests/t/memcat.test +4 -0
- data/ext/libmemcached-0.32/tests/t/memcp.test +3 -0
- data/ext/libmemcached-0.32/tests/t/memrm.test +3 -0
- data/ext/libmemcached-0.32/tests/t/memslap.test +5 -0
- data/ext/libmemcached-0.32/tests/t/memstat.test +3 -0
- data/ext/libmemcached-0.32/tests/test.c +137 -0
- data/ext/libmemcached-0.32/tests/test.h +46 -0
- data/ext/libmemcached-0.32/tests/udp.c +76 -0
- data/memcached.gemspec +4 -4
- data/test/unit/memcached_test.rb +30 -0
- metadata +213 -16
- data/ext/libmemcached-0.32.tar.gz +0 -0
- data/ext/libmemcached-1.patch +0 -270
- data/ext/libmemcached-10.patch +0 -12
- data/ext/libmemcached-2.patch +0 -116
- data/ext/libmemcached-3.patch +0 -8
- data/ext/libmemcached-4.patch +0 -40
- data/ext/libmemcached-5.patch +0 -832
- data/ext/libmemcached-6.patch +0 -20
- data/ext/libmemcached-7.patch +0 -2989
- data/ext/libmemcached-8.patch +0 -137
- data/ext/libmemcached-9.patch +0 -13
- data/ext/sasl.patch +0 -29283
@@ -0,0 +1,514 @@
|
|
1
|
+
/*
|
2
|
+
Memcached library
|
3
|
+
|
4
|
+
memcached_set()
|
5
|
+
memcached_replace()
|
6
|
+
memcached_add()
|
7
|
+
|
8
|
+
*/
|
9
|
+
#include "common.h"
|
10
|
+
#include "memcached_io.h"
|
11
|
+
|
12
|
+
typedef enum {
|
13
|
+
SET_OP,
|
14
|
+
REPLACE_OP,
|
15
|
+
ADD_OP,
|
16
|
+
PREPEND_OP,
|
17
|
+
APPEND_OP,
|
18
|
+
CAS_OP,
|
19
|
+
DELETE_OP,
|
20
|
+
} memcached_storage_action;
|
21
|
+
|
22
|
+
/* Inline this */
|
23
|
+
static const char *storage_op_string(memcached_storage_action verb)
|
24
|
+
{
|
25
|
+
switch (verb)
|
26
|
+
{
|
27
|
+
case SET_OP:
|
28
|
+
return "set ";
|
29
|
+
case DELETE_OP:
|
30
|
+
return "delete ";
|
31
|
+
case REPLACE_OP:
|
32
|
+
return "replace ";
|
33
|
+
case ADD_OP:
|
34
|
+
return "add ";
|
35
|
+
case PREPEND_OP:
|
36
|
+
return "prepend ";
|
37
|
+
case APPEND_OP:
|
38
|
+
return "append ";
|
39
|
+
case CAS_OP:
|
40
|
+
return "cas ";
|
41
|
+
default:
|
42
|
+
return "tosserror"; /* This is impossible, fixes issue for compiler warning in VisualStudio */
|
43
|
+
}
|
44
|
+
|
45
|
+
/* NOTREACHED */
|
46
|
+
}
|
47
|
+
|
48
|
+
static memcached_return memcached_send_binary(memcached_st *ptr,
|
49
|
+
const char *master_key,
|
50
|
+
size_t master_key_length,
|
51
|
+
const char *key,
|
52
|
+
size_t key_length,
|
53
|
+
const char *value,
|
54
|
+
size_t value_length,
|
55
|
+
time_t expiration,
|
56
|
+
uint32_t flags,
|
57
|
+
uint64_t cas,
|
58
|
+
memcached_storage_action verb);
|
59
|
+
|
60
|
+
static inline memcached_return memcached_send(memcached_st *ptr,
|
61
|
+
const char *master_key, size_t master_key_length,
|
62
|
+
const char *key, size_t key_length,
|
63
|
+
const char *value, size_t value_length,
|
64
|
+
time_t expiration,
|
65
|
+
uint32_t flags,
|
66
|
+
uint64_t cas,
|
67
|
+
memcached_storage_action verb)
|
68
|
+
{
|
69
|
+
char to_write;
|
70
|
+
size_t write_length;
|
71
|
+
ssize_t sent_length;
|
72
|
+
memcached_return rc;
|
73
|
+
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
|
74
|
+
unsigned int server_key;
|
75
|
+
|
76
|
+
WATCHPOINT_ASSERT(!(value == NULL && value_length > 0));
|
77
|
+
|
78
|
+
rc= memcached_validate_key_length(key_length, ptr->flags & MEM_BINARY_PROTOCOL);
|
79
|
+
unlikely (rc != MEMCACHED_SUCCESS)
|
80
|
+
return rc;
|
81
|
+
|
82
|
+
unlikely (ptr->number_of_hosts == 0)
|
83
|
+
return MEMCACHED_NO_SERVERS;
|
84
|
+
|
85
|
+
if ((ptr->flags & MEM_VERIFY_KEY) && (memcached_key_test((const char **)&key, &key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED))
|
86
|
+
return MEMCACHED_BAD_KEY_PROVIDED;
|
87
|
+
|
88
|
+
if (ptr->flags & MEM_BINARY_PROTOCOL)
|
89
|
+
return memcached_send_binary(ptr, master_key, master_key_length,
|
90
|
+
key, key_length,
|
91
|
+
value, value_length, expiration,
|
92
|
+
flags, cas, verb);
|
93
|
+
|
94
|
+
server_key= memcached_generate_hash(ptr, master_key, master_key_length);
|
95
|
+
|
96
|
+
if (cas)
|
97
|
+
write_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
|
98
|
+
"%s%s%.*s %u %llu %zu %llu%s\r\n",
|
99
|
+
storage_op_string(verb),
|
100
|
+
ptr->prefix_key,
|
101
|
+
(int)key_length, key, flags,
|
102
|
+
(unsigned long long)expiration, value_length,
|
103
|
+
(unsigned long long)cas,
|
104
|
+
(ptr->flags & MEM_NOREPLY) ? " noreply" : "");
|
105
|
+
else
|
106
|
+
{
|
107
|
+
char *buffer_ptr= buffer;
|
108
|
+
const char *command= storage_op_string(verb);
|
109
|
+
|
110
|
+
/* Copy in the command, no space needed, we handle that in the command function*/
|
111
|
+
memcpy(buffer_ptr, command, strlen(command));
|
112
|
+
|
113
|
+
/* Copy in the key prefix, switch to the buffer_ptr */
|
114
|
+
buffer_ptr= memcpy(buffer_ptr + strlen(command) , ptr->prefix_key, strlen(ptr->prefix_key));
|
115
|
+
|
116
|
+
/* Copy in the key, adjust point if a key prefix was used. */
|
117
|
+
buffer_ptr= memcpy(buffer_ptr + (ptr->prefix_key ? strlen(ptr->prefix_key) : 0),
|
118
|
+
key, key_length);
|
119
|
+
buffer_ptr+= key_length;
|
120
|
+
buffer_ptr[0]= ' ';
|
121
|
+
buffer_ptr++;
|
122
|
+
write_length= (size_t)(buffer_ptr - buffer);
|
123
|
+
|
124
|
+
if (verb == DELETE_OP) {
|
125
|
+
if (ptr->flags & MEM_NOREPLY)
|
126
|
+
write_length+= (size_t) snprintf(buffer_ptr, MEMCACHED_DEFAULT_COMMAND_SIZE, "noreply");
|
127
|
+
} else {
|
128
|
+
write_length+= (size_t) snprintf(buffer_ptr, MEMCACHED_DEFAULT_COMMAND_SIZE,
|
129
|
+
"%u %llu %zu%s\r\n",
|
130
|
+
flags,
|
131
|
+
(unsigned long long)expiration, value_length,
|
132
|
+
(ptr->flags & MEM_NOREPLY) ? " noreply" : "");
|
133
|
+
}
|
134
|
+
}
|
135
|
+
|
136
|
+
if (ptr->flags & MEM_USE_UDP && ptr->flags & MEM_BUFFER_REQUESTS)
|
137
|
+
{
|
138
|
+
size_t cmd_size= write_length + value_length + 2;
|
139
|
+
if (cmd_size > MAX_UDP_DATAGRAM_LENGTH - UDP_DATAGRAM_HEADER_LENGTH)
|
140
|
+
return MEMCACHED_WRITE_FAILURE;
|
141
|
+
if (cmd_size + ptr->hosts[server_key].write_buffer_offset > MAX_UDP_DATAGRAM_LENGTH)
|
142
|
+
memcached_io_write(&ptr->hosts[server_key], NULL, 0, 1);
|
143
|
+
}
|
144
|
+
|
145
|
+
if (write_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
|
146
|
+
return MEMCACHED_WRITE_FAILURE;
|
147
|
+
|
148
|
+
/* Send command header */
|
149
|
+
rc= memcached_do(&ptr->hosts[server_key], buffer, write_length, 0);
|
150
|
+
if (rc != MEMCACHED_SUCCESS)
|
151
|
+
return rc;
|
152
|
+
|
153
|
+
/* Send command body */
|
154
|
+
if ((sent_length= memcached_io_write(&ptr->hosts[server_key], value, value_length, 0)) == -1)
|
155
|
+
return MEMCACHED_WRITE_FAILURE;
|
156
|
+
|
157
|
+
if ((ptr->flags & MEM_BUFFER_REQUESTS) &&
|
158
|
+
(verb == SET_OP || verb == PREPEND_OP || verb == APPEND_OP || verb == DELETE_OP))
|
159
|
+
to_write= 0;
|
160
|
+
else
|
161
|
+
to_write= 1;
|
162
|
+
|
163
|
+
if ((sent_length= memcached_io_write(&ptr->hosts[server_key], "\r\n", 2, to_write)) == -1)
|
164
|
+
return MEMCACHED_WRITE_FAILURE;
|
165
|
+
|
166
|
+
if (ptr->flags & MEM_NOREPLY)
|
167
|
+
return (to_write == 0) ? MEMCACHED_BUFFERED : MEMCACHED_SUCCESS;
|
168
|
+
|
169
|
+
if (to_write == 0)
|
170
|
+
return MEMCACHED_BUFFERED;
|
171
|
+
|
172
|
+
rc= memcached_response(&ptr->hosts[server_key], buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
|
173
|
+
if (rc == MEMCACHED_STORED || rc == MEMCACHED_DELETED)
|
174
|
+
return MEMCACHED_SUCCESS;
|
175
|
+
|
176
|
+
return rc;
|
177
|
+
}
|
178
|
+
|
179
|
+
|
180
|
+
memcached_return memcached_set(memcached_st *ptr, const char *key, size_t key_length,
|
181
|
+
const char *value, size_t value_length,
|
182
|
+
time_t expiration,
|
183
|
+
uint32_t flags)
|
184
|
+
{
|
185
|
+
memcached_return rc;
|
186
|
+
LIBMEMCACHED_MEMCACHED_SET_START();
|
187
|
+
rc= memcached_send(ptr, key, key_length,
|
188
|
+
key, key_length, value, value_length,
|
189
|
+
expiration, flags, 0, SET_OP);
|
190
|
+
LIBMEMCACHED_MEMCACHED_SET_END();
|
191
|
+
return rc;
|
192
|
+
}
|
193
|
+
|
194
|
+
memcached_return memcached_delete(memcached_st *ptr, const char *key, size_t key_length,
|
195
|
+
time_t expiration)
|
196
|
+
{
|
197
|
+
memcached_return rc;
|
198
|
+
LIBMEMCACHED_MEMCACHED_DELETE_START();
|
199
|
+
rc= memcached_send(ptr, key, key_length,
|
200
|
+
key, key_length, "", 0,
|
201
|
+
expiration, 0, 0, DELETE_OP);
|
202
|
+
LIBMEMCACHED_MEMCACHED_DELETE_END();
|
203
|
+
return rc;
|
204
|
+
}
|
205
|
+
|
206
|
+
memcached_return memcached_delete_by_key(memcached_st *ptr,
|
207
|
+
const char *master_key, size_t master_key_length,
|
208
|
+
const char *key, size_t key_length,
|
209
|
+
time_t expiration)
|
210
|
+
{
|
211
|
+
memcached_return rc;
|
212
|
+
LIBMEMCACHED_MEMCACHED_DELETE_START();
|
213
|
+
rc= memcached_send(ptr, master_key, master_key_length,
|
214
|
+
key, key_length, "", 0,
|
215
|
+
expiration, 0, 0, DELETE_OP);
|
216
|
+
LIBMEMCACHED_MEMCACHED_DELETE_END();
|
217
|
+
return rc;
|
218
|
+
}
|
219
|
+
|
220
|
+
memcached_return memcached_add(memcached_st *ptr,
|
221
|
+
const char *key, size_t key_length,
|
222
|
+
const char *value, size_t value_length,
|
223
|
+
time_t expiration,
|
224
|
+
uint32_t flags)
|
225
|
+
{
|
226
|
+
memcached_return rc;
|
227
|
+
LIBMEMCACHED_MEMCACHED_ADD_START();
|
228
|
+
rc= memcached_send(ptr, key, key_length,
|
229
|
+
key, key_length, value, value_length,
|
230
|
+
expiration, flags, 0, ADD_OP);
|
231
|
+
LIBMEMCACHED_MEMCACHED_ADD_END();
|
232
|
+
return rc;
|
233
|
+
}
|
234
|
+
|
235
|
+
memcached_return memcached_replace(memcached_st *ptr,
|
236
|
+
const char *key, size_t key_length,
|
237
|
+
const char *value, size_t value_length,
|
238
|
+
time_t expiration,
|
239
|
+
uint32_t flags)
|
240
|
+
{
|
241
|
+
memcached_return rc;
|
242
|
+
LIBMEMCACHED_MEMCACHED_REPLACE_START();
|
243
|
+
rc= memcached_send(ptr, key, key_length,
|
244
|
+
key, key_length, value, value_length,
|
245
|
+
expiration, flags, 0, REPLACE_OP);
|
246
|
+
LIBMEMCACHED_MEMCACHED_REPLACE_END();
|
247
|
+
return rc;
|
248
|
+
}
|
249
|
+
|
250
|
+
memcached_return memcached_prepend(memcached_st *ptr,
|
251
|
+
const char *key, size_t key_length,
|
252
|
+
const char *value, size_t value_length,
|
253
|
+
time_t expiration,
|
254
|
+
uint32_t flags)
|
255
|
+
{
|
256
|
+
memcached_return rc;
|
257
|
+
rc= memcached_send(ptr, key, key_length,
|
258
|
+
key, key_length, value, value_length,
|
259
|
+
expiration, flags, 0, PREPEND_OP);
|
260
|
+
return rc;
|
261
|
+
}
|
262
|
+
|
263
|
+
memcached_return memcached_append(memcached_st *ptr,
|
264
|
+
const char *key, size_t key_length,
|
265
|
+
const char *value, size_t value_length,
|
266
|
+
time_t expiration,
|
267
|
+
uint32_t flags)
|
268
|
+
{
|
269
|
+
memcached_return rc;
|
270
|
+
rc= memcached_send(ptr, key, key_length,
|
271
|
+
key, key_length, value, value_length,
|
272
|
+
expiration, flags, 0, APPEND_OP);
|
273
|
+
return rc;
|
274
|
+
}
|
275
|
+
|
276
|
+
memcached_return memcached_cas(memcached_st *ptr,
|
277
|
+
const char *key, size_t key_length,
|
278
|
+
const char *value, size_t value_length,
|
279
|
+
time_t expiration,
|
280
|
+
uint32_t flags,
|
281
|
+
uint64_t cas)
|
282
|
+
{
|
283
|
+
memcached_return rc;
|
284
|
+
rc= memcached_send(ptr, key, key_length,
|
285
|
+
key, key_length, value, value_length,
|
286
|
+
expiration, flags, cas, CAS_OP);
|
287
|
+
return rc;
|
288
|
+
}
|
289
|
+
|
290
|
+
memcached_return memcached_set_by_key(memcached_st *ptr,
|
291
|
+
const char *master_key __attribute__((unused)),
|
292
|
+
size_t master_key_length __attribute__((unused)),
|
293
|
+
const char *key, size_t key_length,
|
294
|
+
const char *value, size_t value_length,
|
295
|
+
time_t expiration,
|
296
|
+
uint32_t flags)
|
297
|
+
{
|
298
|
+
memcached_return rc;
|
299
|
+
LIBMEMCACHED_MEMCACHED_SET_START();
|
300
|
+
rc= memcached_send(ptr, master_key, master_key_length,
|
301
|
+
key, key_length, value, value_length,
|
302
|
+
expiration, flags, 0, SET_OP);
|
303
|
+
LIBMEMCACHED_MEMCACHED_SET_END();
|
304
|
+
return rc;
|
305
|
+
}
|
306
|
+
|
307
|
+
memcached_return memcached_add_by_key(memcached_st *ptr,
|
308
|
+
const char *master_key, size_t master_key_length,
|
309
|
+
const char *key, size_t key_length,
|
310
|
+
const char *value, size_t value_length,
|
311
|
+
time_t expiration,
|
312
|
+
uint32_t flags)
|
313
|
+
{
|
314
|
+
memcached_return rc;
|
315
|
+
LIBMEMCACHED_MEMCACHED_ADD_START();
|
316
|
+
rc= memcached_send(ptr, master_key, master_key_length,
|
317
|
+
key, key_length, value, value_length,
|
318
|
+
expiration, flags, 0, ADD_OP);
|
319
|
+
LIBMEMCACHED_MEMCACHED_ADD_END();
|
320
|
+
return rc;
|
321
|
+
}
|
322
|
+
|
323
|
+
memcached_return memcached_replace_by_key(memcached_st *ptr,
|
324
|
+
const char *master_key, size_t master_key_length,
|
325
|
+
const char *key, size_t key_length,
|
326
|
+
const char *value, size_t value_length,
|
327
|
+
time_t expiration,
|
328
|
+
uint32_t flags)
|
329
|
+
{
|
330
|
+
memcached_return rc;
|
331
|
+
LIBMEMCACHED_MEMCACHED_REPLACE_START();
|
332
|
+
rc= memcached_send(ptr, master_key, master_key_length,
|
333
|
+
key, key_length, value, value_length,
|
334
|
+
expiration, flags, 0, REPLACE_OP);
|
335
|
+
LIBMEMCACHED_MEMCACHED_REPLACE_END();
|
336
|
+
return rc;
|
337
|
+
}
|
338
|
+
|
339
|
+
memcached_return memcached_prepend_by_key(memcached_st *ptr,
|
340
|
+
const char *master_key, size_t master_key_length,
|
341
|
+
const char *key, size_t key_length,
|
342
|
+
const char *value, size_t value_length,
|
343
|
+
time_t expiration,
|
344
|
+
uint32_t flags)
|
345
|
+
{
|
346
|
+
memcached_return rc;
|
347
|
+
rc= memcached_send(ptr, master_key, master_key_length,
|
348
|
+
key, key_length, value, value_length,
|
349
|
+
expiration, flags, 0, PREPEND_OP);
|
350
|
+
return rc;
|
351
|
+
}
|
352
|
+
|
353
|
+
memcached_return memcached_append_by_key(memcached_st *ptr,
|
354
|
+
const char *master_key, size_t master_key_length,
|
355
|
+
const char *key, size_t key_length,
|
356
|
+
const char *value, size_t value_length,
|
357
|
+
time_t expiration,
|
358
|
+
uint32_t flags)
|
359
|
+
{
|
360
|
+
memcached_return rc;
|
361
|
+
rc= memcached_send(ptr, master_key, master_key_length,
|
362
|
+
key, key_length, value, value_length,
|
363
|
+
expiration, flags, 0, APPEND_OP);
|
364
|
+
return rc;
|
365
|
+
}
|
366
|
+
|
367
|
+
memcached_return memcached_cas_by_key(memcached_st *ptr,
|
368
|
+
const char *master_key, size_t master_key_length,
|
369
|
+
const char *key, size_t key_length,
|
370
|
+
const char *value, size_t value_length,
|
371
|
+
time_t expiration,
|
372
|
+
uint32_t flags,
|
373
|
+
uint64_t cas)
|
374
|
+
{
|
375
|
+
memcached_return rc;
|
376
|
+
rc= memcached_send(ptr, master_key, master_key_length,
|
377
|
+
key, key_length, value, value_length,
|
378
|
+
expiration, flags, cas, CAS_OP);
|
379
|
+
return rc;
|
380
|
+
}
|
381
|
+
|
382
|
+
static inline uint8_t get_com_code(memcached_storage_action verb, bool noreply)
|
383
|
+
{
|
384
|
+
/* 0 isn't a value we want, but GCC 4.2 seems to think ret can otherwise
|
385
|
+
* be used uninitialized in this function. FAIL */
|
386
|
+
uint8_t ret= 0;
|
387
|
+
|
388
|
+
if (noreply)
|
389
|
+
switch (verb)
|
390
|
+
{
|
391
|
+
case SET_OP:
|
392
|
+
ret=PROTOCOL_BINARY_CMD_SETQ;
|
393
|
+
break;
|
394
|
+
case DELETE_OP:
|
395
|
+
ret=PROTOCOL_BINARY_CMD_DELETEQ;
|
396
|
+
break;
|
397
|
+
case ADD_OP:
|
398
|
+
ret=PROTOCOL_BINARY_CMD_ADDQ;
|
399
|
+
break;
|
400
|
+
case CAS_OP: /* FALLTHROUGH */
|
401
|
+
case REPLACE_OP:
|
402
|
+
ret=PROTOCOL_BINARY_CMD_REPLACEQ;
|
403
|
+
break;
|
404
|
+
case APPEND_OP:
|
405
|
+
ret=PROTOCOL_BINARY_CMD_APPENDQ;
|
406
|
+
break;
|
407
|
+
case PREPEND_OP:
|
408
|
+
ret=PROTOCOL_BINARY_CMD_PREPENDQ;
|
409
|
+
break;
|
410
|
+
default:
|
411
|
+
WATCHPOINT_ASSERT(verb);
|
412
|
+
break;
|
413
|
+
}
|
414
|
+
else
|
415
|
+
switch (verb)
|
416
|
+
{
|
417
|
+
case SET_OP:
|
418
|
+
ret=PROTOCOL_BINARY_CMD_SET;
|
419
|
+
break;
|
420
|
+
case DELETE_OP:
|
421
|
+
ret=PROTOCOL_BINARY_CMD_DELETE;
|
422
|
+
break;
|
423
|
+
case ADD_OP:
|
424
|
+
ret=PROTOCOL_BINARY_CMD_ADD;
|
425
|
+
break;
|
426
|
+
case CAS_OP: /* FALLTHROUGH */
|
427
|
+
case REPLACE_OP:
|
428
|
+
ret=PROTOCOL_BINARY_CMD_REPLACE;
|
429
|
+
break;
|
430
|
+
case APPEND_OP:
|
431
|
+
ret=PROTOCOL_BINARY_CMD_APPEND;
|
432
|
+
break;
|
433
|
+
case PREPEND_OP:
|
434
|
+
ret=PROTOCOL_BINARY_CMD_PREPEND;
|
435
|
+
break;
|
436
|
+
default:
|
437
|
+
WATCHPOINT_ASSERT(verb);
|
438
|
+
break;
|
439
|
+
}
|
440
|
+
|
441
|
+
return ret;
|
442
|
+
}
|
443
|
+
|
444
|
+
|
445
|
+
|
446
|
+
static memcached_return memcached_send_binary(memcached_st *ptr,
|
447
|
+
const char *master_key,
|
448
|
+
size_t master_key_length,
|
449
|
+
const char *key,
|
450
|
+
size_t key_length,
|
451
|
+
const char *value,
|
452
|
+
size_t value_length,
|
453
|
+
time_t expiration,
|
454
|
+
uint32_t flags,
|
455
|
+
uint64_t cas,
|
456
|
+
memcached_storage_action verb)
|
457
|
+
{
|
458
|
+
uint8_t flush;
|
459
|
+
protocol_binary_request_set request= {.bytes= {0}};
|
460
|
+
size_t send_length= sizeof(request.bytes);
|
461
|
+
uint32_t server_key= memcached_generate_hash(ptr, master_key,
|
462
|
+
master_key_length);
|
463
|
+
memcached_server_st *server= &ptr->hosts[server_key];
|
464
|
+
bool noreply= server->root->flags & MEM_NOREPLY;
|
465
|
+
|
466
|
+
request.message.header.request.magic= PROTOCOL_BINARY_REQ;
|
467
|
+
request.message.header.request.opcode= get_com_code(verb, noreply);
|
468
|
+
request.message.header.request.keylen= htons((uint16_t)(ptr->prefix_key_length + key_length));
|
469
|
+
request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
|
470
|
+
if (verb == APPEND_OP || verb == PREPEND_OP || verb == DELETE_OP)
|
471
|
+
send_length -= 8; /* append, delete, and prepend do not contain extras! */
|
472
|
+
else
|
473
|
+
{
|
474
|
+
request.message.header.request.extlen= 8;
|
475
|
+
request.message.body.flags= htonl(flags);
|
476
|
+
request.message.body.expiration= htonl((uint32_t)expiration);
|
477
|
+
}
|
478
|
+
|
479
|
+
request.message.header.request.bodylen= htonl((uint32_t) (ptr->prefix_key_length + key_length + value_length +
|
480
|
+
request.message.header.request.extlen));
|
481
|
+
|
482
|
+
if (cas)
|
483
|
+
request.message.header.request.cas= htonll(cas);
|
484
|
+
|
485
|
+
flush= (uint8_t) (((server->root->flags & MEM_BUFFER_REQUESTS) && verb == SET_OP) ? 0 : 1);
|
486
|
+
|
487
|
+
if ((server->root->flags & MEM_USE_UDP) && !flush)
|
488
|
+
{
|
489
|
+
size_t cmd_size= send_length + ptr->prefix_key_length + key_length + value_length;
|
490
|
+
if (cmd_size > MAX_UDP_DATAGRAM_LENGTH - UDP_DATAGRAM_HEADER_LENGTH)
|
491
|
+
return MEMCACHED_WRITE_FAILURE;
|
492
|
+
if (cmd_size + server->write_buffer_offset > MAX_UDP_DATAGRAM_LENGTH)
|
493
|
+
memcached_io_write(server,NULL,0, 1);
|
494
|
+
}
|
495
|
+
|
496
|
+
/* write the header */
|
497
|
+
if ((memcached_do(server, (const char*)request.bytes, send_length, 0) != MEMCACHED_SUCCESS) ||
|
498
|
+
(memcached_io_write(server, ptr->prefix_key, ptr->prefix_key_length, 0) == -1) ||
|
499
|
+
(memcached_io_write(server, key, key_length, 0) == -1) ||
|
500
|
+
(memcached_io_write(server, value, value_length, (char) flush) == -1))
|
501
|
+
{
|
502
|
+
memcached_io_reset(server);
|
503
|
+
return MEMCACHED_WRITE_FAILURE;
|
504
|
+
}
|
505
|
+
|
506
|
+
if (flush == 0)
|
507
|
+
return MEMCACHED_BUFFERED;
|
508
|
+
|
509
|
+
if (noreply)
|
510
|
+
return MEMCACHED_SUCCESS;
|
511
|
+
|
512
|
+
return memcached_response(server, NULL, 0, NULL);
|
513
|
+
}
|
514
|
+
|