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,175 @@
|
|
1
|
+
#include "common.h"
|
2
|
+
#include <sys/types.h>
|
3
|
+
#include <sys/socket.h>
|
4
|
+
#include <netinet/tcp.h>
|
5
|
+
|
6
|
+
/*
|
7
|
+
These functions provide data and function callback support
|
8
|
+
*/
|
9
|
+
|
10
|
+
memcached_return memcached_callback_set(memcached_st *ptr,
|
11
|
+
memcached_callback flag,
|
12
|
+
void *data)
|
13
|
+
{
|
14
|
+
switch (flag)
|
15
|
+
{
|
16
|
+
case MEMCACHED_CALLBACK_PREFIX_KEY:
|
17
|
+
{
|
18
|
+
char *key= (char *)data;
|
19
|
+
|
20
|
+
if (key)
|
21
|
+
{
|
22
|
+
size_t key_length= strlen(key);
|
23
|
+
|
24
|
+
if (memcached_key_test((const char **)&key, &key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED)
|
25
|
+
{
|
26
|
+
return MEMCACHED_BAD_KEY_PROVIDED;
|
27
|
+
}
|
28
|
+
|
29
|
+
if ((key_length > MEMCACHED_PREFIX_KEY_MAX_SIZE -1)
|
30
|
+
|| (strcpy(ptr->prefix_key, key) == NULL))
|
31
|
+
{
|
32
|
+
ptr->prefix_key_length= 0;
|
33
|
+
return MEMCACHED_BAD_KEY_PROVIDED;
|
34
|
+
}
|
35
|
+
else
|
36
|
+
{
|
37
|
+
ptr->prefix_key_length= key_length;
|
38
|
+
}
|
39
|
+
}
|
40
|
+
else
|
41
|
+
{
|
42
|
+
memset(ptr->prefix_key, 0, MEMCACHED_PREFIX_KEY_MAX_SIZE);
|
43
|
+
ptr->prefix_key_length= 0;
|
44
|
+
}
|
45
|
+
|
46
|
+
break;
|
47
|
+
}
|
48
|
+
case MEMCACHED_CALLBACK_USER_DATA:
|
49
|
+
{
|
50
|
+
ptr->user_data= data;
|
51
|
+
break;
|
52
|
+
}
|
53
|
+
case MEMCACHED_CALLBACK_CLEANUP_FUNCTION:
|
54
|
+
{
|
55
|
+
memcached_cleanup_func func= *(memcached_cleanup_func *)&data;
|
56
|
+
ptr->on_cleanup= func;
|
57
|
+
break;
|
58
|
+
}
|
59
|
+
case MEMCACHED_CALLBACK_CLONE_FUNCTION:
|
60
|
+
{
|
61
|
+
memcached_clone_func func= *(memcached_clone_func *)&data;
|
62
|
+
ptr->on_clone= func;
|
63
|
+
break;
|
64
|
+
}
|
65
|
+
#ifdef MEMCACHED_ENABLE_DEPRECATED
|
66
|
+
case MEMCACHED_CALLBACK_MALLOC_FUNCTION:
|
67
|
+
{
|
68
|
+
memcached_malloc_function func= *(memcached_malloc_function *)&data;
|
69
|
+
ptr->call_malloc= func;
|
70
|
+
break;
|
71
|
+
}
|
72
|
+
case MEMCACHED_CALLBACK_REALLOC_FUNCTION:
|
73
|
+
{
|
74
|
+
memcached_realloc_function func= *(memcached_realloc_function *)&data;
|
75
|
+
ptr->call_realloc= func;
|
76
|
+
break;
|
77
|
+
}
|
78
|
+
case MEMCACHED_CALLBACK_FREE_FUNCTION:
|
79
|
+
{
|
80
|
+
memcached_free_function func= *(memcached_free_function *)&data;
|
81
|
+
ptr->call_free= func;
|
82
|
+
break;
|
83
|
+
}
|
84
|
+
#endif
|
85
|
+
case MEMCACHED_CALLBACK_GET_FAILURE:
|
86
|
+
{
|
87
|
+
memcached_trigger_key func= *(memcached_trigger_key *)&data;
|
88
|
+
ptr->get_key_failure= func;
|
89
|
+
break;
|
90
|
+
}
|
91
|
+
case MEMCACHED_CALLBACK_DELETE_TRIGGER:
|
92
|
+
{
|
93
|
+
memcached_trigger_delete_key func= *(memcached_trigger_delete_key *)&data;
|
94
|
+
ptr->delete_trigger= func;
|
95
|
+
break;
|
96
|
+
}
|
97
|
+
default:
|
98
|
+
return MEMCACHED_FAILURE;
|
99
|
+
}
|
100
|
+
|
101
|
+
return MEMCACHED_SUCCESS;
|
102
|
+
}
|
103
|
+
|
104
|
+
void *memcached_callback_get(memcached_st *ptr,
|
105
|
+
memcached_callback flag,
|
106
|
+
memcached_return *error)
|
107
|
+
{
|
108
|
+
memcached_return local_error;
|
109
|
+
|
110
|
+
if (!error)
|
111
|
+
error = &local_error;
|
112
|
+
|
113
|
+
switch (flag)
|
114
|
+
{
|
115
|
+
case MEMCACHED_CALLBACK_PREFIX_KEY:
|
116
|
+
{
|
117
|
+
if (ptr->prefix_key[0] == 0)
|
118
|
+
{
|
119
|
+
*error= MEMCACHED_FAILURE;
|
120
|
+
return NULL;
|
121
|
+
}
|
122
|
+
else
|
123
|
+
{
|
124
|
+
*error= MEMCACHED_SUCCESS;
|
125
|
+
return (void *)ptr->prefix_key;
|
126
|
+
}
|
127
|
+
}
|
128
|
+
case MEMCACHED_CALLBACK_USER_DATA:
|
129
|
+
{
|
130
|
+
*error= ptr->user_data ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
|
131
|
+
return (void *)ptr->user_data;
|
132
|
+
}
|
133
|
+
case MEMCACHED_CALLBACK_CLEANUP_FUNCTION:
|
134
|
+
{
|
135
|
+
*error= ptr->on_cleanup ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
|
136
|
+
return *(void **)&ptr->on_cleanup;
|
137
|
+
}
|
138
|
+
case MEMCACHED_CALLBACK_CLONE_FUNCTION:
|
139
|
+
{
|
140
|
+
*error= ptr->on_clone ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
|
141
|
+
return *(void **)&ptr->on_clone;
|
142
|
+
}
|
143
|
+
#ifdef MEMCACHED_ENABLE_DEPRECATED
|
144
|
+
case MEMCACHED_CALLBACK_MALLOC_FUNCTION:
|
145
|
+
{
|
146
|
+
*error= ptr->call_malloc ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
|
147
|
+
return *(void **)&ptr->call_malloc;
|
148
|
+
}
|
149
|
+
case MEMCACHED_CALLBACK_REALLOC_FUNCTION:
|
150
|
+
{
|
151
|
+
*error= ptr->call_realloc ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
|
152
|
+
return *(void **)&ptr->call_realloc;
|
153
|
+
}
|
154
|
+
case MEMCACHED_CALLBACK_FREE_FUNCTION:
|
155
|
+
{
|
156
|
+
*error= ptr->call_free ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
|
157
|
+
return *(void **)&ptr->call_free;
|
158
|
+
}
|
159
|
+
#endif
|
160
|
+
case MEMCACHED_CALLBACK_GET_FAILURE:
|
161
|
+
{
|
162
|
+
*error= ptr->get_key_failure ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
|
163
|
+
return *(void **)&ptr->get_key_failure;
|
164
|
+
}
|
165
|
+
case MEMCACHED_CALLBACK_DELETE_TRIGGER:
|
166
|
+
{
|
167
|
+
*error= ptr->delete_trigger ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
|
168
|
+
return *(void **)&ptr->delete_trigger;
|
169
|
+
}
|
170
|
+
default:
|
171
|
+
WATCHPOINT_ASSERT(0);
|
172
|
+
*error= MEMCACHED_FAILURE;
|
173
|
+
return NULL;
|
174
|
+
}
|
175
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
/*
|
2
|
+
* Summary: Preprocessor symbols set from configure we need install-time
|
3
|
+
*
|
4
|
+
* Copy: See Copyright for the status of this software.
|
5
|
+
*
|
6
|
+
* Author: Trond Norbye
|
7
|
+
*/
|
8
|
+
|
9
|
+
#ifndef MEMCACHED_CONFIGURE_H
|
10
|
+
#define MEMCACHED_CONFIGURE_H
|
11
|
+
|
12
|
+
#ifdef __cplusplus
|
13
|
+
extern "C" {
|
14
|
+
#endif
|
15
|
+
|
16
|
+
@DEPRECATED@
|
17
|
+
@LIBMEMCACHED_WITH_SASL_SUPPORT@
|
18
|
+
|
19
|
+
#ifdef __cplusplus
|
20
|
+
}
|
21
|
+
#endif
|
22
|
+
|
23
|
+
#endif /* MEMCACHED_CONFIGURE_H */
|
@@ -0,0 +1,361 @@
|
|
1
|
+
#include "common.h"
|
2
|
+
#include <netdb.h>
|
3
|
+
#include <poll.h>
|
4
|
+
#include <sys/time.h>
|
5
|
+
|
6
|
+
static memcached_return set_hostinfo(memcached_server_st *server)
|
7
|
+
{
|
8
|
+
struct addrinfo *ai;
|
9
|
+
struct addrinfo hints;
|
10
|
+
int e;
|
11
|
+
char str_port[NI_MAXSERV];
|
12
|
+
|
13
|
+
sprintf(str_port, "%u", server->port);
|
14
|
+
|
15
|
+
memset(&hints, 0, sizeof(hints));
|
16
|
+
|
17
|
+
// hints.ai_family= AF_INET;
|
18
|
+
if (server->type == MEMCACHED_CONNECTION_UDP)
|
19
|
+
{
|
20
|
+
hints.ai_protocol= IPPROTO_UDP;
|
21
|
+
hints.ai_socktype= SOCK_DGRAM;
|
22
|
+
}
|
23
|
+
else
|
24
|
+
{
|
25
|
+
hints.ai_socktype= SOCK_STREAM;
|
26
|
+
hints.ai_protocol= IPPROTO_TCP;
|
27
|
+
}
|
28
|
+
|
29
|
+
e= getaddrinfo(server->hostname, str_port, &hints, &ai);
|
30
|
+
if (e != 0)
|
31
|
+
{
|
32
|
+
WATCHPOINT_STRING(server->hostname);
|
33
|
+
WATCHPOINT_STRING(gai_strerror(e));
|
34
|
+
return MEMCACHED_HOST_LOOKUP_FAILURE;
|
35
|
+
}
|
36
|
+
|
37
|
+
if (server->address_info)
|
38
|
+
{
|
39
|
+
freeaddrinfo(server->address_info);
|
40
|
+
server->address_info= NULL;
|
41
|
+
}
|
42
|
+
server->address_info= ai;
|
43
|
+
|
44
|
+
return MEMCACHED_SUCCESS;
|
45
|
+
}
|
46
|
+
|
47
|
+
static memcached_return set_socket_options(memcached_server_st *ptr)
|
48
|
+
{
|
49
|
+
WATCHPOINT_ASSERT(ptr->fd != -1);
|
50
|
+
|
51
|
+
if (ptr->type == MEMCACHED_CONNECTION_UDP)
|
52
|
+
return MEMCACHED_SUCCESS;
|
53
|
+
|
54
|
+
#ifdef HAVE_SNDTIMEO
|
55
|
+
if (ptr->root->snd_timeout)
|
56
|
+
{
|
57
|
+
int error;
|
58
|
+
struct timeval waittime;
|
59
|
+
|
60
|
+
waittime.tv_sec= 0;
|
61
|
+
waittime.tv_usec= ptr->root->snd_timeout;
|
62
|
+
|
63
|
+
error= setsockopt(ptr->fd, SOL_SOCKET, SO_SNDTIMEO,
|
64
|
+
&waittime, (socklen_t)sizeof(struct timeval));
|
65
|
+
WATCHPOINT_ASSERT(error == 0);
|
66
|
+
}
|
67
|
+
#endif
|
68
|
+
|
69
|
+
#ifdef HAVE_RCVTIMEO
|
70
|
+
if (ptr->root->rcv_timeout)
|
71
|
+
{
|
72
|
+
int error;
|
73
|
+
struct timeval waittime;
|
74
|
+
|
75
|
+
waittime.tv_sec= 0;
|
76
|
+
waittime.tv_usec= ptr->root->rcv_timeout;
|
77
|
+
|
78
|
+
error= setsockopt(ptr->fd, SOL_SOCKET, SO_RCVTIMEO,
|
79
|
+
&waittime, (socklen_t)sizeof(struct timeval));
|
80
|
+
WATCHPOINT_ASSERT(error == 0);
|
81
|
+
}
|
82
|
+
#endif
|
83
|
+
|
84
|
+
if (ptr->root->flags & MEM_NO_BLOCK)
|
85
|
+
{
|
86
|
+
int error;
|
87
|
+
struct linger linger;
|
88
|
+
|
89
|
+
linger.l_onoff= 1;
|
90
|
+
linger.l_linger= 0; /* By default on close() just drop the socket */
|
91
|
+
error= setsockopt(ptr->fd, SOL_SOCKET, SO_LINGER,
|
92
|
+
&linger, (socklen_t)sizeof(struct linger));
|
93
|
+
WATCHPOINT_ASSERT(error == 0);
|
94
|
+
}
|
95
|
+
|
96
|
+
if (ptr->root->flags & MEM_TCP_NODELAY)
|
97
|
+
{
|
98
|
+
int flag= 1;
|
99
|
+
int error;
|
100
|
+
|
101
|
+
error= setsockopt(ptr->fd, IPPROTO_TCP, TCP_NODELAY,
|
102
|
+
&flag, (socklen_t)sizeof(int));
|
103
|
+
WATCHPOINT_ASSERT(error == 0);
|
104
|
+
}
|
105
|
+
|
106
|
+
if (ptr->root->send_size)
|
107
|
+
{
|
108
|
+
int error;
|
109
|
+
|
110
|
+
error= setsockopt(ptr->fd, SOL_SOCKET, SO_SNDBUF,
|
111
|
+
&ptr->root->send_size, (socklen_t)sizeof(int));
|
112
|
+
WATCHPOINT_ASSERT(error == 0);
|
113
|
+
}
|
114
|
+
|
115
|
+
if (ptr->root->recv_size)
|
116
|
+
{
|
117
|
+
int error;
|
118
|
+
|
119
|
+
error= setsockopt(ptr->fd, SOL_SOCKET, SO_RCVBUF,
|
120
|
+
&ptr->root->recv_size, (socklen_t)sizeof(int));
|
121
|
+
WATCHPOINT_ASSERT(error == 0);
|
122
|
+
}
|
123
|
+
|
124
|
+
/* For the moment, not getting a nonblocking mode will not be fatal */
|
125
|
+
if ((ptr->root->flags & MEM_NO_BLOCK) || ptr->root->connect_timeout)
|
126
|
+
{
|
127
|
+
int flags;
|
128
|
+
|
129
|
+
flags= fcntl(ptr->fd, F_GETFL, 0);
|
130
|
+
unlikely (flags != -1)
|
131
|
+
{
|
132
|
+
(void)fcntl(ptr->fd, F_SETFL, flags | O_NONBLOCK);
|
133
|
+
}
|
134
|
+
}
|
135
|
+
|
136
|
+
return MEMCACHED_SUCCESS;
|
137
|
+
}
|
138
|
+
|
139
|
+
static memcached_return unix_socket_connect(memcached_server_st *ptr)
|
140
|
+
{
|
141
|
+
struct sockaddr_un servAddr;
|
142
|
+
socklen_t addrlen;
|
143
|
+
|
144
|
+
if (ptr->fd == -1)
|
145
|
+
{
|
146
|
+
if ((ptr->fd= socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
|
147
|
+
{
|
148
|
+
ptr->cached_errno= errno;
|
149
|
+
return MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE;
|
150
|
+
}
|
151
|
+
|
152
|
+
memset(&servAddr, 0, sizeof (struct sockaddr_un));
|
153
|
+
servAddr.sun_family= AF_UNIX;
|
154
|
+
strcpy(servAddr.sun_path, ptr->hostname); /* Copy filename */
|
155
|
+
|
156
|
+
addrlen= (socklen_t) (strlen(servAddr.sun_path) + sizeof(servAddr.sun_family));
|
157
|
+
|
158
|
+
test_connect:
|
159
|
+
if (connect(ptr->fd,
|
160
|
+
(struct sockaddr *)&servAddr,
|
161
|
+
sizeof(servAddr)) < 0)
|
162
|
+
{
|
163
|
+
switch (errno)
|
164
|
+
{
|
165
|
+
case EINPROGRESS:
|
166
|
+
case EALREADY:
|
167
|
+
case EINTR:
|
168
|
+
goto test_connect;
|
169
|
+
case EISCONN: /* We were spinning waiting on connect */
|
170
|
+
break;
|
171
|
+
default:
|
172
|
+
WATCHPOINT_ERRNO(errno);
|
173
|
+
ptr->cached_errno= errno;
|
174
|
+
return MEMCACHED_ERRNO;
|
175
|
+
}
|
176
|
+
}
|
177
|
+
}
|
178
|
+
|
179
|
+
WATCHPOINT_ASSERT(ptr->fd != -1);
|
180
|
+
return MEMCACHED_SUCCESS;
|
181
|
+
}
|
182
|
+
|
183
|
+
static memcached_return network_connect(memcached_server_st *ptr)
|
184
|
+
{
|
185
|
+
if (ptr->fd == -1)
|
186
|
+
{
|
187
|
+
struct addrinfo *use;
|
188
|
+
|
189
|
+
if (!ptr->sockaddr_inited ||
|
190
|
+
(!(ptr->root->flags & MEM_USE_CACHE_LOOKUPS)))
|
191
|
+
{
|
192
|
+
memcached_return rc;
|
193
|
+
|
194
|
+
rc= set_hostinfo(ptr);
|
195
|
+
if (rc != MEMCACHED_SUCCESS)
|
196
|
+
return rc;
|
197
|
+
ptr->sockaddr_inited= true;
|
198
|
+
}
|
199
|
+
|
200
|
+
use= ptr->address_info;
|
201
|
+
/* Create the socket */
|
202
|
+
while (use != NULL)
|
203
|
+
{
|
204
|
+
/* Memcache server does not support IPV6 in udp mode, so skip if not ipv4 */
|
205
|
+
if (ptr->type == MEMCACHED_CONNECTION_UDP && use->ai_family != AF_INET)
|
206
|
+
{
|
207
|
+
use= use->ai_next;
|
208
|
+
continue;
|
209
|
+
}
|
210
|
+
|
211
|
+
if ((ptr->fd= socket(use->ai_family,
|
212
|
+
use->ai_socktype,
|
213
|
+
use->ai_protocol)) < 0)
|
214
|
+
{
|
215
|
+
ptr->cached_errno= errno;
|
216
|
+
WATCHPOINT_ERRNO(errno);
|
217
|
+
return MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE;
|
218
|
+
}
|
219
|
+
|
220
|
+
(void)set_socket_options(ptr);
|
221
|
+
|
222
|
+
int flags= 0;
|
223
|
+
if (ptr->root->connect_timeout)
|
224
|
+
{
|
225
|
+
flags= fcntl(ptr->fd, F_GETFL, 0);
|
226
|
+
if (flags != -1 && !(flags & O_NONBLOCK))
|
227
|
+
(void)fcntl(ptr->fd, F_SETFL, flags | O_NONBLOCK);
|
228
|
+
}
|
229
|
+
|
230
|
+
/* connect to server */
|
231
|
+
while (ptr->fd != -1 &&
|
232
|
+
connect(ptr->fd, use->ai_addr, use->ai_addrlen) < 0)
|
233
|
+
{
|
234
|
+
ptr->cached_errno= errno;
|
235
|
+
if (errno == EINPROGRESS || /* nonblocking mode - first return, */
|
236
|
+
errno == EALREADY) /* nonblocking mode - subsequent returns */
|
237
|
+
{
|
238
|
+
struct pollfd fds[1];
|
239
|
+
fds[0].fd = ptr->fd;
|
240
|
+
fds[0].events = POLLOUT;
|
241
|
+
int error= poll(fds, 1, ptr->root->connect_timeout);
|
242
|
+
|
243
|
+
if (error != 1 || fds[0].revents & POLLERR)
|
244
|
+
{
|
245
|
+
ptr->cached_errno = 0;
|
246
|
+
|
247
|
+
if (fds[0].revents & POLLERR)
|
248
|
+
{
|
249
|
+
int err;
|
250
|
+
socklen_t len = sizeof (err);
|
251
|
+
(void)getsockopt(ptr->fd, SOL_SOCKET, SO_ERROR, &err, &len);
|
252
|
+
ptr->cached_errno= (err == 0) ? errno : err;
|
253
|
+
}
|
254
|
+
|
255
|
+
(void)close(ptr->fd);
|
256
|
+
ptr->fd= -1;
|
257
|
+
}
|
258
|
+
}
|
259
|
+
else if (errno == EISCONN) /* we are connected :-) */
|
260
|
+
{
|
261
|
+
break;
|
262
|
+
}
|
263
|
+
else if (errno != EINTR)
|
264
|
+
{
|
265
|
+
(void)close(ptr->fd);
|
266
|
+
ptr->fd= -1;
|
267
|
+
break;
|
268
|
+
}
|
269
|
+
}
|
270
|
+
|
271
|
+
#ifdef LIBMEMCACHED_WITH_SASL_SUPPORT
|
272
|
+
if (ptr->fd != -1 && ptr->root->sasl_callbacks != NULL)
|
273
|
+
{
|
274
|
+
memcached_return rc= memcached_sasl_authenticate_connection(ptr);
|
275
|
+
if (rc != MEMCACHED_SUCCESS)
|
276
|
+
{
|
277
|
+
(void)close(ptr->fd);
|
278
|
+
ptr->fd= -1;
|
279
|
+
return rc;
|
280
|
+
}
|
281
|
+
}
|
282
|
+
#endif
|
283
|
+
|
284
|
+
|
285
|
+
if (ptr->fd != -1)
|
286
|
+
{
|
287
|
+
/* restore flags */
|
288
|
+
if (ptr->root->connect_timeout && (ptr->root->flags & MEM_NO_BLOCK) == 0)
|
289
|
+
(void)fcntl(ptr->fd, F_SETFL, flags & ~O_NONBLOCK);
|
290
|
+
|
291
|
+
WATCHPOINT_ASSERT(ptr->cursor_active == 0);
|
292
|
+
return MEMCACHED_SUCCESS;
|
293
|
+
}
|
294
|
+
use = use->ai_next;
|
295
|
+
}
|
296
|
+
}
|
297
|
+
|
298
|
+
if (ptr->fd == -1)
|
299
|
+
{
|
300
|
+
ptr->server_failure_counter ++;
|
301
|
+
if (ptr->cached_errno == 0)
|
302
|
+
return MEMCACHED_TIMEOUT;
|
303
|
+
|
304
|
+
return MEMCACHED_ERRNO; /* The last error should be from connect() */
|
305
|
+
}
|
306
|
+
|
307
|
+
return MEMCACHED_SUCCESS; /* The last error should be from connect() */
|
308
|
+
}
|
309
|
+
|
310
|
+
|
311
|
+
memcached_return memcached_connect(memcached_server_st *ptr)
|
312
|
+
{
|
313
|
+
memcached_return rc= MEMCACHED_NO_SERVERS;
|
314
|
+
LIBMEMCACHED_MEMCACHED_CONNECT_START();
|
315
|
+
|
316
|
+
/* both retry_timeout and server_failure_limit must be set in order to delay retrying a server on error. */
|
317
|
+
WATCHPOINT_ASSERT(ptr->root);
|
318
|
+
if (ptr->root->retry_timeout && ptr->root->server_failure_limit)
|
319
|
+
{
|
320
|
+
struct timeval next_time;
|
321
|
+
|
322
|
+
gettimeofday(&next_time, NULL);
|
323
|
+
|
324
|
+
/* if we've had too many consecutive errors on this server, mark it dead. */
|
325
|
+
if (ptr->server_failure_counter >= ptr->root->server_failure_limit)
|
326
|
+
{
|
327
|
+
ptr->next_retry= next_time.tv_sec + ptr->root->retry_timeout;
|
328
|
+
ptr->server_failure_counter= 0;
|
329
|
+
}
|
330
|
+
|
331
|
+
if (next_time.tv_sec < ptr->next_retry)
|
332
|
+
{
|
333
|
+
if (memcached_behavior_get(ptr->root, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS))
|
334
|
+
run_distribution(ptr->root);
|
335
|
+
|
336
|
+
return MEMCACHED_SERVER_MARKED_DEAD;
|
337
|
+
}
|
338
|
+
}
|
339
|
+
|
340
|
+
/* We need to clean up the multi startup piece */
|
341
|
+
switch (ptr->type)
|
342
|
+
{
|
343
|
+
case MEMCACHED_CONNECTION_UNKNOWN:
|
344
|
+
WATCHPOINT_ASSERT(0);
|
345
|
+
rc= MEMCACHED_NOT_SUPPORTED;
|
346
|
+
break;
|
347
|
+
case MEMCACHED_CONNECTION_UDP:
|
348
|
+
case MEMCACHED_CONNECTION_TCP:
|
349
|
+
rc= network_connect(ptr);
|
350
|
+
break;
|
351
|
+
case MEMCACHED_CONNECTION_UNIX_SOCKET:
|
352
|
+
rc= unix_socket_connect(ptr);
|
353
|
+
break;
|
354
|
+
default:
|
355
|
+
WATCHPOINT_ASSERT(0);
|
356
|
+
}
|
357
|
+
|
358
|
+
LIBMEMCACHED_MEMCACHED_CONNECT_END();
|
359
|
+
|
360
|
+
return rc;
|
361
|
+
}
|