Merge lp:~flier-lu/libmemcached/win32-vs2008 into lp:~tangent-org/libmemcached/trunk
- win32-vs2008
- Merge into trunk
Proposed by
flier
Status: | Work in progress |
---|---|
Proposed branch: | lp:~flier-lu/libmemcached/win32-vs2008 |
Merge into: | lp:~tangent-org/libmemcached/trunk |
Diff against target: |
7279 lines (+4809/-598) 67 files modified
.bzrignore (+13/-0) clients/memcapable.c (+103/-61) clients/memcat.c (+7/-4) clients/memcp.c (+10/-7) clients/memdump.c (+5/-2) clients/memerror.c (+4/-1) clients/memflush.c (+4/-1) clients/memrm.c (+4/-1) clients/memstat.c (+13/-9) clients/utilities.c (+241/-231) clients/utilities.h (+5/-0) libhashkit/common.h (+20/-0) libhashkit/fnv.c (+8/-4) libhashkit/hashkit.c (+7/-9) libhashkit/visibility.h (+14/-4) libmemcached/allocators.c (+30/-20) libmemcached/allocators.h (+1/-1) libmemcached/analyze.c (+3/-1) libmemcached/auto.c (+14/-9) libmemcached/behavior.c (+5/-4) libmemcached/byteorder.c (+3/-1) libmemcached/common.h (+14/-6) libmemcached/connect.c (+11/-7) libmemcached/delete.c (+16/-10) libmemcached/do.c (+4/-2) libmemcached/fetch.c (+2/-1) libmemcached/flush.c (+6/-3) libmemcached/flush_buffers.c (+2/-1) libmemcached/get.c (+66/-52) libmemcached/hash.c (+9/-3) libmemcached/hosts.c (+6/-4) libmemcached/io.c (+42/-26) libmemcached/memcached.c (+19/-32) libmemcached/memcached.h (+1/-7) libmemcached/purge.c (+8/-6) libmemcached/quit.c (+4/-1) libmemcached/response.c (+13/-6) libmemcached/sasl.c (+4/-0) libmemcached/server.c (+12/-5) libmemcached/stats.c (+17/-8) libmemcached/storage.c (+33/-22) libmemcached/types.h (+7/-0) libmemcached/verbosity.c (+3/-1) libmemcached/version.c (+13/-6) libmemcached/visibility.h (+14/-4) libmemcached/watchpoint.h (+3/-3) poll/poll.c (+21/-12) win32/common.vsprops (+25/-0) win32/debug.vsprops (+12/-0) win32/getopt.c (+1067/-0) win32/getopt.h (+173/-0) win32/inttypes.h (+13/-0) win32/libmemcached.sln (+92/-0) win32/libmemcached.vcproj (+618/-0) win32/memcapable.vcproj (+205/-0) win32/memcat.vcproj (+204/-0) win32/memcp.vcproj (+206/-0) win32/memdump.vcproj (+205/-0) win32/memerror.vcproj (+205/-0) win32/memflush.vcproj (+205/-0) win32/memrm.vcproj (+205/-0) win32/memslap.vcproj (+263/-0) win32/memstat.vcproj (+205/-0) win32/release.vsprops (+12/-0) win32/stdbool.h (+6/-0) win32/wrappers.c (+16/-0) win32/wrappers.h (+8/-0) |
To merge this branch: | bzr merge lp:~flier-lu/libmemcached/win32-vs2008 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Libmemcached-developers | Pending | ||
Review via email: mp+45334@code.launchpad.net |
Commit message
Description of the change
Remove C99 syntax and add supports to Win32 with VS2008
To post a comment you must log in.
- 905. By flier
-
use pointer instead of reference to pass allocator
- 906. By flier
-
port libhashkit to win32
- 907. By flier
-
-h
- 908. By flier
-
port poll to win32
- 909. By flier
-
update solution
- 910. By flier
-
define LIBMEMCACHED_STATIC to support static link
- 911. By flier
-
use DLL mode by default
- 912. By flier
-
replace %zu instead of %lu
- 913. By flier
-
porting client
Unmerged revisions
- 913. By flier
-
porting client
- 912. By flier
-
replace %zu instead of %lu
- 911. By flier
-
use DLL mode by default
- 910. By flier
-
define LIBMEMCACHED_STATIC to support static link
- 909. By flier
-
update solution
- 908. By flier
-
port poll to win32
- 907. By flier
-
-h
- 906. By flier
-
port libhashkit to win32
- 905. By flier
-
use pointer instead of reference to pass allocator
- 904. By flier
-
Add VS2008 project
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file '.bzrignore' | |||
2 | --- .bzrignore 2010-09-14 07:55:39 +0000 | |||
3 | +++ .bzrignore 2011-01-13 03:40:43 +0000 | |||
4 | @@ -185,3 +185,16 @@ | |||
5 | 185 | tests/testplus | 185 | tests/testplus |
6 | 186 | tests/testudp | 186 | tests/testudp |
7 | 187 | unittests/unittests | 187 | unittests/unittests |
8 | 188 | win32/Debug | ||
9 | 189 | win32/Release | ||
10 | 190 | win32/libmemcached.vcproj.WIN2003R2.flier.user | ||
11 | 191 | win32/memcapable.vcproj.WIN2003R2.flier.user | ||
12 | 192 | win32/memcat.vcproj.WIN2003R2.flier.user | ||
13 | 193 | win32/memcp.vcproj.WIN2003R2.flier.user | ||
14 | 194 | win32/memdump.vcproj.WIN2003R2.flier.user | ||
15 | 195 | win32/memerror.vcproj.WIN2003R2.flier.user | ||
16 | 196 | win32/memflush.vcproj.WIN2003R2.flier.user | ||
17 | 197 | win32/memrm.vcproj.WIN2003R2.flier.user | ||
18 | 198 | win32/memslap.vcproj.WIN2003R2.flier.user | ||
19 | 199 | win32/memstat.vcproj.WIN2003R2.flier.user | ||
20 | 200 | *.bak | ||
21 | 188 | 201 | ||
22 | === modified file 'clients/memcapable.c' | |||
23 | --- clients/memcapable.c 2010-10-28 22:21:05 +0000 | |||
24 | +++ clients/memcapable.c 2011-01-13 03:40:43 +0000 | |||
25 | @@ -11,11 +11,18 @@ | |||
26 | 11 | 11 | ||
27 | 12 | /* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */ | 12 | /* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */ |
28 | 13 | #undef NDEBUG | 13 | #undef NDEBUG |
29 | 14 | |||
30 | 14 | #include "config.h" | 15 | #include "config.h" |
35 | 15 | #include <pthread.h> | 16 | #ifdef WIN32 |
36 | 16 | #include <sys/types.h> | 17 | # define ETIMEDOUT WSAETIMEDOUT |
37 | 17 | #include <fcntl.h> | 18 | #else |
38 | 18 | #include <signal.h> | 19 | # include <pthread.h> |
39 | 20 | # include <sys/types.h> | ||
40 | 21 | # include <fcntl.h> | ||
41 | 22 | # include <signal.h> | ||
42 | 23 | # include <unistd.h> | ||
43 | 24 | #endif | ||
44 | 25 | |||
45 | 19 | #include <stdio.h> | 26 | #include <stdio.h> |
46 | 20 | #include <stdlib.h> | 27 | #include <stdlib.h> |
47 | 21 | #include <errno.h> | 28 | #include <errno.h> |
48 | @@ -23,7 +30,6 @@ | |||
49 | 23 | #include <string.h> | 30 | #include <string.h> |
50 | 24 | #include <inttypes.h> | 31 | #include <inttypes.h> |
51 | 25 | #include <stdbool.h> | 32 | #include <stdbool.h> |
52 | 26 | #include <unistd.h> | ||
53 | 27 | #include <ctype.h> | 33 | #include <ctype.h> |
54 | 28 | 34 | ||
55 | 29 | #include <libmemcached/memcached.h> | 35 | #include <libmemcached/memcached.h> |
56 | @@ -88,11 +94,13 @@ | |||
57 | 88 | static struct addrinfo *lookuphost(const char *hostname, const char *port) | 94 | static struct addrinfo *lookuphost(const char *hostname, const char *port) |
58 | 89 | { | 95 | { |
59 | 90 | struct addrinfo *ai= 0; | 96 | struct addrinfo *ai= 0; |
63 | 91 | struct addrinfo hints= {.ai_family=AF_UNSPEC, | 97 | struct addrinfo hints; |
61 | 92 | .ai_protocol=IPPROTO_TCP, | ||
62 | 93 | .ai_socktype=SOCK_STREAM}; | ||
64 | 94 | int error= getaddrinfo(hostname, port, &hints, &ai); | 98 | int error= getaddrinfo(hostname, port, &hints, &ai); |
65 | 95 | 99 | ||
66 | 100 | hints.ai_family=AF_UNSPEC; | ||
67 | 101 | hints.ai_protocol=IPPROTO_TCP; | ||
68 | 102 | hints.ai_socktype=SOCK_STREAM; | ||
69 | 103 | |||
70 | 96 | if (error != 0) | 104 | if (error != 0) |
71 | 97 | { | 105 | { |
72 | 98 | if (error != EAI_SYSTEM) | 106 | if (error != EAI_SYSTEM) |
73 | @@ -187,13 +195,12 @@ | |||
74 | 187 | ret= recv(fd, buf, len, 0); | 195 | ret= recv(fd, buf, len, 0); |
75 | 188 | 196 | ||
76 | 189 | if (ret == SOCKET_ERROR && get_socket_errno() == EWOULDBLOCK) { | 197 | if (ret == SOCKET_ERROR && get_socket_errno() == EWOULDBLOCK) { |
82 | 190 | struct pollfd fds= { | 198 | struct pollfd fds; |
78 | 191 | .events= direction, | ||
79 | 192 | .fd= fd | ||
80 | 193 | }; | ||
81 | 194 | |||
83 | 195 | int err= poll(&fds, 1, timeout * 1000); | 199 | int err= poll(&fds, 1, timeout * 1000); |
84 | 196 | 200 | ||
85 | 201 | fds.events= direction; | ||
86 | 202 | fds.fd= fd; | ||
87 | 203 | |||
88 | 197 | if (err == 1) | 204 | if (err == 1) |
89 | 198 | { | 205 | { |
90 | 199 | if (direction == POLLOUT) | 206 | if (direction == POLLOUT) |
91 | @@ -322,6 +329,8 @@ | |||
92 | 322 | */ | 329 | */ |
93 | 323 | static enum test_return recv_packet(response *rsp) | 330 | static enum test_return recv_packet(response *rsp) |
94 | 324 | { | 331 | { |
95 | 332 | size_t bodysz; | ||
96 | 333 | |||
97 | 325 | execute(retry_read(rsp, sizeof(protocol_binary_response_no_extras))); | 334 | execute(retry_read(rsp, sizeof(protocol_binary_response_no_extras))); |
98 | 326 | 335 | ||
99 | 327 | /* Fix the byte order in the packet header */ | 336 | /* Fix the byte order in the packet header */ |
100 | @@ -334,7 +343,7 @@ | |||
101 | 334 | rsp->plain.message.header.response.cas= | 343 | rsp->plain.message.header.response.cas= |
102 | 335 | ntohll(rsp->plain.message.header.response.cas); | 344 | ntohll(rsp->plain.message.header.response.cas); |
103 | 336 | 345 | ||
105 | 337 | size_t bodysz= rsp->plain.message.header.response.bodylen; | 346 | bodysz= rsp->plain.message.header.response.bodylen; |
106 | 338 | if (bodysz > 0) | 347 | if (bodysz > 0) |
107 | 339 | execute(retry_read(rsp->bytes + sizeof (protocol_binary_response_no_extras), bodysz)); | 348 | execute(retry_read(rsp->bytes + sizeof (protocol_binary_response_no_extras), bodysz)); |
108 | 340 | 349 | ||
109 | @@ -362,6 +371,8 @@ | |||
110 | 362 | uint32_t flags, | 371 | uint32_t flags, |
111 | 363 | uint32_t exptime) | 372 | uint32_t exptime) |
112 | 364 | { | 373 | { |
113 | 374 | off_t key_offset; | ||
114 | 375 | |||
115 | 365 | /* all of the storage commands use the same command layout */ | 376 | /* all of the storage commands use the same command layout */ |
116 | 366 | protocol_binary_request_set *request= &cmd->set; | 377 | protocol_binary_request_set *request= &cmd->set; |
117 | 367 | 378 | ||
118 | @@ -375,7 +386,7 @@ | |||
119 | 375 | request->message.body.flags= flags; | 386 | request->message.body.flags= flags; |
120 | 376 | request->message.body.expiration= exptime; | 387 | request->message.body.expiration= exptime; |
121 | 377 | 388 | ||
123 | 378 | off_t key_offset= sizeof (protocol_binary_request_no_extras) + 8; | 389 | key_offset= sizeof (protocol_binary_request_no_extras) + 8; |
124 | 379 | memcpy(cmd->bytes + key_offset, key, keylen); | 390 | memcpy(cmd->bytes + key_offset, key, keylen); |
125 | 380 | if (dta != NULL) | 391 | if (dta != NULL) |
126 | 381 | memcpy(cmd->bytes + key_offset + keylen, dta, dtalen); | 392 | memcpy(cmd->bytes + key_offset + keylen, dta, dtalen); |
127 | @@ -397,6 +408,8 @@ | |||
128 | 397 | const void* dta, | 408 | const void* dta, |
129 | 398 | size_t dtalen) | 409 | size_t dtalen) |
130 | 399 | { | 410 | { |
131 | 411 | off_t key_offset; | ||
132 | 412 | |||
133 | 400 | /* all of the storage commands use the same command layout */ | 413 | /* all of the storage commands use the same command layout */ |
134 | 401 | memset(cmd, 0, sizeof (*cmd)); | 414 | memset(cmd, 0, sizeof (*cmd)); |
135 | 402 | cmd->plain.message.header.request.magic= PROTOCOL_BINARY_REQ; | 415 | cmd->plain.message.header.request.magic= PROTOCOL_BINARY_REQ; |
136 | @@ -405,7 +418,7 @@ | |||
137 | 405 | cmd->plain.message.header.request.bodylen= (uint32_t)(keylen + dtalen); | 418 | cmd->plain.message.header.request.bodylen= (uint32_t)(keylen + dtalen); |
138 | 406 | cmd->plain.message.header.request.opaque= 0xdeadbeef; | 419 | cmd->plain.message.header.request.opaque= 0xdeadbeef; |
139 | 407 | 420 | ||
141 | 408 | off_t key_offset= sizeof (protocol_binary_request_no_extras); | 421 | key_offset= sizeof (protocol_binary_request_no_extras); |
142 | 409 | 422 | ||
143 | 410 | if (key != NULL) | 423 | if (key != NULL) |
144 | 411 | memcpy(cmd->bytes + key_offset, key, keylen); | 424 | memcpy(cmd->bytes + key_offset, key, keylen); |
145 | @@ -454,6 +467,8 @@ | |||
146 | 454 | uint64_t initial, | 467 | uint64_t initial, |
147 | 455 | uint32_t exptime) | 468 | uint32_t exptime) |
148 | 456 | { | 469 | { |
149 | 470 | off_t key_offset; | ||
150 | 471 | |||
151 | 457 | memset(cmd, 0, sizeof (cmd->incr)); | 472 | memset(cmd, 0, sizeof (cmd->incr)); |
152 | 458 | cmd->incr.message.header.request.magic= PROTOCOL_BINARY_REQ; | 473 | cmd->incr.message.header.request.magic= PROTOCOL_BINARY_REQ; |
153 | 459 | cmd->incr.message.header.request.opcode= cc; | 474 | cmd->incr.message.header.request.opcode= cc; |
154 | @@ -465,7 +480,7 @@ | |||
155 | 465 | cmd->incr.message.body.initial= htonll(initial); | 480 | cmd->incr.message.body.initial= htonll(initial); |
156 | 466 | cmd->incr.message.body.expiration= htonl(exptime); | 481 | cmd->incr.message.body.expiration= htonl(exptime); |
157 | 467 | 482 | ||
159 | 468 | off_t key_offset= sizeof (protocol_binary_request_no_extras) + 20; | 483 | key_offset= sizeof (protocol_binary_request_no_extras) + 20; |
160 | 469 | memcpy(cmd->bytes + key_offset, key, keylen); | 484 | memcpy(cmd->bytes + key_offset, key, keylen); |
161 | 470 | } | 485 | } |
162 | 471 | 486 | ||
163 | @@ -643,12 +658,13 @@ | |||
164 | 643 | { | 658 | { |
165 | 644 | command cmd; | 659 | command cmd; |
166 | 645 | response rsp; | 660 | response rsp; |
167 | 661 | int ii; | ||
168 | 646 | 662 | ||
169 | 647 | uint64_t value= 0xdeadbeefdeadcafe; | 663 | uint64_t value= 0xdeadbeefdeadcafe; |
170 | 648 | storage_command(&cmd, cc, key, strlen(key), &value, sizeof (value), 0, 0); | 664 | storage_command(&cmd, cc, key, strlen(key), &value, sizeof (value), 0, 0); |
171 | 649 | 665 | ||
172 | 650 | /* set should always work */ | 666 | /* set should always work */ |
174 | 651 | for (int ii= 0; ii < 10; ii++) | 667 | for (ii= 0; ii < 10; ii++) |
175 | 652 | { | 668 | { |
176 | 653 | if (ii == 0) | 669 | if (ii == 0) |
177 | 654 | execute(send_packet(&cmd)); | 670 | execute(send_packet(&cmd)); |
178 | @@ -716,12 +732,13 @@ | |||
179 | 716 | { | 732 | { |
180 | 717 | command cmd; | 733 | command cmd; |
181 | 718 | response rsp; | 734 | response rsp; |
182 | 735 | int ii; | ||
183 | 719 | uint64_t value= 0xdeadbeefdeadcafe; | 736 | uint64_t value= 0xdeadbeefdeadcafe; |
184 | 720 | storage_command(&cmd, cc, key, strlen(key), &value, sizeof (value), 0, 0); | 737 | storage_command(&cmd, cc, key, strlen(key), &value, sizeof (value), 0, 0); |
185 | 721 | 738 | ||
186 | 722 | /* first add should work, rest of them should fail (even with cas | 739 | /* first add should work, rest of them should fail (even with cas |
187 | 723 | as wildcard */ | 740 | as wildcard */ |
189 | 724 | for (int ii=0; ii < 10; ii++) | 741 | for (ii=0; ii < 10; ii++) |
190 | 725 | { | 742 | { |
191 | 726 | if (ii == 0) | 743 | if (ii == 0) |
192 | 727 | execute(send_packet(&cmd)); | 744 | execute(send_packet(&cmd)); |
193 | @@ -775,12 +792,13 @@ | |||
194 | 775 | { | 792 | { |
195 | 776 | command cmd; | 793 | command cmd; |
196 | 777 | response rsp; | 794 | response rsp; |
197 | 795 | int ii; | ||
198 | 778 | uint64_t value= 0xdeadbeefdeadcafe; | 796 | uint64_t value= 0xdeadbeefdeadcafe; |
199 | 779 | storage_command(&cmd, cc, key, strlen(key), &value, sizeof (value), 0, 0); | 797 | storage_command(&cmd, cc, key, strlen(key), &value, sizeof (value), 0, 0); |
200 | 780 | 798 | ||
201 | 781 | /* first replace should fail, successive should succeed (when the | 799 | /* first replace should fail, successive should succeed (when the |
202 | 782 | item is added! */ | 800 | item is added! */ |
204 | 783 | for (int ii= 0; ii < 10; ii++) | 801 | for (ii= 0; ii < 10; ii++) |
205 | 784 | { | 802 | { |
206 | 785 | if (ii == 0) | 803 | if (ii == 0) |
207 | 786 | execute(send_packet(&cmd)); | 804 | execute(send_packet(&cmd)); |
208 | @@ -931,9 +949,9 @@ | |||
209 | 931 | { | 949 | { |
210 | 932 | command cmd; | 950 | command cmd; |
211 | 933 | response rsp; | 951 | response rsp; |
212 | 952 | uint64_t ii; | ||
213 | 934 | arithmetic_command(&cmd, cc, key, strlen(key), 1, 0, 0); | 953 | arithmetic_command(&cmd, cc, key, strlen(key), 1, 0, 0); |
216 | 935 | 954 | ||
215 | 936 | uint64_t ii; | ||
217 | 937 | for (ii= 0; ii < 10; ++ii) | 955 | for (ii= 0; ii < 10; ++ii) |
218 | 938 | { | 956 | { |
219 | 939 | if (ii == 0) | 957 | if (ii == 0) |
220 | @@ -969,9 +987,9 @@ | |||
221 | 969 | { | 987 | { |
222 | 970 | command cmd; | 988 | command cmd; |
223 | 971 | response rsp; | 989 | response rsp; |
224 | 990 | int ii; | ||
225 | 972 | arithmetic_command(&cmd, cc, key, strlen(key), 1, 9, 0); | 991 | arithmetic_command(&cmd, cc, key, strlen(key), 1, 9, 0); |
228 | 973 | 992 | ||
227 | 974 | int ii; | ||
229 | 975 | for (ii= 9; ii > -1; --ii) | 993 | for (ii= 9; ii > -1; --ii) |
230 | 976 | { | 994 | { |
231 | 977 | if (ii == 9) | 995 | if (ii == 9) |
232 | @@ -1038,8 +1056,9 @@ | |||
233 | 1038 | { | 1056 | { |
234 | 1039 | command cmd; | 1057 | command cmd; |
235 | 1040 | response rsp; | 1058 | response rsp; |
236 | 1059 | int ii; | ||
237 | 1041 | 1060 | ||
239 | 1042 | for (int ii= 0; ii < 2; ++ii) | 1061 | for (ii= 0; ii < 2; ++ii) |
240 | 1043 | { | 1062 | { |
241 | 1044 | execute(binary_set_item(key, key)); | 1063 | execute(binary_set_item(key, key)); |
242 | 1045 | flush_command(&cmd, cc, 0, ii == 0); | 1064 | flush_command(&cmd, cc, 0, ii == 0); |
243 | @@ -1200,6 +1219,8 @@ | |||
244 | 1200 | 1219 | ||
245 | 1201 | static enum test_return test_ascii_quit(void) | 1220 | static enum test_return test_ascii_quit(void) |
246 | 1202 | { | 1221 | { |
247 | 1222 | char buffer[80]; | ||
248 | 1223 | |||
249 | 1203 | /* Verify that quit handles unknown options */ | 1224 | /* Verify that quit handles unknown options */ |
250 | 1204 | execute(send_string("quit foo bar\r\n")); | 1225 | execute(send_string("quit foo bar\r\n")); |
251 | 1205 | execute(receive_error_response()); | 1226 | execute(receive_error_response()); |
252 | @@ -1212,7 +1233,6 @@ | |||
253 | 1212 | execute(send_string("quit\r\n")); | 1233 | execute(send_string("quit\r\n")); |
254 | 1213 | 1234 | ||
255 | 1214 | /* Socket should be closed now, read should return 0 */ | 1235 | /* Socket should be closed now, read should return 0 */ |
256 | 1215 | char buffer[80]; | ||
257 | 1216 | verify(timeout_io_op(sock, POLLIN, buffer, sizeof(buffer)) == 0); | 1236 | verify(timeout_io_op(sock, POLLIN, buffer, sizeof(buffer)) == 0); |
258 | 1217 | return TEST_PASS_RECONNECT; | 1237 | return TEST_PASS_RECONNECT; |
259 | 1218 | 1238 | ||
260 | @@ -1220,6 +1240,8 @@ | |||
261 | 1220 | 1240 | ||
262 | 1221 | static enum test_return test_ascii_version(void) | 1241 | static enum test_return test_ascii_version(void) |
263 | 1222 | { | 1242 | { |
264 | 1243 | char buffer[256]; | ||
265 | 1244 | |||
266 | 1223 | /* Verify that version command handles unknown options */ | 1245 | /* Verify that version command handles unknown options */ |
267 | 1224 | execute(send_string("version foo bar\r\n")); | 1246 | execute(send_string("version foo bar\r\n")); |
268 | 1225 | execute(receive_error_response()); | 1247 | execute(receive_error_response()); |
269 | @@ -1230,7 +1252,7 @@ | |||
270 | 1230 | 1252 | ||
271 | 1231 | /* Verify that verify works */ | 1253 | /* Verify that verify works */ |
272 | 1232 | execute(send_string("version\r\n")); | 1254 | execute(send_string("version\r\n")); |
274 | 1233 | char buffer[256]; | 1255 | |
275 | 1234 | execute(receive_line(buffer, sizeof(buffer))); | 1256 | execute(receive_line(buffer, sizeof(buffer))); |
276 | 1235 | verify(strncmp(buffer, "VERSION ", 8) == 0); | 1257 | verify(strncmp(buffer, "VERSION ", 8) == 0); |
277 | 1236 | 1258 | ||
278 | @@ -1318,18 +1340,20 @@ | |||
279 | 1318 | 1340 | ||
280 | 1319 | static enum test_return ascii_get_unknown_value(char **key, char **value, ssize_t *ndata) | 1341 | static enum test_return ascii_get_unknown_value(char **key, char **value, ssize_t *ndata) |
281 | 1320 | { | 1342 | { |
282 | 1343 | char *end, *ptr; | ||
283 | 1344 | unsigned long val; | ||
284 | 1321 | char buffer[1024]; | 1345 | char buffer[1024]; |
285 | 1322 | 1346 | ||
286 | 1323 | execute(receive_line(buffer, sizeof(buffer))); | 1347 | execute(receive_line(buffer, sizeof(buffer))); |
287 | 1324 | verify(strncmp(buffer, "VALUE ", 6) == 0); | 1348 | verify(strncmp(buffer, "VALUE ", 6) == 0); |
289 | 1325 | char *end= strchr(buffer + 6, ' '); | 1349 | end= strchr(buffer + 6, ' '); |
290 | 1326 | verify(end != NULL); | 1350 | verify(end != NULL); |
291 | 1327 | *end= '\0'; | 1351 | *end= '\0'; |
292 | 1328 | *key= strdup(buffer + 6); | 1352 | *key= strdup(buffer + 6); |
293 | 1329 | verify(*key != NULL); | 1353 | verify(*key != NULL); |
295 | 1330 | char *ptr= end + 1; | 1354 | ptr= end + 1; |
296 | 1331 | 1355 | ||
298 | 1332 | unsigned long val= strtoul(ptr, &end, 10); /* flags */ | 1356 | val= strtoul(ptr, &end, 10); /* flags */ |
299 | 1333 | verify(ptr != end); | 1357 | verify(ptr != end); |
300 | 1334 | verify(val == 0); | 1358 | verify(val == 0); |
301 | 1335 | verify(end != NULL); | 1359 | verify(end != NULL); |
302 | @@ -1353,6 +1377,8 @@ | |||
303 | 1353 | 1377 | ||
304 | 1354 | static enum test_return ascii_get_value(const char *key, const char *value) | 1378 | static enum test_return ascii_get_value(const char *key, const char *value) |
305 | 1355 | { | 1379 | { |
306 | 1380 | char *ptr, *end; | ||
307 | 1381 | unsigned long val; | ||
308 | 1356 | 1382 | ||
309 | 1357 | char buffer[1024]; | 1383 | char buffer[1024]; |
310 | 1358 | size_t datasize= strlen(value); | 1384 | size_t datasize= strlen(value); |
311 | @@ -1361,10 +1387,9 @@ | |||
312 | 1361 | execute(receive_line(buffer, sizeof(buffer))); | 1387 | execute(receive_line(buffer, sizeof(buffer))); |
313 | 1362 | verify(strncmp(buffer, "VALUE ", 6) == 0); | 1388 | verify(strncmp(buffer, "VALUE ", 6) == 0); |
314 | 1363 | verify(strncmp(buffer + 6, key, strlen(key)) == 0); | 1389 | verify(strncmp(buffer + 6, key, strlen(key)) == 0); |
317 | 1364 | char *ptr= buffer + 6 + strlen(key) + 1; | 1390 | ptr= buffer + 6 + strlen(key) + 1; |
316 | 1365 | char *end; | ||
318 | 1366 | 1391 | ||
320 | 1367 | unsigned long val= strtoul(ptr, &end, 10); /* flags */ | 1392 | val= strtoul(ptr, &end, 10); /* flags */ |
321 | 1368 | verify(ptr != end); | 1393 | verify(ptr != end); |
322 | 1369 | verify(val == 0); | 1394 | verify(val == 0); |
323 | 1370 | verify(end != NULL); | 1395 | verify(end != NULL); |
324 | @@ -1409,6 +1434,8 @@ | |||
325 | 1409 | static enum test_return ascii_gets_value(const char *key, const char *value, | 1434 | static enum test_return ascii_gets_value(const char *key, const char *value, |
326 | 1410 | unsigned long *cas) | 1435 | unsigned long *cas) |
327 | 1411 | { | 1436 | { |
328 | 1437 | char *ptr, *end; | ||
329 | 1438 | unsigned long val; | ||
330 | 1412 | 1439 | ||
331 | 1413 | char buffer[1024]; | 1440 | char buffer[1024]; |
332 | 1414 | size_t datasize= strlen(value); | 1441 | size_t datasize= strlen(value); |
333 | @@ -1417,10 +1444,9 @@ | |||
334 | 1417 | execute(receive_line(buffer, sizeof(buffer))); | 1444 | execute(receive_line(buffer, sizeof(buffer))); |
335 | 1418 | verify(strncmp(buffer, "VALUE ", 6) == 0); | 1445 | verify(strncmp(buffer, "VALUE ", 6) == 0); |
336 | 1419 | verify(strncmp(buffer + 6, key, strlen(key)) == 0); | 1446 | verify(strncmp(buffer + 6, key, strlen(key)) == 0); |
341 | 1420 | char *ptr= buffer + 6 + strlen(key) + 1; | 1447 | ptr= buffer + 6 + strlen(key) + 1; |
342 | 1421 | char *end; | 1448 | |
343 | 1422 | 1449 | val= strtoul(ptr, &end, 10); /* flags */ | |
340 | 1423 | unsigned long val= strtoul(ptr, &end, 10); /* flags */ | ||
344 | 1424 | verify(ptr != end); | 1450 | verify(ptr != end); |
345 | 1425 | verify(val == 0); | 1451 | verify(val == 0); |
346 | 1426 | verify(end != NULL); | 1452 | verify(end != NULL); |
347 | @@ -1555,6 +1581,8 @@ | |||
348 | 1555 | 1581 | ||
349 | 1556 | static enum test_return test_ascii_delete_impl(const char *key, bool noreply) | 1582 | static enum test_return test_ascii_delete_impl(const char *key, bool noreply) |
350 | 1557 | { | 1583 | { |
351 | 1584 | char buffer[1024]; | ||
352 | 1585 | |||
353 | 1558 | execute(ascii_set_item(key, "value")); | 1586 | execute(ascii_set_item(key, "value")); |
354 | 1559 | 1587 | ||
355 | 1560 | execute(send_string("delete\r\n")); | 1588 | execute(send_string("delete\r\n")); |
356 | @@ -1562,8 +1590,7 @@ | |||
357 | 1562 | /* BUG: the server accepts delete a b */ | 1590 | /* BUG: the server accepts delete a b */ |
358 | 1563 | execute(send_string("delete a b c d e\r\n")); | 1591 | execute(send_string("delete a b c d e\r\n")); |
359 | 1564 | execute(receive_error_response()); | 1592 | execute(receive_error_response()); |
362 | 1565 | 1593 | ||
361 | 1566 | char buffer[1024]; | ||
363 | 1567 | sprintf(buffer, "delete %s%s\r\n", key, noreply ? " noreply" : ""); | 1594 | sprintf(buffer, "delete %s%s\r\n", key, noreply ? " noreply" : ""); |
364 | 1568 | execute(send_string(buffer)); | 1595 | execute(send_string(buffer)); |
365 | 1569 | 1596 | ||
366 | @@ -1606,11 +1633,13 @@ | |||
367 | 1606 | 1633 | ||
368 | 1607 | static enum test_return test_ascii_gets(void) | 1634 | static enum test_return test_ascii_gets(void) |
369 | 1608 | { | 1635 | { |
370 | 1636 | unsigned long cas; | ||
371 | 1637 | |||
372 | 1609 | execute(ascii_set_item("test_ascii_gets", "value")); | 1638 | execute(ascii_set_item("test_ascii_gets", "value")); |
373 | 1610 | 1639 | ||
374 | 1611 | execute(send_string("gets\r\n")); | 1640 | execute(send_string("gets\r\n")); |
375 | 1612 | execute(receive_error_response()); | 1641 | execute(receive_error_response()); |
377 | 1613 | unsigned long cas; | 1642 | |
378 | 1614 | execute(ascii_gets_item("test_ascii_gets", "value", true, &cas)); | 1643 | execute(ascii_gets_item("test_ascii_gets", "value", true, &cas)); |
379 | 1615 | execute(ascii_gets_item("test_ascii_gets_notfound", "value", false, &cas)); | 1644 | execute(ascii_gets_item("test_ascii_gets_notfound", "value", false, &cas)); |
380 | 1616 | 1645 | ||
381 | @@ -1619,7 +1648,11 @@ | |||
382 | 1619 | 1648 | ||
383 | 1620 | static enum test_return test_ascii_mget(void) | 1649 | static enum test_return test_ascii_mget(void) |
384 | 1621 | { | 1650 | { |
385 | 1651 | uint32_t x; | ||
386 | 1622 | const uint32_t nkeys= 5; | 1652 | const uint32_t nkeys= 5; |
387 | 1653 | char *returned[5]; | ||
388 | 1654 | char buffer[5]; | ||
389 | 1655 | |||
390 | 1623 | const char * const keys[]= { | 1656 | const char * const keys[]= { |
391 | 1624 | "test_ascii_mget1", | 1657 | "test_ascii_mget1", |
392 | 1625 | "test_ascii_mget2", | 1658 | "test_ascii_mget2", |
393 | @@ -1629,7 +1662,7 @@ | |||
394 | 1629 | "test_ascii_mget6" | 1662 | "test_ascii_mget6" |
395 | 1630 | }; | 1663 | }; |
396 | 1631 | 1664 | ||
398 | 1632 | for (uint32_t x= 0; x < nkeys; ++x) | 1665 | for (x= 0; x < nkeys; ++x) |
399 | 1633 | execute(ascii_set_item(keys[x], "value")); | 1666 | execute(ascii_set_item(keys[x], "value")); |
400 | 1634 | 1667 | ||
401 | 1635 | /* Ask for a key that doesn't exist as well */ | 1668 | /* Ask for a key that doesn't exist as well */ |
402 | @@ -1637,9 +1670,7 @@ | |||
403 | 1637 | "test_ascii_mget4 test_ascii_mget5 " | 1670 | "test_ascii_mget4 test_ascii_mget5 " |
404 | 1638 | "test_ascii_mget6\r\n")); | 1671 | "test_ascii_mget6\r\n")); |
405 | 1639 | 1672 | ||
409 | 1640 | char *returned[nkeys]; | 1673 | for (x= 0; x < nkeys; ++x) |
407 | 1641 | |||
408 | 1642 | for (uint32_t x= 0; x < nkeys; ++x) | ||
410 | 1643 | { | 1674 | { |
411 | 1644 | ssize_t nbytes = 0; | 1675 | ssize_t nbytes = 0; |
412 | 1645 | char *v= NULL; | 1676 | char *v= NULL; |
413 | @@ -1648,16 +1679,16 @@ | |||
414 | 1648 | verify(memcmp(v, "value", 5) == 0); | 1679 | verify(memcmp(v, "value", 5) == 0); |
415 | 1649 | free(v); | 1680 | free(v); |
416 | 1650 | } | 1681 | } |
419 | 1651 | 1682 | ||
418 | 1652 | char buffer[5]; | ||
420 | 1653 | execute(retry_read(buffer, 5)); | 1683 | execute(retry_read(buffer, 5)); |
421 | 1654 | verify(memcmp(buffer, "END\r\n", 5) == 0); | 1684 | verify(memcmp(buffer, "END\r\n", 5) == 0); |
422 | 1655 | 1685 | ||
423 | 1656 | /* verify that we got all the keys we expected */ | 1686 | /* verify that we got all the keys we expected */ |
425 | 1657 | for (uint32_t x= 0; x < nkeys; ++x) | 1687 | for (x= 0; x < nkeys; ++x) |
426 | 1658 | { | 1688 | { |
427 | 1689 | uint32_t y; | ||
428 | 1659 | bool found= false; | 1690 | bool found= false; |
430 | 1660 | for (uint32_t y= 0; y < nkeys; ++y) | 1691 | for (y= 0; y < nkeys; ++y) |
431 | 1661 | { | 1692 | { |
432 | 1662 | if (strcmp(keys[x], returned[y]) == 0) | 1693 | if (strcmp(keys[x], returned[y]) == 0) |
433 | 1663 | { | 1694 | { |
434 | @@ -1668,7 +1699,7 @@ | |||
435 | 1668 | verify(found); | 1699 | verify(found); |
436 | 1669 | } | 1700 | } |
437 | 1670 | 1701 | ||
439 | 1671 | for (uint32_t x= 0; x < nkeys; ++x) | 1702 | for (x= 0; x < nkeys; ++x) |
440 | 1672 | free(returned[x]); | 1703 | free(returned[x]); |
441 | 1673 | 1704 | ||
442 | 1674 | return TEST_PASS; | 1705 | return TEST_PASS; |
443 | @@ -1676,11 +1707,12 @@ | |||
444 | 1676 | 1707 | ||
445 | 1677 | static enum test_return test_ascii_incr_impl(const char* key, bool noreply) | 1708 | static enum test_return test_ascii_incr_impl(const char* key, bool noreply) |
446 | 1678 | { | 1709 | { |
447 | 1710 | int x; | ||
448 | 1679 | char cmd[300]; | 1711 | char cmd[300]; |
449 | 1680 | sprintf(cmd, "incr %s 1%s\r\n", key, noreply ? " noreply" : ""); | 1712 | sprintf(cmd, "incr %s 1%s\r\n", key, noreply ? " noreply" : ""); |
450 | 1681 | 1713 | ||
451 | 1682 | execute(ascii_set_item(key, "0")); | 1714 | execute(ascii_set_item(key, "0")); |
453 | 1683 | for (int x= 1; x < 11; ++x) | 1715 | for (x= 1; x < 11; ++x) |
454 | 1684 | { | 1716 | { |
455 | 1685 | execute(send_string(cmd)); | 1717 | execute(send_string(cmd)); |
456 | 1686 | 1718 | ||
457 | @@ -1688,9 +1720,10 @@ | |||
458 | 1688 | execute(test_ascii_version()); | 1720 | execute(test_ascii_version()); |
459 | 1689 | else | 1721 | else |
460 | 1690 | { | 1722 | { |
461 | 1723 | int val; | ||
462 | 1691 | char buffer[80]; | 1724 | char buffer[80]; |
463 | 1692 | execute(receive_line(buffer, sizeof(buffer))); | 1725 | execute(receive_line(buffer, sizeof(buffer))); |
465 | 1693 | int val= atoi(buffer); | 1726 | val= atoi(buffer); |
466 | 1694 | verify(val == x); | 1727 | verify(val == x); |
467 | 1695 | } | 1728 | } |
468 | 1696 | } | 1729 | } |
469 | @@ -1712,11 +1745,12 @@ | |||
470 | 1712 | 1745 | ||
471 | 1713 | static enum test_return test_ascii_decr_impl(const char* key, bool noreply) | 1746 | static enum test_return test_ascii_decr_impl(const char* key, bool noreply) |
472 | 1714 | { | 1747 | { |
473 | 1748 | int x; | ||
474 | 1715 | char cmd[300]; | 1749 | char cmd[300]; |
475 | 1716 | sprintf(cmd, "decr %s 1%s\r\n", key, noreply ? " noreply" : ""); | 1750 | sprintf(cmd, "decr %s 1%s\r\n", key, noreply ? " noreply" : ""); |
476 | 1717 | 1751 | ||
477 | 1718 | execute(ascii_set_item(key, "9")); | 1752 | execute(ascii_set_item(key, "9")); |
479 | 1719 | for (int x= 8; x > -1; --x) | 1753 | for (x= 8; x > -1; --x) |
480 | 1720 | { | 1754 | { |
481 | 1721 | execute(send_string(cmd)); | 1755 | execute(send_string(cmd)); |
482 | 1722 | 1756 | ||
483 | @@ -1724,9 +1758,10 @@ | |||
484 | 1724 | execute(test_ascii_version()); | 1758 | execute(test_ascii_version()); |
485 | 1725 | else | 1759 | else |
486 | 1726 | { | 1760 | { |
487 | 1761 | int val; | ||
488 | 1727 | char buffer[80]; | 1762 | char buffer[80]; |
489 | 1728 | execute(receive_line(buffer, sizeof(buffer))); | 1763 | execute(receive_line(buffer, sizeof(buffer))); |
491 | 1729 | int val= atoi(buffer); | 1764 | val= atoi(buffer); |
492 | 1730 | verify(val == x); | 1765 | verify(val == x); |
493 | 1731 | } | 1766 | } |
494 | 1732 | } | 1767 | } |
495 | @@ -1801,6 +1836,7 @@ | |||
496 | 1801 | bool noreply) | 1836 | bool noreply) |
497 | 1802 | { | 1837 | { |
498 | 1803 | const char *value; | 1838 | const char *value; |
499 | 1839 | char cmd[400]; | ||
500 | 1804 | 1840 | ||
501 | 1805 | if (append) | 1841 | if (append) |
502 | 1806 | value="hello"; | 1842 | value="hello"; |
503 | @@ -1813,8 +1849,7 @@ | |||
504 | 1813 | value=" world"; | 1849 | value=" world"; |
505 | 1814 | else | 1850 | else |
506 | 1815 | value="hello"; | 1851 | value="hello"; |
509 | 1816 | 1852 | ||
508 | 1817 | char cmd[400]; | ||
510 | 1818 | sprintf(cmd, "%s %s 0 0 %u%s\r\n%s\r\n", | 1853 | sprintf(cmd, "%s %s 0 0 %u%s\r\n%s\r\n", |
511 | 1819 | append ? "append" : "prepend", | 1854 | append ? "append" : "prepend", |
512 | 1820 | key, (unsigned int)strlen(value), noreply ? " noreply" : "", | 1855 | key, (unsigned int)strlen(value), noreply ? " noreply" : "", |
513 | @@ -1864,10 +1899,12 @@ | |||
514 | 1864 | 1899 | ||
515 | 1865 | static enum test_return test_ascii_stat(void) | 1900 | static enum test_return test_ascii_stat(void) |
516 | 1866 | { | 1901 | { |
517 | 1902 | char buffer[1024]; | ||
518 | 1903 | |||
519 | 1867 | execute(send_string("stats noreply\r\n")); | 1904 | execute(send_string("stats noreply\r\n")); |
520 | 1868 | execute(receive_error_response()); | 1905 | execute(receive_error_response()); |
521 | 1869 | execute(send_string("stats\r\n")); | 1906 | execute(send_string("stats\r\n")); |
523 | 1870 | char buffer[1024]; | 1907 | |
524 | 1871 | do { | 1908 | do { |
525 | 1872 | execute(receive_line(buffer, sizeof(buffer))); | 1909 | execute(receive_line(buffer, sizeof(buffer))); |
526 | 1873 | } while (strcmp(buffer, "END\r\n") != 0); | 1910 | } while (strcmp(buffer, "END\r\n") != 0); |
527 | @@ -1948,7 +1985,7 @@ | |||
528 | 1948 | int failed= 0; | 1985 | int failed= 0; |
529 | 1949 | const char *hostname= "localhost"; | 1986 | const char *hostname= "localhost"; |
530 | 1950 | const char *port= "11211"; | 1987 | const char *port= "11211"; |
532 | 1951 | int cmd; | 1988 | int cmd, ii; |
533 | 1952 | bool prompt= false; | 1989 | bool prompt= false; |
534 | 1953 | const char *testname= NULL; | 1990 | const char *testname= NULL; |
535 | 1954 | 1991 | ||
536 | @@ -2000,8 +2037,11 @@ | |||
537 | 2000 | return 1; | 2037 | return 1; |
538 | 2001 | } | 2038 | } |
539 | 2002 | 2039 | ||
541 | 2003 | for (int ii= 0; testcases[ii].description != NULL; ++ii) | 2040 | for (ii= 0; testcases[ii].description != NULL; ++ii) |
542 | 2004 | { | 2041 | { |
543 | 2042 | bool reconnect= false; | ||
544 | 2043 | enum test_return ret; | ||
545 | 2044 | |||
546 | 2005 | if (testname != NULL && strcmp(testcases[ii].description, testname) != 0) | 2045 | if (testname != NULL && strcmp(testcases[ii].description, testname) != 0) |
547 | 2006 | continue; | 2046 | continue; |
548 | 2007 | 2047 | ||
549 | @@ -2011,8 +2051,10 @@ | |||
550 | 2011 | 2051 | ||
551 | 2012 | if (prompt) | 2052 | if (prompt) |
552 | 2013 | { | 2053 | { |
553 | 2054 | char buffer[80] = {0}; | ||
554 | 2055 | |||
555 | 2014 | fprintf(stdout, "\nPress <return> when you are ready? "); | 2056 | fprintf(stdout, "\nPress <return> when you are ready? "); |
557 | 2015 | char buffer[80] = {0}; | 2057 | |
558 | 2016 | if (fgets(buffer, sizeof(buffer), stdin) != NULL) { | 2058 | if (fgets(buffer, sizeof(buffer), stdin) != NULL) { |
559 | 2017 | if (strncmp(buffer, "skip", 4) == 0) | 2059 | if (strncmp(buffer, "skip", 4) == 0) |
560 | 2018 | { | 2060 | { |
561 | @@ -2029,8 +2071,8 @@ | |||
562 | 2029 | fflush(stdout); | 2071 | fflush(stdout); |
563 | 2030 | } | 2072 | } |
564 | 2031 | 2073 | ||
567 | 2032 | bool reconnect= false; | 2074 | reconnect= false; |
568 | 2033 | enum test_return ret= testcases[ii].function(); | 2075 | ret= testcases[ii].function(); |
569 | 2034 | if (ret == TEST_FAIL) | 2076 | if (ret == TEST_FAIL) |
570 | 2035 | { | 2077 | { |
571 | 2036 | reconnect= true; | 2078 | reconnect= true; |
572 | 2037 | 2079 | ||
573 | === modified file 'clients/memcat.c' | |||
574 | --- clients/memcat.c 2010-07-27 22:38:51 +0000 | |||
575 | +++ clients/memcat.c 2011-01-13 03:40:43 +0000 | |||
576 | @@ -11,10 +11,13 @@ | |||
577 | 11 | 11 | ||
578 | 12 | #include "config.h" | 12 | #include "config.h" |
579 | 13 | 13 | ||
580 | 14 | #ifndef WIN32 | ||
581 | 15 | # include <unistd.h> | ||
582 | 16 | #endif | ||
583 | 17 | |||
584 | 14 | #include <stdio.h> | 18 | #include <stdio.h> |
585 | 15 | #include <inttypes.h> | 19 | #include <inttypes.h> |
586 | 16 | #include <string.h> | 20 | #include <string.h> |
587 | 17 | #include <unistd.h> | ||
588 | 18 | #include <getopt.h> | 21 | #include <getopt.h> |
589 | 19 | #include <libmemcached/memcached.h> | 22 | #include <libmemcached/memcached.h> |
590 | 20 | 23 | ||
591 | @@ -95,8 +98,8 @@ | |||
592 | 95 | { | 98 | { |
593 | 96 | if (opt_verbose) | 99 | if (opt_verbose) |
594 | 97 | { | 100 | { |
597 | 98 | printf("key: %s\nflags: %x\nlength: %zu\nvalue: ", | 101 | printf("key: %s\nflags: %x\nlength: %lu\nvalue: ", |
598 | 99 | argv[optind], flags, string_length); | 102 | argv[optind], flags, (unsigned long)string_length); |
599 | 100 | } | 103 | } |
600 | 101 | 104 | ||
601 | 102 | if (opt_file) | 105 | if (opt_file) |
602 | @@ -115,7 +118,7 @@ | |||
603 | 115 | written= fwrite(string, 1, string_length, fp); | 118 | written= fwrite(string, 1, string_length, fp); |
604 | 116 | if (written != string_length) | 119 | if (written != string_length) |
605 | 117 | { | 120 | { |
607 | 118 | fprintf(stderr, "error writing file (written %zu, should be %zu)\n", written, string_length); | 121 | fprintf(stderr, "error writing file (written %lu, should be %lu)\n", (unsigned long) written, (unsigned long) string_length); |
608 | 119 | return_code= -1; | 122 | return_code= -1; |
609 | 120 | break; | 123 | break; |
610 | 121 | } | 124 | } |
611 | 122 | 125 | ||
612 | === modified file 'clients/memcp.c' | |||
613 | --- clients/memcp.c 2010-07-27 22:38:51 +0000 | |||
614 | +++ clients/memcp.c 2011-01-13 03:40:43 +0000 | |||
615 | @@ -11,19 +11,22 @@ | |||
616 | 11 | 11 | ||
617 | 12 | #include "config.h" | 12 | #include "config.h" |
618 | 13 | 13 | ||
619 | 14 | #ifndef WIN32 | ||
620 | 15 | # include <unistd.h> | ||
621 | 16 | # include <sys/types.h> | ||
622 | 17 | # include <sys/types.h> | ||
623 | 18 | # include <strings.h> | ||
624 | 19 | #endif | ||
625 | 20 | |||
626 | 14 | #include <stdio.h> | 21 | #include <stdio.h> |
627 | 15 | #include <stdlib.h> | 22 | #include <stdlib.h> |
628 | 16 | #include <inttypes.h> | 23 | #include <inttypes.h> |
629 | 17 | #include <unistd.h> | ||
630 | 18 | #include <getopt.h> | 24 | #include <getopt.h> |
631 | 19 | #include <sys/types.h> | ||
632 | 20 | #include <sys/stat.h> | ||
633 | 21 | #include <sys/types.h> | ||
634 | 22 | #include <fcntl.h> | 25 | #include <fcntl.h> |
635 | 23 | #include <errno.h> | 26 | #include <errno.h> |
636 | 24 | #include <strings.h> | ||
637 | 25 | #include <string.h> | 27 | #include <string.h> |
638 | 26 | #include <sys/types.h> | 28 | #include <sys/types.h> |
639 | 29 | #include <sys/stat.h> | ||
640 | 27 | #include <stdlib.h> | 30 | #include <stdlib.h> |
641 | 28 | #include <limits.h> | 31 | #include <limits.h> |
642 | 29 | 32 | ||
643 | @@ -147,9 +150,9 @@ | |||
644 | 147 | if (opt_verbose) | 150 | if (opt_verbose) |
645 | 148 | { | 151 | { |
646 | 149 | static const char *opstr[] = { "set", "add", "replace" }; | 152 | static const char *opstr[] = { "set", "add", "replace" }; |
648 | 150 | printf("op: %s\nsource file: %s\nlength: %zu\n" | 153 | printf("op: %s\nsource file: %s\nlength: %lu\n" |
649 | 151 | "key: %s\nflags: %x\nexpires: %llu\n", | 154 | "key: %s\nflags: %x\nexpires: %llu\n", |
651 | 152 | opstr[opt_method - OPT_SET], argv[optind], (size_t)sbuf.st_size, | 155 | opstr[opt_method - OPT_SET], argv[optind], (unsigned long)sbuf.st_size, |
652 | 153 | ptr, opt_flags, (unsigned long long)opt_expires); | 156 | ptr, opt_flags, (unsigned long long)opt_expires); |
653 | 154 | } | 157 | } |
654 | 155 | 158 | ||
655 | 156 | 159 | ||
656 | === modified file 'clients/memdump.c' | |||
657 | --- clients/memdump.c 2010-06-29 06:39:40 +0000 | |||
658 | +++ clients/memdump.c 2011-01-13 03:40:43 +0000 | |||
659 | @@ -11,17 +11,20 @@ | |||
660 | 11 | 11 | ||
661 | 12 | #include "config.h" | 12 | #include "config.h" |
662 | 13 | 13 | ||
663 | 14 | #ifndef WIN32 | ||
664 | 15 | # include <unistd.h> | ||
665 | 16 | # include <strings.h> | ||
666 | 17 | #endif | ||
667 | 18 | |||
668 | 14 | #include <stdio.h> | 19 | #include <stdio.h> |
669 | 15 | #include <stdlib.h> | 20 | #include <stdlib.h> |
670 | 16 | #include <inttypes.h> | 21 | #include <inttypes.h> |
671 | 17 | #include <unistd.h> | ||
672 | 18 | #include <getopt.h> | 22 | #include <getopt.h> |
673 | 19 | #include <sys/types.h> | 23 | #include <sys/types.h> |
674 | 20 | #include <sys/stat.h> | 24 | #include <sys/stat.h> |
675 | 21 | #include <sys/types.h> | 25 | #include <sys/types.h> |
676 | 22 | #include <fcntl.h> | 26 | #include <fcntl.h> |
677 | 23 | #include <errno.h> | 27 | #include <errno.h> |
678 | 24 | #include <strings.h> | ||
679 | 25 | #include <string.h> | 28 | #include <string.h> |
680 | 26 | 29 | ||
681 | 27 | #include <libmemcached/memcached.h> | 30 | #include <libmemcached/memcached.h> |
682 | 28 | 31 | ||
683 | === modified file 'clients/memerror.c' | |||
684 | --- clients/memerror.c 2010-06-29 06:39:40 +0000 | |||
685 | +++ clients/memerror.c 2011-01-13 03:40:43 +0000 | |||
686 | @@ -10,10 +10,13 @@ | |||
687 | 10 | */ | 10 | */ |
688 | 11 | #include "config.h" | 11 | #include "config.h" |
689 | 12 | 12 | ||
690 | 13 | #ifndef WIN32 | ||
691 | 14 | # include <unistd.h> | ||
692 | 15 | #endif | ||
693 | 16 | |||
694 | 13 | #include <stdio.h> | 17 | #include <stdio.h> |
695 | 14 | #include <inttypes.h> | 18 | #include <inttypes.h> |
696 | 15 | #include <string.h> | 19 | #include <string.h> |
697 | 16 | #include <unistd.h> | ||
698 | 17 | #include <getopt.h> | 20 | #include <getopt.h> |
699 | 18 | #include <stdlib.h> | 21 | #include <stdlib.h> |
700 | 19 | #include <libmemcached/memcached.h> | 22 | #include <libmemcached/memcached.h> |
701 | 20 | 23 | ||
702 | === modified file 'clients/memflush.c' | |||
703 | --- clients/memflush.c 2010-06-29 06:39:40 +0000 | |||
704 | +++ clients/memflush.c 2011-01-13 03:40:43 +0000 | |||
705 | @@ -9,9 +9,12 @@ | |||
706 | 9 | * | 9 | * |
707 | 10 | */ | 10 | */ |
708 | 11 | #include "config.h" | 11 | #include "config.h" |
709 | 12 | |||
710 | 13 | #ifndef WIN32 | ||
711 | 14 | # include <unistd.h> | ||
712 | 15 | #endif | ||
713 | 12 | 16 | ||
714 | 13 | #include <stdio.h> | 17 | #include <stdio.h> |
715 | 14 | #include <unistd.h> | ||
716 | 15 | #include <string.h> | 18 | #include <string.h> |
717 | 16 | #include <getopt.h> | 19 | #include <getopt.h> |
718 | 17 | #include <libmemcached/memcached.h> | 20 | #include <libmemcached/memcached.h> |
719 | 18 | 21 | ||
720 | === modified file 'clients/memrm.c' | |||
721 | --- clients/memrm.c 2010-07-27 22:38:51 +0000 | |||
722 | +++ clients/memrm.c 2011-01-13 03:40:43 +0000 | |||
723 | @@ -10,8 +10,11 @@ | |||
724 | 10 | */ | 10 | */ |
725 | 11 | #include "config.h" | 11 | #include "config.h" |
726 | 12 | 12 | ||
727 | 13 | #ifndef WIN32 | ||
728 | 14 | # include <unistd.h> | ||
729 | 15 | #endif | ||
730 | 16 | |||
731 | 13 | #include <stdio.h> | 17 | #include <stdio.h> |
732 | 14 | #include <unistd.h> | ||
733 | 15 | #include <getopt.h> | 18 | #include <getopt.h> |
734 | 16 | #include <libmemcached/memcached.h> | 19 | #include <libmemcached/memcached.h> |
735 | 17 | #include <string.h> | 20 | #include <string.h> |
736 | 18 | 21 | ||
737 | === modified file 'clients/memstat.c' | |||
738 | --- clients/memstat.c 2010-07-28 20:59:36 +0000 | |||
739 | +++ clients/memstat.c 2011-01-13 03:40:43 +0000 | |||
740 | @@ -13,6 +13,10 @@ | |||
741 | 13 | */ | 13 | */ |
742 | 14 | #include "config.h" | 14 | #include "config.h" |
743 | 15 | 15 | ||
744 | 16 | #ifndef WIN32 | ||
745 | 17 | # include <sys/time.h> | ||
746 | 18 | #endif | ||
747 | 19 | |||
748 | 16 | #include <stdio.h> | 20 | #include <stdio.h> |
749 | 17 | #include <sys/types.h> | 21 | #include <sys/types.h> |
750 | 18 | #include <sys/stat.h> | 22 | #include <sys/stat.h> |
751 | @@ -20,7 +24,6 @@ | |||
752 | 20 | #include <fcntl.h> | 24 | #include <fcntl.h> |
753 | 21 | #include <string.h> | 25 | #include <string.h> |
754 | 22 | #include <getopt.h> | 26 | #include <getopt.h> |
755 | 23 | #include <sys/time.h> | ||
756 | 24 | 27 | ||
757 | 25 | #include <libmemcached/memcached.h> | 28 | #include <libmemcached/memcached.h> |
758 | 26 | 29 | ||
759 | @@ -158,9 +161,12 @@ | |||
760 | 158 | else if (strcmp(analyze_mode, "latency") == 0) | 161 | else if (strcmp(analyze_mode, "latency") == 0) |
761 | 159 | { | 162 | { |
762 | 160 | memcached_st **servers; | 163 | memcached_st **servers; |
764 | 161 | uint32_t flags, server_count= memcached_server_count(memc); | 164 | uint32_t x, flags, server_count= memcached_server_count(memc); |
765 | 162 | uint32_t num_of_tests= 32; | 165 | uint32_t num_of_tests= 32; |
766 | 163 | const char *test_key= "libmemcached_test_key"; | 166 | const char *test_key= "libmemcached_test_key"; |
767 | 167 | struct timeval start_time, end_time; | ||
768 | 168 | uint32_t slowest_server= 0; | ||
769 | 169 | long elapsed_time, slowest_time= 0; | ||
770 | 164 | 170 | ||
771 | 165 | servers= malloc(sizeof(memcached_st*) * server_count); | 171 | servers= malloc(sizeof(memcached_st*) * server_count); |
772 | 166 | if (!servers) | 172 | if (!servers) |
773 | @@ -169,7 +175,7 @@ | |||
774 | 169 | return; | 175 | return; |
775 | 170 | } | 176 | } |
776 | 171 | 177 | ||
778 | 172 | for (uint32_t x= 0; x < server_count; x++) | 178 | for (x= 0; x < server_count; x++) |
779 | 173 | { | 179 | { |
780 | 174 | memcached_server_instance_st instance= | 180 | memcached_server_instance_st instance= |
781 | 175 | memcached_server_instance_by_position(memc, x); | 181 | memcached_server_instance_by_position(memc, x); |
782 | @@ -192,17 +198,15 @@ | |||
783 | 192 | } | 198 | } |
784 | 193 | 199 | ||
785 | 194 | printf("Network Latency Test:\n\n"); | 200 | printf("Network Latency Test:\n\n"); |
786 | 195 | struct timeval start_time, end_time; | ||
787 | 196 | uint32_t slowest_server= 0; | ||
788 | 197 | long elapsed_time, slowest_time= 0; | ||
789 | 198 | 201 | ||
791 | 199 | for (uint32_t x= 0; x < server_count; x++) | 202 | for (x= 0; x < server_count; x++) |
792 | 200 | { | 203 | { |
793 | 204 | uint32_t y; | ||
794 | 201 | memcached_server_instance_st instance= | 205 | memcached_server_instance_st instance= |
795 | 202 | memcached_server_instance_by_position(memc, x); | 206 | memcached_server_instance_by_position(memc, x); |
796 | 203 | gettimeofday(&start_time, NULL); | 207 | gettimeofday(&start_time, NULL); |
797 | 204 | 208 | ||
799 | 205 | for (uint32_t y= 0; y < num_of_tests; y++) | 209 | for (y= 0; y < num_of_tests; y++) |
800 | 206 | { | 210 | { |
801 | 207 | size_t vlen; | 211 | size_t vlen; |
802 | 208 | char *val= memcached_get(servers[x], test_key, strlen(test_key), | 212 | char *val= memcached_get(servers[x], test_key, strlen(test_key), |
803 | @@ -250,7 +254,7 @@ | |||
804 | 250 | } | 254 | } |
805 | 251 | printf("\n"); | 255 | printf("\n"); |
806 | 252 | 256 | ||
808 | 253 | for (uint32_t x= 0; x < server_count; x++) | 257 | for (x= 0; x < server_count; x++) |
809 | 254 | memcached_free(servers[x]); | 258 | memcached_free(servers[x]); |
810 | 255 | 259 | ||
811 | 256 | free(servers); | 260 | free(servers); |
812 | 257 | 261 | ||
813 | === modified file 'clients/utilities.c' | |||
814 | --- clients/utilities.c 2010-07-28 20:59:36 +0000 | |||
815 | +++ clients/utilities.c 2011-01-13 03:40:43 +0000 | |||
816 | @@ -1,231 +1,241 @@ | |||
1048 | 1 | /* LibMemcached | 1 | /* LibMemcached |
1049 | 2 | * Copyright (C) 2006-2009 Brian Aker | 2 | * Copyright (C) 2006-2009 Brian Aker |
1050 | 3 | * All rights reserved. | 3 | * All rights reserved. |
1051 | 4 | * | 4 | * |
1052 | 5 | * Use and distribution licensed under the BSD license. See | 5 | * Use and distribution licensed under the BSD license. See |
1053 | 6 | * the COPYING file in the parent directory for full text. | 6 | * the COPYING file in the parent directory for full text. |
1054 | 7 | * | 7 | * |
1055 | 8 | * Summary: | 8 | * Summary: |
1056 | 9 | * | 9 | * |
1057 | 10 | */ | 10 | */ |
1058 | 11 | #include "config.h" | 11 | #include "config.h" |
1059 | 12 | 12 | ||
1060 | 13 | #include <stdio.h> | 13 | #include <stdio.h> |
1061 | 14 | #include <ctype.h> | 14 | #include <ctype.h> |
1062 | 15 | #include <string.h> | 15 | #include <string.h> |
1063 | 16 | #include "utilities.h" | 16 | #include "utilities.h" |
1064 | 17 | 17 | ||
1065 | 18 | 18 | #ifdef WIN32 | |
1066 | 19 | long int timedif(struct timeval a, struct timeval b) | 19 | #include <assert.h> |
1067 | 20 | { | 20 | |
1068 | 21 | long us, s; | 21 | long long strtoll(char const* s, char** sN, int base) |
1069 | 22 | 22 | { | |
1070 | 23 | us = (int)(a.tv_usec - b.tv_usec); | 23 | assert(sN == 0); |
1071 | 24 | us /= 1000; | 24 | assert(base == 10); |
1072 | 25 | s = (int)(a.tv_sec - b.tv_sec); | 25 | return _atoi64(s); |
1073 | 26 | s *= 1000; | 26 | } |
1074 | 27 | return s + us; | 27 | #endif |
1075 | 28 | } | 28 | |
1076 | 29 | 29 | long int timedif(struct timeval a, struct timeval b) | |
1077 | 30 | void version_command(const char *command_name) | 30 | { |
1078 | 31 | { | 31 | long us, s; |
1079 | 32 | printf("%s v%u.%u\n", command_name, 1U, 0U); | 32 | |
1080 | 33 | exit(0); | 33 | us = (int)(a.tv_usec - b.tv_usec); |
1081 | 34 | } | 34 | us /= 1000; |
1082 | 35 | 35 | s = (int)(a.tv_sec - b.tv_sec); | |
1083 | 36 | static const char *lookup_help(memcached_options option) | 36 | s *= 1000; |
1084 | 37 | { | 37 | return s + us; |
1085 | 38 | switch (option) | 38 | } |
1086 | 39 | { | 39 | |
1087 | 40 | case OPT_SERVERS: return("List which servers you wish to connect to."); | 40 | void version_command(const char *command_name) |
1088 | 41 | case OPT_VERSION: return("Display the version of the application and then exit."); | 41 | { |
1089 | 42 | case OPT_HELP: return("Display this message and then exit."); | 42 | printf("%s v%u.%u\n", command_name, 1U, 0U); |
1090 | 43 | case OPT_VERBOSE: return("Give more details on the progression of the application."); | 43 | exit(0); |
1091 | 44 | case OPT_DEBUG: return("Provide output only useful for debugging."); | 44 | } |
1092 | 45 | case OPT_FLAG: return("Provide flag information for storage operation."); | 45 | |
1093 | 46 | case OPT_EXPIRE: return("Set the expire option for the object."); | 46 | static const char *lookup_help(memcached_options option) |
1094 | 47 | case OPT_SET: return("Use set command with memcached when storing."); | 47 | { |
1095 | 48 | case OPT_REPLACE: return("Use replace command with memcached when storing."); | 48 | switch (option) |
1096 | 49 | case OPT_ADD: return("Use add command with memcached when storing."); | 49 | { |
1097 | 50 | case OPT_SLAP_EXECUTE_NUMBER: return("Number of times to execute the given test."); | 50 | case OPT_SERVERS: return("List which servers you wish to connect to."); |
1098 | 51 | case OPT_SLAP_INITIAL_LOAD: return("Number of key pairs to load before executing tests."); | 51 | case OPT_VERSION: return("Display the version of the application and then exit."); |
1099 | 52 | case OPT_SLAP_TEST: return("Test to run (currently \"get\" or \"set\")."); | 52 | case OPT_HELP: return("Display this message and then exit."); |
1100 | 53 | case OPT_SLAP_CONCURRENCY: return("Number of users to simulate with load."); | 53 | case OPT_VERBOSE: return("Give more details on the progression of the application."); |
1101 | 54 | case OPT_SLAP_NON_BLOCK: return("Set TCP up to use non-blocking IO."); | 54 | case OPT_DEBUG: return("Provide output only useful for debugging."); |
1102 | 55 | case OPT_SLAP_TCP_NODELAY: return("Set TCP socket up to use nodelay."); | 55 | case OPT_FLAG: return("Provide flag information for storage operation."); |
1103 | 56 | case OPT_FLUSH: return("Flush servers before running tests."); | 56 | case OPT_EXPIRE: return("Set the expire option for the object."); |
1104 | 57 | case OPT_HASH: return("Select hash type."); | 57 | case OPT_SET: return("Use set command with memcached when storing."); |
1105 | 58 | case OPT_BINARY: return("Switch to binary protocol."); | 58 | case OPT_REPLACE: return("Use replace command with memcached when storing."); |
1106 | 59 | case OPT_ANALYZE: return("Analyze the provided servers."); | 59 | case OPT_ADD: return("Use add command with memcached when storing."); |
1107 | 60 | case OPT_UDP: return("Use UDP protocol when communicating with server."); | 60 | case OPT_SLAP_EXECUTE_NUMBER: return("Number of times to execute the given test."); |
1108 | 61 | case OPT_USERNAME: return "Username to use for SASL authentication"; | 61 | case OPT_SLAP_INITIAL_LOAD: return("Number of key pairs to load before executing tests."); |
1109 | 62 | case OPT_PASSWD: return "Password to use for SASL authentication"; | 62 | case OPT_SLAP_TEST: return("Test to run (currently \"get\" or \"set\")."); |
1110 | 63 | case OPT_FILE: return "Path to file in which to save result"; | 63 | case OPT_SLAP_CONCURRENCY: return("Number of users to simulate with load."); |
1111 | 64 | case OPT_STAT_ARGS: return "Argument for statistics"; | 64 | case OPT_SLAP_NON_BLOCK: return("Set TCP up to use non-blocking IO."); |
1112 | 65 | default: WATCHPOINT_ASSERT(0); | 65 | case OPT_SLAP_TCP_NODELAY: return("Set TCP socket up to use nodelay."); |
1113 | 66 | }; | 66 | case OPT_FLUSH: return("Flush servers before running tests."); |
1114 | 67 | 67 | case OPT_HASH: return("Select hash type."); | |
1115 | 68 | WATCHPOINT_ASSERT(0); | 68 | case OPT_BINARY: return("Switch to binary protocol."); |
1116 | 69 | return "forgot to document this function :)"; | 69 | case OPT_ANALYZE: return("Analyze the provided servers."); |
1117 | 70 | } | 70 | case OPT_UDP: return("Use UDP protocol when communicating with server."); |
1118 | 71 | 71 | case OPT_USERNAME: return "Username to use for SASL authentication"; | |
1119 | 72 | void help_command(const char *command_name, const char *description, | 72 | case OPT_PASSWD: return "Password to use for SASL authentication"; |
1120 | 73 | const struct option *long_options, | 73 | case OPT_FILE: return "Path to file in which to save result"; |
1121 | 74 | memcached_programs_help_st *options __attribute__((unused))) | 74 | case OPT_STAT_ARGS: return "Argument for statistics"; |
1122 | 75 | { | 75 | default: WATCHPOINT_ASSERT(0); |
1123 | 76 | unsigned int x; | 76 | }; |
1124 | 77 | 77 | ||
1125 | 78 | printf("%s v%u.%u\n\n", command_name, 1U, 0U); | 78 | WATCHPOINT_ASSERT(0); |
1126 | 79 | printf("\t%s\n\n", description); | 79 | return "forgot to document this function :)"; |
1127 | 80 | printf("Current options. A '=' means the option takes a value.\n\n"); | 80 | } |
1128 | 81 | 81 | ||
1129 | 82 | for (x= 0; long_options[x].name; x++) | 82 | void help_command(const char *command_name, const char *description, |
1130 | 83 | { | 83 | const struct option *long_options, |
1131 | 84 | const char *help_message; | 84 | memcached_programs_help_st *options __attribute__((unused))) |
1132 | 85 | 85 | { | |
1133 | 86 | printf("\t --%s%c\n", long_options[x].name, | 86 | unsigned int x; |
1134 | 87 | long_options[x].has_arg ? '=' : ' '); | 87 | |
1135 | 88 | if ((help_message= lookup_help(long_options[x].val))) | 88 | printf("%s v%u.%u\n\n", command_name, 1U, 0U); |
1136 | 89 | printf("\t\t%s\n", help_message); | 89 | printf("\t%s\n\n", description); |
1137 | 90 | } | 90 | printf("Current options. A '=' means the option takes a value.\n\n"); |
1138 | 91 | 91 | ||
1139 | 92 | printf("\n"); | 92 | for (x= 0; long_options[x].name; x++) |
1140 | 93 | exit(0); | 93 | { |
1141 | 94 | } | 94 | const char *help_message; |
1142 | 95 | 95 | ||
1143 | 96 | void process_hash_option(memcached_st *memc, char *opt_hash) | 96 | printf("\t --%s%c\n", long_options[x].name, |
1144 | 97 | { | 97 | long_options[x].has_arg ? '=' : ' '); |
1145 | 98 | uint64_t set; | 98 | if ((help_message= lookup_help(long_options[x].val))) |
1146 | 99 | memcached_return_t rc; | 99 | printf("\t\t%s\n", help_message); |
1147 | 100 | 100 | } | |
1148 | 101 | if (opt_hash == NULL) | 101 | |
1149 | 102 | return; | 102 | printf("\n"); |
1150 | 103 | 103 | exit(0); | |
1151 | 104 | set= MEMCACHED_HASH_DEFAULT; /* Just here to solve warning */ | 104 | } |
1152 | 105 | if (!strcasecmp(opt_hash, "CRC")) | 105 | |
1153 | 106 | set= MEMCACHED_HASH_CRC; | 106 | void process_hash_option(memcached_st *memc, char *opt_hash) |
1154 | 107 | else if (!strcasecmp(opt_hash, "FNV1_64")) | 107 | { |
1155 | 108 | set= MEMCACHED_HASH_FNV1_64; | 108 | uint64_t set; |
1156 | 109 | else if (!strcasecmp(opt_hash, "FNV1A_64")) | 109 | memcached_return_t rc; |
1157 | 110 | set= MEMCACHED_HASH_FNV1A_64; | 110 | |
1158 | 111 | else if (!strcasecmp(opt_hash, "FNV1_32")) | 111 | if (opt_hash == NULL) |
1159 | 112 | set= MEMCACHED_HASH_FNV1_32; | 112 | return; |
1160 | 113 | else if (!strcasecmp(opt_hash, "FNV1A_32")) | 113 | |
1161 | 114 | set= MEMCACHED_HASH_FNV1A_32; | 114 | set= MEMCACHED_HASH_DEFAULT; /* Just here to solve warning */ |
1162 | 115 | else | 115 | if (!strcasecmp(opt_hash, "CRC")) |
1163 | 116 | { | 116 | set= MEMCACHED_HASH_CRC; |
1164 | 117 | fprintf(stderr, "hash: type not recognized %s\n", opt_hash); | 117 | else if (!strcasecmp(opt_hash, "FNV1_64")) |
1165 | 118 | exit(1); | 118 | set= MEMCACHED_HASH_FNV1_64; |
1166 | 119 | } | 119 | else if (!strcasecmp(opt_hash, "FNV1A_64")) |
1167 | 120 | 120 | set= MEMCACHED_HASH_FNV1A_64; | |
1168 | 121 | rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, set); | 121 | else if (!strcasecmp(opt_hash, "FNV1_32")) |
1169 | 122 | if (rc != MEMCACHED_SUCCESS) | 122 | set= MEMCACHED_HASH_FNV1_32; |
1170 | 123 | { | 123 | else if (!strcasecmp(opt_hash, "FNV1A_32")) |
1171 | 124 | fprintf(stderr, "hash: memcache error %s\n", memcached_strerror(memc, rc)); | 124 | set= MEMCACHED_HASH_FNV1A_32; |
1172 | 125 | exit(1); | 125 | else |
1173 | 126 | } | 126 | { |
1174 | 127 | } | 127 | fprintf(stderr, "hash: type not recognized %s\n", opt_hash); |
1175 | 128 | 128 | exit(1); | |
1176 | 129 | #ifdef LIBMEMCACHED_WITH_SASL_SUPPORT | 129 | } |
1177 | 130 | static char *username; | 130 | |
1178 | 131 | static char *passwd; | 131 | rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, set); |
1179 | 132 | 132 | if (rc != MEMCACHED_SUCCESS) | |
1180 | 133 | static int get_username(void *context, int id, const char **result, | 133 | { |
1181 | 134 | unsigned int *len) | 134 | fprintf(stderr, "hash: memcache error %s\n", memcached_strerror(memc, rc)); |
1182 | 135 | { | 135 | exit(1); |
1183 | 136 | (void)context; | 136 | } |
1184 | 137 | if (!result || (id != SASL_CB_USER && id != SASL_CB_AUTHNAME)) | 137 | } |
1185 | 138 | return SASL_BADPARAM; | 138 | |
1186 | 139 | 139 | #ifdef LIBMEMCACHED_WITH_SASL_SUPPORT | |
1187 | 140 | *result= username; | 140 | static char *username; |
1188 | 141 | if (len) | 141 | static char *passwd; |
1189 | 142 | *len= (username == NULL) ? 0 : (unsigned int)strlen(username); | 142 | |
1190 | 143 | 143 | static int get_username(void *context, int id, const char **result, | |
1191 | 144 | return SASL_OK; | 144 | unsigned int *len) |
1192 | 145 | } | 145 | { |
1193 | 146 | 146 | (void)context; | |
1194 | 147 | static int get_password(sasl_conn_t *conn, void *context, int id, | 147 | if (!result || (id != SASL_CB_USER && id != SASL_CB_AUTHNAME)) |
1195 | 148 | sasl_secret_t **psecret) | 148 | return SASL_BADPARAM; |
1196 | 149 | { | 149 | |
1197 | 150 | (void)context; | 150 | *result= username; |
1198 | 151 | static sasl_secret_t* x; | 151 | if (len) |
1199 | 152 | 152 | *len= (username == NULL) ? 0 : (unsigned int)strlen(username); | |
1200 | 153 | if (!conn || ! psecret || id != SASL_CB_PASS) | 153 | |
1201 | 154 | return SASL_BADPARAM; | 154 | return SASL_OK; |
1202 | 155 | 155 | } | |
1203 | 156 | if (passwd == NULL) | 156 | |
1204 | 157 | { | 157 | static int get_password(sasl_conn_t *conn, void *context, int id, |
1205 | 158 | *psecret= NULL; | 158 | sasl_secret_t **psecret) |
1206 | 159 | return SASL_OK; | 159 | { |
1207 | 160 | } | 160 | (void)context; |
1208 | 161 | 161 | static sasl_secret_t* x; | |
1209 | 162 | size_t len= strlen(passwd); | 162 | |
1210 | 163 | x = realloc(x, sizeof(sasl_secret_t) + len); | 163 | if (!conn || ! psecret || id != SASL_CB_PASS) |
1211 | 164 | if (!x) | 164 | return SASL_BADPARAM; |
1212 | 165 | return SASL_NOMEM; | 165 | |
1213 | 166 | 166 | if (passwd == NULL) | |
1214 | 167 | x->len = len; | 167 | { |
1215 | 168 | strcpy((void *)x->data, passwd); | 168 | *psecret= NULL; |
1216 | 169 | 169 | return SASL_OK; | |
1217 | 170 | *psecret = x; | 170 | } |
1218 | 171 | return SASL_OK; | 171 | |
1219 | 172 | } | 172 | size_t len= strlen(passwd); |
1220 | 173 | 173 | x = realloc(x, sizeof(sasl_secret_t) + len); | |
1221 | 174 | /* callbacks we support */ | 174 | if (!x) |
1222 | 175 | static sasl_callback_t sasl_callbacks[] = { | 175 | return SASL_NOMEM; |
1223 | 176 | { | 176 | |
1224 | 177 | SASL_CB_USER, &get_username, NULL | 177 | x->len = len; |
1225 | 178 | }, { | 178 | strcpy((void *)x->data, passwd); |
1226 | 179 | SASL_CB_AUTHNAME, &get_username, NULL | 179 | |
1227 | 180 | }, { | 180 | *psecret = x; |
1228 | 181 | SASL_CB_PASS, &get_password, NULL | 181 | return SASL_OK; |
1229 | 182 | }, { | 182 | } |
1230 | 183 | SASL_CB_LIST_END, NULL, NULL | 183 | |
1231 | 184 | } | 184 | /* callbacks we support */ |
1232 | 185 | }; | 185 | static sasl_callback_t sasl_callbacks[] = { |
1233 | 186 | #endif | 186 | { |
1234 | 187 | 187 | SASL_CB_USER, &get_username, NULL | |
1235 | 188 | bool initialize_sasl(memcached_st *memc, char *user, char *password) | 188 | }, { |
1236 | 189 | { | 189 | SASL_CB_AUTHNAME, &get_username, NULL |
1237 | 190 | #ifdef LIBMEMCACHED_WITH_SASL_SUPPORT | 190 | }, { |
1238 | 191 | if (user != NULL && password != NULL) | 191 | SASL_CB_PASS, &get_password, NULL |
1239 | 192 | { | 192 | }, { |
1240 | 193 | username= user; | 193 | SASL_CB_LIST_END, NULL, NULL |
1241 | 194 | passwd= password; | 194 | } |
1242 | 195 | 195 | }; | |
1243 | 196 | if (sasl_client_init(NULL) != SASL_OK) | 196 | #endif |
1244 | 197 | { | 197 | |
1245 | 198 | fprintf(stderr, "Failed to initialize sasl library!\n"); | 198 | bool initialize_sasl(memcached_st *memc, char *user, char *password) |
1246 | 199 | return false; | 199 | { |
1247 | 200 | } | 200 | #ifdef LIBMEMCACHED_WITH_SASL_SUPPORT |
1248 | 201 | memcached_set_sasl_callbacks(memc, sasl_callbacks); | 201 | if (user != NULL && password != NULL) |
1249 | 202 | } | 202 | { |
1250 | 203 | #else | 203 | username= user; |
1251 | 204 | (void)memc; | 204 | passwd= password; |
1252 | 205 | (void)user; | 205 | |
1253 | 206 | (void)password; | 206 | if (sasl_client_init(NULL) != SASL_OK) |
1254 | 207 | #endif | 207 | { |
1255 | 208 | 208 | fprintf(stderr, "Failed to initialize sasl library!\n"); | |
1256 | 209 | return true; | 209 | return false; |
1257 | 210 | } | 210 | } |
1258 | 211 | 211 | memcached_set_sasl_callbacks(memc, sasl_callbacks); | |
1259 | 212 | void shutdown_sasl(void) | 212 | } |
1260 | 213 | { | 213 | #else |
1261 | 214 | #ifdef LIBMEMCACHED_WITH_SASL_SUPPORT | 214 | (void)memc; |
1262 | 215 | if (username != NULL || passwd != NULL) | 215 | (void)user; |
1263 | 216 | sasl_done(); | 216 | (void)password; |
1264 | 217 | #endif | 217 | #endif |
1265 | 218 | } | 218 | |
1266 | 219 | 219 | return true; | |
1267 | 220 | void initialize_sockets(void) | 220 | } |
1268 | 221 | { | 221 | |
1269 | 222 | /* Define the function for all platforms to avoid #ifdefs in each program */ | 222 | void shutdown_sasl(void) |
1270 | 223 | #ifdef WIN32 | 223 | { |
1271 | 224 | WSADATA wsaData; | 224 | #ifdef LIBMEMCACHED_WITH_SASL_SUPPORT |
1272 | 225 | if (WSAStartup(MAKEWORD(2,0), &wsaData) != 0) | 225 | if (username != NULL || passwd != NULL) |
1273 | 226 | { | 226 | sasl_done(); |
1274 | 227 | fprintf(stderr, "Socket Initialization Error. Program aborted\n"); | 227 | #endif |
1275 | 228 | exit(EXIT_FAILURE); | 228 | } |
1276 | 229 | } | 229 | |
1277 | 230 | #endif | 230 | void initialize_sockets(void) |
1278 | 231 | } | 231 | { |
1279 | 232 | /* Define the function for all platforms to avoid #ifdefs in each program */ | ||
1280 | 233 | #ifdef WIN32 | ||
1281 | 234 | WSADATA wsaData; | ||
1282 | 235 | if (WSAStartup(MAKEWORD(2,0), &wsaData) != 0) | ||
1283 | 236 | { | ||
1284 | 237 | fprintf(stderr, "Socket Initialization Error. Program aborted\n"); | ||
1285 | 238 | exit(EXIT_FAILURE); | ||
1286 | 239 | } | ||
1287 | 240 | #endif | ||
1288 | 241 | } | ||
1289 | 232 | 242 | ||
1290 | === modified file 'clients/utilities.h' | |||
1291 | --- clients/utilities.h 2010-07-27 22:38:51 +0000 | |||
1292 | +++ clients/utilities.h 2011-01-13 03:40:43 +0000 | |||
1293 | @@ -34,6 +34,11 @@ | |||
1294 | 34 | #define OPTIONSTRING const char* | 34 | #define OPTIONSTRING const char* |
1295 | 35 | #endif | 35 | #endif |
1296 | 36 | 36 | ||
1297 | 37 | #ifdef WIN32 | ||
1298 | 38 | # define strcasecmp strcmp | ||
1299 | 39 | long long strtoll(char const* s, char** sN, int base); | ||
1300 | 40 | #endif | ||
1301 | 41 | |||
1302 | 37 | typedef struct memcached_programs_help_st memcached_programs_help_st; | 42 | typedef struct memcached_programs_help_st memcached_programs_help_st; |
1303 | 38 | 43 | ||
1304 | 39 | struct memcached_programs_help_st | 44 | struct memcached_programs_help_st |
1305 | 40 | 45 | ||
1306 | === modified file 'libhashkit/common.h' | |||
1307 | --- libhashkit/common.h 2010-09-13 12:27:18 +0000 | |||
1308 | +++ libhashkit/common.h 2011-01-13 03:40:43 +0000 | |||
1309 | @@ -17,6 +17,26 @@ | |||
1310 | 17 | #include <stdlib.h> | 17 | #include <stdlib.h> |
1311 | 18 | #include <math.h> | 18 | #include <math.h> |
1312 | 19 | 19 | ||
1313 | 20 | #ifdef WIN32 | ||
1314 | 21 | |||
1315 | 22 | #include <limits.h> | ||
1316 | 23 | #define UINT32_MAX UINT_MAX | ||
1317 | 24 | |||
1318 | 25 | #define __CONCAT(x, y) (x##y) | ||
1319 | 26 | |||
1320 | 27 | #define INT8_C(value) ((int8_t) value) | ||
1321 | 28 | #define UINT8_C(value) ((uint8_t) __CONCAT(value, U)) | ||
1322 | 29 | #define INT16_C(value) value | ||
1323 | 30 | #define UINT16_C(value) __CONCAT(value, U) | ||
1324 | 31 | #define INT32_C(value) __CONCAT(value, L) | ||
1325 | 32 | #define UINT32_C(value) __CONCAT(value, UL) | ||
1326 | 33 | #define INT64_C(value) __CONCAT(value, LL) | ||
1327 | 34 | #define UINT64_C(value) __CONCAT(value, ULL) | ||
1328 | 35 | #define INTMAX_C(value) __CONCAT(value, LL) | ||
1329 | 36 | #define UINTMAX_C(value) __CONCAT(value, ULL) | ||
1330 | 37 | |||
1331 | 38 | #endif | ||
1332 | 39 | |||
1333 | 20 | #include "hashkit.h" | 40 | #include "hashkit.h" |
1334 | 21 | 41 | ||
1335 | 22 | #ifdef __cplusplus | 42 | #ifdef __cplusplus |
1336 | 23 | 43 | ||
1337 | === modified file 'libhashkit/fnv.c' | |||
1338 | --- libhashkit/fnv.c 2010-01-19 23:39:13 +0000 | |||
1339 | +++ libhashkit/fnv.c 2011-01-13 03:40:43 +0000 | |||
1340 | @@ -18,8 +18,9 @@ | |||
1341 | 18 | { | 18 | { |
1342 | 19 | /* Thanks to pierre@demartines.com for the pointer */ | 19 | /* Thanks to pierre@demartines.com for the pointer */ |
1343 | 20 | uint64_t hash= FNV_64_INIT; | 20 | uint64_t hash= FNV_64_INIT; |
1344 | 21 | size_t x; | ||
1345 | 21 | 22 | ||
1347 | 22 | for (size_t x= 0; x < key_length; x++) | 23 | for (x= 0; x < key_length; x++) |
1348 | 23 | { | 24 | { |
1349 | 24 | hash *= FNV_64_PRIME; | 25 | hash *= FNV_64_PRIME; |
1350 | 25 | hash ^= (uint64_t)key[x]; | 26 | hash ^= (uint64_t)key[x]; |
1351 | @@ -31,8 +32,9 @@ | |||
1352 | 31 | uint32_t hashkit_fnv1a_64(const char *key, size_t key_length, void *context __attribute__((unused))) | 32 | uint32_t hashkit_fnv1a_64(const char *key, size_t key_length, void *context __attribute__((unused))) |
1353 | 32 | { | 33 | { |
1354 | 33 | uint32_t hash= (uint32_t) FNV_64_INIT; | 34 | uint32_t hash= (uint32_t) FNV_64_INIT; |
1355 | 35 | size_t x; | ||
1356 | 34 | 36 | ||
1358 | 35 | for (size_t x= 0; x < key_length; x++) | 37 | for (x= 0; x < key_length; x++) |
1359 | 36 | { | 38 | { |
1360 | 37 | uint32_t val= (uint32_t)key[x]; | 39 | uint32_t val= (uint32_t)key[x]; |
1361 | 38 | hash ^= val; | 40 | hash ^= val; |
1362 | @@ -45,8 +47,9 @@ | |||
1363 | 45 | uint32_t hashkit_fnv1_32(const char *key, size_t key_length, void *context __attribute__((unused))) | 47 | uint32_t hashkit_fnv1_32(const char *key, size_t key_length, void *context __attribute__((unused))) |
1364 | 46 | { | 48 | { |
1365 | 47 | uint32_t hash= FNV_32_INIT; | 49 | uint32_t hash= FNV_32_INIT; |
1366 | 50 | size_t x; | ||
1367 | 48 | 51 | ||
1369 | 49 | for (size_t x= 0; x < key_length; x++) | 52 | for (x= 0; x < key_length; x++) |
1370 | 50 | { | 53 | { |
1371 | 51 | uint32_t val= (uint32_t)key[x]; | 54 | uint32_t val= (uint32_t)key[x]; |
1372 | 52 | hash *= FNV_32_PRIME; | 55 | hash *= FNV_32_PRIME; |
1373 | @@ -59,8 +62,9 @@ | |||
1374 | 59 | uint32_t hashkit_fnv1a_32(const char *key, size_t key_length, void *context __attribute__((unused))) | 62 | uint32_t hashkit_fnv1a_32(const char *key, size_t key_length, void *context __attribute__((unused))) |
1375 | 60 | { | 63 | { |
1376 | 61 | uint32_t hash= FNV_32_INIT; | 64 | uint32_t hash= FNV_32_INIT; |
1377 | 65 | size_t x; | ||
1378 | 62 | 66 | ||
1380 | 63 | for (size_t x= 0; x < key_length; x++) | 67 | for (x= 0; x < key_length; x++) |
1381 | 64 | { | 68 | { |
1382 | 65 | uint32_t val= (uint32_t)key[x]; | 69 | uint32_t val= (uint32_t)key[x]; |
1383 | 66 | hash ^= val; | 70 | hash ^= val; |
1384 | 67 | 71 | ||
1385 | === modified file 'libhashkit/hashkit.c' | |||
1386 | --- libhashkit/hashkit.c 2010-01-22 19:04:16 +0000 | |||
1387 | +++ libhashkit/hashkit.c 2011-01-13 03:40:43 +0000 | |||
1388 | @@ -8,18 +8,16 @@ | |||
1389 | 8 | 8 | ||
1390 | 9 | #include "common.h" | 9 | #include "common.h" |
1391 | 10 | 10 | ||
1401 | 11 | static const hashkit_st global_default_hash= { | 11 | static hashkit_st global_default_hash; |
1393 | 12 | .base_hash= { | ||
1394 | 13 | .function= hashkit_one_at_a_time, | ||
1395 | 14 | .context= NULL | ||
1396 | 15 | }, | ||
1397 | 16 | .flags= { | ||
1398 | 17 | .is_base_same_distributed= false, | ||
1399 | 18 | } | ||
1400 | 19 | }; | ||
1402 | 20 | 12 | ||
1403 | 21 | static inline bool _hashkit_init(hashkit_st *self) | 13 | static inline bool _hashkit_init(hashkit_st *self) |
1404 | 22 | { | 14 | { |
1405 | 15 | memset(&global_default_hash, 0, sizeof(global_default_hash)); | ||
1406 | 16 | |||
1407 | 17 | global_default_hash.base_hash.function = hashkit_one_at_a_time; | ||
1408 | 18 | global_default_hash.base_hash.context = NULL; | ||
1409 | 19 | global_default_hash.flags.is_base_same_distributed = false; | ||
1410 | 20 | |||
1411 | 23 | self->base_hash= global_default_hash.base_hash; | 21 | self->base_hash= global_default_hash.base_hash; |
1412 | 24 | self->distribution_hash= global_default_hash.base_hash; | 22 | self->distribution_hash= global_default_hash.base_hash; |
1413 | 25 | self->flags= global_default_hash.flags; | 23 | self->flags= global_default_hash.flags; |
1414 | 26 | 24 | ||
1415 | === modified file 'libhashkit/visibility.h' | |||
1416 | --- libhashkit/visibility.h 2009-12-17 17:28:30 +0000 | |||
1417 | +++ libhashkit/visibility.h 2011-01-13 03:40:43 +0000 | |||
1418 | @@ -32,16 +32,26 @@ | |||
1419 | 32 | # define HASHKIT_API __global | 32 | # define HASHKIT_API __global |
1420 | 33 | # define HASHKIT_LOCAL __hidden | 33 | # define HASHKIT_LOCAL __hidden |
1421 | 34 | # elif defined(_MSC_VER) | 34 | # elif defined(_MSC_VER) |
1424 | 35 | # define HASHKIT_API extern __declspec(dllexport) | 35 | # if defined(LIBMEMCACHED_STATIC) |
1425 | 36 | # define HASHKIT_LOCAL | 36 | # define HASHKIT_API |
1426 | 37 | # define HASHKIT_LOCAL | ||
1427 | 38 | # else | ||
1428 | 39 | # define HASHKIT_API extern __declspec(dllexport) | ||
1429 | 40 | # define HASHKIT_LOCAL | ||
1430 | 41 | # endif | ||
1431 | 37 | # else | 42 | # else |
1432 | 38 | # define HASHKIT_API | 43 | # define HASHKIT_API |
1433 | 39 | # define HASHKIT_LOCAL | 44 | # define HASHKIT_LOCAL |
1434 | 40 | # endif /* defined(HAVE_VISIBILITY) */ | 45 | # endif /* defined(HAVE_VISIBILITY) */ |
1435 | 41 | #else /* defined(BUILDING_HASHKIT) */ | 46 | #else /* defined(BUILDING_HASHKIT) */ |
1436 | 42 | # if defined(_MSC_VER) | 47 | # if defined(_MSC_VER) |
1439 | 43 | # define HASHKIT_API extern __declspec(dllimport) | 48 | # if defined(LIBMEMCACHED_STATIC) |
1440 | 44 | # define HASHKIT_LOCAL | 49 | # define HASHKIT_API |
1441 | 50 | # define HASHKIT_LOCAL | ||
1442 | 51 | # else | ||
1443 | 52 | # define HASHKIT_API extern __declspec(dllimport) | ||
1444 | 53 | # define HASHKIT_LOCAL | ||
1445 | 54 | # endif | ||
1446 | 45 | # else | 55 | # else |
1447 | 46 | # define HASHKIT_API | 56 | # define HASHKIT_API |
1448 | 47 | # define HASHKIT_LOCAL | 57 | # define HASHKIT_LOCAL |
1449 | 48 | 58 | ||
1450 | === modified file 'libmemcached/allocators.c' | |||
1451 | --- libmemcached/allocators.c 2010-01-18 22:58:20 +0000 | |||
1452 | +++ libmemcached/allocators.c 2011-01-13 03:40:43 +0000 | |||
1453 | @@ -23,7 +23,7 @@ | |||
1454 | 23 | 23 | ||
1455 | 24 | void *_libmemcached_calloc(const memcached_st *ptr, size_t nelem, size_t size, void *context) | 24 | void *_libmemcached_calloc(const memcached_st *ptr, size_t nelem, size_t size, void *context) |
1456 | 25 | { | 25 | { |
1458 | 26 | if (ptr->allocators.malloc != _libmemcached_malloc) | 26 | if (ptr->allocators->malloc != _libmemcached_malloc) |
1459 | 27 | { | 27 | { |
1460 | 28 | void *ret = _libmemcached_malloc(ptr, nelem * size, context); | 28 | void *ret = _libmemcached_malloc(ptr, nelem * size, context); |
1461 | 29 | if (ret != NULL) | 29 | if (ret != NULL) |
1462 | @@ -35,16 +35,26 @@ | |||
1463 | 35 | return calloc(nelem, size); | 35 | return calloc(nelem, size); |
1464 | 36 | } | 36 | } |
1465 | 37 | 37 | ||
1475 | 38 | static const struct _allocators_st global_default_allocator= { | 38 | struct _allocators_st *create_global_default_allocator() |
1467 | 39 | .calloc= _libmemcached_calloc, | ||
1468 | 40 | .context= NULL, | ||
1469 | 41 | .free= _libmemcached_free, | ||
1470 | 42 | .malloc= _libmemcached_malloc, | ||
1471 | 43 | .realloc= _libmemcached_realloc | ||
1472 | 44 | }; | ||
1473 | 45 | |||
1474 | 46 | struct _allocators_st memcached_allocators_return_default(void) | ||
1476 | 47 | { | 39 | { |
1477 | 40 | struct _allocators_st *allocator = (struct _allocators_st *) malloc(sizeof(struct _allocators_st)); | ||
1478 | 41 | |||
1479 | 42 | allocator->calloc= _libmemcached_calloc; | ||
1480 | 43 | allocator->context= NULL; | ||
1481 | 44 | allocator->free= _libmemcached_free; | ||
1482 | 45 | allocator->malloc= _libmemcached_malloc; | ||
1483 | 46 | allocator->realloc= _libmemcached_realloc; | ||
1484 | 47 | |||
1485 | 48 | return allocator; | ||
1486 | 49 | } | ||
1487 | 50 | |||
1488 | 51 | static struct _allocators_st *global_default_allocator = NULL; | ||
1489 | 52 | |||
1490 | 53 | struct _allocators_st *memcached_allocators_return_default(void) | ||
1491 | 54 | { | ||
1492 | 55 | if (global_default_allocator == NULL) | ||
1493 | 56 | global_default_allocator = create_global_default_allocator(); | ||
1494 | 57 | |||
1495 | 48 | return global_default_allocator; | 58 | return global_default_allocator; |
1496 | 49 | } | 59 | } |
1497 | 50 | 60 | ||
1498 | @@ -66,11 +76,11 @@ | |||
1499 | 66 | } | 76 | } |
1500 | 67 | else | 77 | else |
1501 | 68 | { | 78 | { |
1507 | 69 | ptr->allocators.malloc= mem_malloc; | 79 | ptr->allocators->malloc= mem_malloc; |
1508 | 70 | ptr->allocators.free= mem_free; | 80 | ptr->allocators->free= mem_free; |
1509 | 71 | ptr->allocators.realloc= mem_realloc; | 81 | ptr->allocators->realloc= mem_realloc; |
1510 | 72 | ptr->allocators.calloc= mem_calloc; | 82 | ptr->allocators->calloc= mem_calloc; |
1511 | 73 | ptr->allocators.context= context; | 83 | ptr->allocators->context= context; |
1512 | 74 | } | 84 | } |
1513 | 75 | 85 | ||
1514 | 76 | return MEMCACHED_SUCCESS; | 86 | return MEMCACHED_SUCCESS; |
1515 | @@ -78,7 +88,7 @@ | |||
1516 | 78 | 88 | ||
1517 | 79 | void *memcached_get_memory_allocators_context(const memcached_st *ptr) | 89 | void *memcached_get_memory_allocators_context(const memcached_st *ptr) |
1518 | 80 | { | 90 | { |
1520 | 81 | return ptr->allocators.context; | 91 | return ptr->allocators->context; |
1521 | 82 | } | 92 | } |
1522 | 83 | 93 | ||
1523 | 84 | void memcached_get_memory_allocators(const memcached_st *ptr, | 94 | void memcached_get_memory_allocators(const memcached_st *ptr, |
1524 | @@ -87,8 +97,8 @@ | |||
1525 | 87 | memcached_realloc_fn *mem_realloc, | 97 | memcached_realloc_fn *mem_realloc, |
1526 | 88 | memcached_calloc_fn *mem_calloc) | 98 | memcached_calloc_fn *mem_calloc) |
1527 | 89 | { | 99 | { |
1532 | 90 | *mem_malloc= ptr->allocators.malloc; | 100 | *mem_malloc= ptr->allocators->malloc; |
1533 | 91 | *mem_free= ptr->allocators.free; | 101 | *mem_free= ptr->allocators->free; |
1534 | 92 | *mem_realloc= ptr->allocators.realloc; | 102 | *mem_realloc= ptr->allocators->realloc; |
1535 | 93 | *mem_calloc= ptr->allocators.calloc; | 103 | *mem_calloc= ptr->allocators->calloc; |
1536 | 94 | } | 104 | } |
1537 | 95 | 105 | ||
1538 | === modified file 'libmemcached/allocators.h' | |||
1539 | --- libmemcached/allocators.h 2010-01-21 23:45:12 +0000 | |||
1540 | +++ libmemcached/allocators.h 2011-01-13 03:40:43 +0000 | |||
1541 | @@ -47,7 +47,7 @@ | |||
1542 | 47 | void *_libmemcached_calloc(const memcached_st *ptr, size_t nelem, size_t size, void *context); | 47 | void *_libmemcached_calloc(const memcached_st *ptr, size_t nelem, size_t size, void *context); |
1543 | 48 | 48 | ||
1544 | 49 | LIBMEMCACHED_LOCAL | 49 | LIBMEMCACHED_LOCAL |
1546 | 50 | struct _allocators_st memcached_allocators_return_default(void); | 50 | struct _allocators_st *memcached_allocators_return_default(void); |
1547 | 51 | 51 | ||
1548 | 52 | #ifdef __cplusplus | 52 | #ifdef __cplusplus |
1549 | 53 | } | 53 | } |
1550 | 54 | 54 | ||
1551 | === modified file 'libmemcached/analyze.c' | |||
1552 | --- libmemcached/analyze.c 2010-01-10 00:49:55 +0000 | |||
1553 | +++ libmemcached/analyze.c 2011-01-13 03:40:43 +0000 | |||
1554 | @@ -49,13 +49,15 @@ | |||
1555 | 49 | const uint64_t total_get_hits, | 49 | const uint64_t total_get_hits, |
1556 | 50 | const uint64_t total_get_cmds) | 50 | const uint64_t total_get_cmds) |
1557 | 51 | { | 51 | { |
1558 | 52 | double temp; | ||
1559 | 53 | |||
1560 | 52 | if (total_get_hits == 0 || total_get_cmds == 0) | 54 | if (total_get_hits == 0 || total_get_cmds == 0) |
1561 | 53 | { | 55 | { |
1562 | 54 | result->pool_hit_ratio= 0; | 56 | result->pool_hit_ratio= 0; |
1563 | 55 | return; | 57 | return; |
1564 | 56 | } | 58 | } |
1565 | 57 | 59 | ||
1567 | 58 | double temp= (double) (total_get_hits/total_get_cmds); | 60 | temp = (double) (total_get_hits/total_get_cmds); |
1568 | 59 | result->pool_hit_ratio= temp * 100; | 61 | result->pool_hit_ratio= temp * 100; |
1569 | 60 | } | 62 | } |
1570 | 61 | 63 | ||
1571 | 62 | 64 | ||
1572 | === modified file 'libmemcached/auto.c' | |||
1573 | --- libmemcached/auto.c 2010-09-13 12:26:17 +0000 | |||
1574 | +++ libmemcached/auto.c 2011-01-13 03:40:43 +0000 | |||
1575 | @@ -89,6 +89,11 @@ | |||
1576 | 89 | { | 89 | { |
1577 | 90 | uint32_t server_key; | 90 | uint32_t server_key; |
1578 | 91 | memcached_server_write_instance_st instance; | 91 | memcached_server_write_instance_st instance; |
1579 | 92 | protocol_binary_request_incr request; | ||
1580 | 93 | memcached_return_t rc; | ||
1581 | 94 | |||
1582 | 95 | struct libmemcached_io_vector_st vector[3]; | ||
1583 | 96 | |||
1584 | 92 | bool no_reply= ptr->flags.no_reply; | 97 | bool no_reply= ptr->flags.no_reply; |
1585 | 93 | 98 | ||
1586 | 94 | unlikely (memcached_server_count(ptr) == 0) | 99 | unlikely (memcached_server_count(ptr) == 0) |
1587 | @@ -103,8 +108,9 @@ | |||
1588 | 103 | cmd= PROTOCOL_BINARY_CMD_DECREMENTQ; | 108 | cmd= PROTOCOL_BINARY_CMD_DECREMENTQ; |
1589 | 104 | if(cmd == PROTOCOL_BINARY_CMD_INCREMENT) | 109 | if(cmd == PROTOCOL_BINARY_CMD_INCREMENT) |
1590 | 105 | cmd= PROTOCOL_BINARY_CMD_INCREMENTQ; | 110 | cmd= PROTOCOL_BINARY_CMD_INCREMENTQ; |
1593 | 106 | } | 111 | } |
1594 | 107 | protocol_binary_request_incr request= {.bytes= {0}}; | 112 | |
1595 | 113 | memset(&request, 0, sizeof(request)); | ||
1596 | 108 | 114 | ||
1597 | 109 | request.message.header.request.magic= PROTOCOL_BINARY_REQ; | 115 | request.message.header.request.magic= PROTOCOL_BINARY_REQ; |
1598 | 110 | request.message.header.request.opcode= cmd; | 116 | request.message.header.request.opcode= cmd; |
1599 | @@ -116,14 +122,13 @@ | |||
1600 | 116 | request.message.body.initial= htonll(initial); | 122 | request.message.body.initial= htonll(initial); |
1601 | 117 | request.message.body.expiration= htonl((uint32_t) expiration); | 123 | request.message.body.expiration= htonl((uint32_t) expiration); |
1602 | 118 | 124 | ||
1609 | 119 | struct libmemcached_io_vector_st vector[]= | 125 | vector[0].length= sizeof(request.bytes); |
1610 | 120 | { | 126 | vector[0].buffer= request.bytes; |
1611 | 121 | { .length= sizeof(request.bytes), .buffer= request.bytes }, | 127 | vector[1].length= ptr->prefix_key_length; |
1612 | 122 | { .length= ptr->prefix_key_length, .buffer= ptr->prefix_key }, | 128 | vector[1].buffer= ptr->prefix_key; |
1613 | 123 | { .length= key_length, .buffer= key } | 129 | vector[2].length= key_length; |
1614 | 124 | }; | 130 | vector[2].buffer= key; |
1615 | 125 | 131 | ||
1616 | 126 | memcached_return_t rc; | ||
1617 | 127 | if ((rc= memcached_vdo(instance, vector, 3, true)) != MEMCACHED_SUCCESS) | 132 | if ((rc= memcached_vdo(instance, vector, 3, true)) != MEMCACHED_SUCCESS) |
1618 | 128 | { | 133 | { |
1619 | 129 | memcached_io_reset(instance); | 134 | memcached_io_reset(instance); |
1620 | 130 | 135 | ||
1621 | === modified file 'libmemcached/behavior.c' | |||
1622 | --- libmemcached/behavior.c 2010-07-27 22:38:51 +0000 | |||
1623 | +++ libmemcached/behavior.c 2011-01-13 03:40:43 +0000 | |||
1624 | @@ -178,6 +178,9 @@ | |||
1625 | 178 | case MEMCACHED_BEHAVIOR_CORK: | 178 | case MEMCACHED_BEHAVIOR_CORK: |
1626 | 179 | { | 179 | { |
1627 | 180 | memcached_server_write_instance_st instance; | 180 | memcached_server_write_instance_st instance; |
1628 | 181 | memcached_return_t rc; | ||
1629 | 182 | memcached_ternary_t enabled; | ||
1630 | 183 | |||
1631 | 181 | bool action= set_flag(data); | 184 | bool action= set_flag(data); |
1632 | 182 | 185 | ||
1633 | 183 | if (action == false) | 186 | if (action == false) |
1634 | @@ -191,16 +194,14 @@ | |||
1635 | 191 | return MEMCACHED_NO_SERVERS; | 194 | return MEMCACHED_NO_SERVERS; |
1636 | 192 | 195 | ||
1637 | 193 | 196 | ||
1640 | 194 | /* We just try the first host, and if it is down we return zero */ | 197 | /* We just try the first host, and if it is down we return zero */ |
1639 | 195 | memcached_return_t rc; | ||
1641 | 196 | rc= memcached_connect(instance); | 198 | rc= memcached_connect(instance); |
1642 | 197 | if (rc != MEMCACHED_SUCCESS) | 199 | if (rc != MEMCACHED_SUCCESS) |
1643 | 198 | { | 200 | { |
1644 | 199 | return rc; | 201 | return rc; |
1645 | 200 | } | 202 | } |
1646 | 201 | 203 | ||
1649 | 202 | /* Now we test! */ | 204 | /* Now we test! */ |
1648 | 203 | memcached_ternary_t enabled; | ||
1650 | 204 | enabled= test_cork(instance, true); | 205 | enabled= test_cork(instance, true); |
1651 | 205 | 206 | ||
1652 | 206 | switch (enabled) | 207 | switch (enabled) |
1653 | 207 | 208 | ||
1654 | === modified file 'libmemcached/byteorder.c' | |||
1655 | --- libmemcached/byteorder.c 2010-09-02 08:23:44 +0000 | |||
1656 | +++ libmemcached/byteorder.c 2011-01-13 03:40:43 +0000 | |||
1657 | @@ -19,7 +19,9 @@ | |||
1658 | 19 | /* Little endian, flip the bytes around until someone makes a faster/better | 19 | /* Little endian, flip the bytes around until someone makes a faster/better |
1659 | 20 | * way to do this. */ | 20 | * way to do this. */ |
1660 | 21 | uint64_t rv= 0; | 21 | uint64_t rv= 0; |
1662 | 22 | for (uint8_t x= 0; x < 8; x++) | 22 | uint8_t x; |
1663 | 23 | |||
1664 | 24 | for (x= 0; x < 8; x++) | ||
1665 | 23 | { | 25 | { |
1666 | 24 | rv= (rv << 8) | (in & 0xff); | 26 | rv= (rv << 8) | (in & 0xff); |
1667 | 25 | in >>= 8; | 27 | in >>= 8; |
1668 | 26 | 28 | ||
1669 | === modified file 'libmemcached/common.h' | |||
1670 | --- libmemcached/common.h 2010-07-27 22:38:51 +0000 | |||
1671 | +++ libmemcached/common.h 2011-01-13 03:40:43 +0000 | |||
1672 | @@ -21,10 +21,18 @@ | |||
1673 | 21 | #include <stdio.h> | 21 | #include <stdio.h> |
1674 | 22 | #include <stdlib.h> | 22 | #include <stdlib.h> |
1675 | 23 | #include <string.h> | 23 | #include <string.h> |
1677 | 24 | #include <strings.h> | 24 | |
1678 | 25 | #ifdef WIN32 | ||
1679 | 26 | # define snprintf _snprintf | ||
1680 | 27 | # define strtoull strtoul | ||
1681 | 28 | #else | ||
1682 | 29 | # include <strings.h> | ||
1683 | 30 | # include <unistd.h> | ||
1684 | 31 | #endif | ||
1685 | 32 | |||
1686 | 25 | #include <ctype.h> | 33 | #include <ctype.h> |
1687 | 26 | #include <sys/types.h> | 34 | #include <sys/types.h> |
1689 | 27 | #include <unistd.h> | 35 | |
1690 | 28 | #include <limits.h> | 36 | #include <limits.h> |
1691 | 29 | #include <errno.h> | 37 | #include <errno.h> |
1692 | 30 | #include <fcntl.h> | 38 | #include <fcntl.h> |
1693 | @@ -204,22 +212,22 @@ | |||
1694 | 204 | 212 | ||
1695 | 205 | static inline void libmemcached_free(const memcached_st *ptr, void *mem) | 213 | static inline void libmemcached_free(const memcached_st *ptr, void *mem) |
1696 | 206 | { | 214 | { |
1698 | 207 | ptr->allocators.free(ptr, mem, ptr->allocators.context); | 215 | ptr->allocators->free(ptr, mem, ptr->allocators->context); |
1699 | 208 | } | 216 | } |
1700 | 209 | 217 | ||
1701 | 210 | static inline void *libmemcached_malloc(const memcached_st *ptr, const size_t size) | 218 | static inline void *libmemcached_malloc(const memcached_st *ptr, const size_t size) |
1702 | 211 | { | 219 | { |
1704 | 212 | return ptr->allocators.malloc(ptr, size, ptr->allocators.context); | 220 | return ptr->allocators->malloc(ptr, size, ptr->allocators->context); |
1705 | 213 | } | 221 | } |
1706 | 214 | 222 | ||
1707 | 215 | static inline void *libmemcached_realloc(const memcached_st *ptr, void *mem, const size_t size) | 223 | static inline void *libmemcached_realloc(const memcached_st *ptr, void *mem, const size_t size) |
1708 | 216 | { | 224 | { |
1710 | 217 | return ptr->allocators.realloc(ptr, mem, size, ptr->allocators.context); | 225 | return ptr->allocators->realloc(ptr, mem, size, ptr->allocators->context); |
1711 | 218 | } | 226 | } |
1712 | 219 | 227 | ||
1713 | 220 | static inline void *libmemcached_calloc(const memcached_st *ptr, size_t nelem, size_t size) | 228 | static inline void *libmemcached_calloc(const memcached_st *ptr, size_t nelem, size_t size) |
1714 | 221 | { | 229 | { |
1716 | 222 | return ptr->allocators.calloc(ptr, nelem, size, ptr->allocators.context); | 230 | return ptr->allocators->calloc(ptr, nelem, size, ptr->allocators->context); |
1717 | 223 | } | 231 | } |
1718 | 224 | 232 | ||
1719 | 225 | #ifdef __cplusplus | 233 | #ifdef __cplusplus |
1720 | 226 | 234 | ||
1721 | === modified file 'libmemcached/connect.c' | |||
1722 | --- libmemcached/connect.c 2010-09-13 06:05:34 +0000 | |||
1723 | +++ libmemcached/connect.c 2011-01-13 03:40:43 +0000 | |||
1724 | @@ -10,22 +10,26 @@ | |||
1725 | 10 | */ | 10 | */ |
1726 | 11 | 11 | ||
1727 | 12 | #include "common.h" | 12 | #include "common.h" |
1729 | 13 | #include <sys/time.h> | 13 | #ifndef WIN32 |
1730 | 14 | # include <sys/time.h> | ||
1731 | 15 | #endif | ||
1732 | 14 | #include <time.h> | 16 | #include <time.h> |
1733 | 15 | 17 | ||
1734 | 16 | static memcached_return_t connect_poll(memcached_server_st *ptr) | 18 | static memcached_return_t connect_poll(memcached_server_st *ptr) |
1735 | 17 | { | 19 | { |
1736 | 20 | int timeout; | ||
1737 | 21 | |||
1738 | 22 | int error; | ||
1739 | 23 | size_t loop_max= 5; | ||
1740 | 24 | |||
1741 | 18 | struct pollfd fds[1]; | 25 | struct pollfd fds[1]; |
1742 | 19 | fds[0].fd = ptr->fd; | 26 | fds[0].fd = ptr->fd; |
1743 | 20 | fds[0].events = POLLOUT; | 27 | fds[0].events = POLLOUT; |
1744 | 21 | 28 | ||
1746 | 22 | int timeout= ptr->root->connect_timeout; | 29 | timeout= ptr->root->connect_timeout; |
1747 | 23 | if (ptr->root->flags.no_block == true) | 30 | if (ptr->root->flags.no_block == true) |
1748 | 24 | timeout= -1; | 31 | timeout= -1; |
1749 | 25 | 32 | ||
1750 | 26 | int error; | ||
1751 | 27 | size_t loop_max= 5; | ||
1752 | 28 | |||
1753 | 29 | while (--loop_max) // Should only loop on cases of ERESTART or EINTR | 33 | while (--loop_max) // Should only loop on cases of ERESTART or EINTR |
1754 | 30 | { | 34 | { |
1755 | 31 | error= poll(fds, 1, timeout); | 35 | error= poll(fds, 1, timeout); |
1756 | @@ -371,7 +375,7 @@ | |||
1757 | 371 | static memcached_return_t network_connect(memcached_server_st *ptr) | 375 | static memcached_return_t network_connect(memcached_server_st *ptr) |
1758 | 372 | { | 376 | { |
1759 | 373 | bool timeout_error_occured= false; | 377 | bool timeout_error_occured= false; |
1761 | 374 | 378 | struct addrinfo *use; | |
1762 | 375 | 379 | ||
1763 | 376 | WATCHPOINT_ASSERT(ptr->fd == INVALID_SOCKET); | 380 | WATCHPOINT_ASSERT(ptr->fd == INVALID_SOCKET); |
1764 | 377 | WATCHPOINT_ASSERT(ptr->cursor_active == 0); | 381 | WATCHPOINT_ASSERT(ptr->cursor_active == 0); |
1765 | @@ -386,7 +390,7 @@ | |||
1766 | 386 | ptr->options.sockaddr_inited= true; | 390 | ptr->options.sockaddr_inited= true; |
1767 | 387 | } | 391 | } |
1768 | 388 | 392 | ||
1770 | 389 | struct addrinfo *use= ptr->address_info; | 393 | use= ptr->address_info; |
1771 | 390 | /* Create the socket */ | 394 | /* Create the socket */ |
1772 | 391 | while (use != NULL) | 395 | while (use != NULL) |
1773 | 392 | { | 396 | { |
1774 | 393 | 397 | ||
1775 | === modified file 'libmemcached/delete.c' | |||
1776 | --- libmemcached/delete.c 2010-09-13 12:26:17 +0000 | |||
1777 | +++ libmemcached/delete.c 2011-01-13 03:40:43 +0000 | |||
1778 | @@ -25,6 +25,7 @@ | |||
1779 | 25 | char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; | 25 | char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; |
1780 | 26 | uint32_t server_key; | 26 | uint32_t server_key; |
1781 | 27 | memcached_server_write_instance_st instance; | 27 | memcached_server_write_instance_st instance; |
1782 | 28 | bool no_reply; | ||
1783 | 28 | 29 | ||
1784 | 29 | LIBMEMCACHED_MEMCACHED_DELETE_START(); | 30 | LIBMEMCACHED_MEMCACHED_DELETE_START(); |
1785 | 30 | 31 | ||
1786 | @@ -41,7 +42,7 @@ | |||
1787 | 41 | 42 | ||
1788 | 42 | to_write= (ptr->flags.buffer_requests) ? false : true; | 43 | to_write= (ptr->flags.buffer_requests) ? false : true; |
1789 | 43 | 44 | ||
1791 | 44 | bool no_reply= (ptr->flags.no_reply); | 45 | no_reply= (ptr->flags.no_reply); |
1792 | 45 | 46 | ||
1793 | 46 | if (ptr->flags.binary_protocol) | 47 | if (ptr->flags.binary_protocol) |
1794 | 47 | { | 48 | { |
1795 | @@ -153,7 +154,12 @@ | |||
1796 | 153 | bool flush) | 154 | bool flush) |
1797 | 154 | { | 155 | { |
1798 | 155 | memcached_server_write_instance_st instance; | 156 | memcached_server_write_instance_st instance; |
1800 | 156 | protocol_binary_request_delete request= {.bytes= {0}}; | 157 | protocol_binary_request_delete request; |
1801 | 158 | struct libmemcached_io_vector_st vector[3]; | ||
1802 | 159 | memcached_return_t rc; | ||
1803 | 160 | uint32_t x; | ||
1804 | 161 | |||
1805 | 162 | memset(&request, 0, sizeof(request)); | ||
1806 | 157 | 163 | ||
1807 | 158 | instance= memcached_server_instance_fetch(ptr, server_key); | 164 | instance= memcached_server_instance_fetch(ptr, server_key); |
1808 | 159 | 165 | ||
1809 | @@ -175,14 +181,14 @@ | |||
1810 | 175 | memcached_io_write(instance, NULL, 0, true); | 181 | memcached_io_write(instance, NULL, 0, true); |
1811 | 176 | } | 182 | } |
1812 | 177 | 183 | ||
1819 | 178 | struct libmemcached_io_vector_st vector[]= | 184 | vector[0].length= sizeof(request.bytes); |
1820 | 179 | { | 185 | vector[0].buffer= request.bytes; |
1821 | 180 | { .length= sizeof(request.bytes), .buffer= request.bytes}, | 186 | vector[1].length= ptr->prefix_key_length; |
1822 | 181 | { .length= ptr->prefix_key_length, .buffer= ptr->prefix_key }, | 187 | vector[1].buffer= ptr->prefix_key; |
1823 | 182 | { .length= key_length, .buffer= key }, | 188 | vector[2].length= key_length; |
1824 | 183 | }; | 189 | vector[2].buffer= key; |
1825 | 184 | 190 | ||
1827 | 185 | memcached_return_t rc= MEMCACHED_SUCCESS; | 191 | rc= MEMCACHED_SUCCESS; |
1828 | 186 | 192 | ||
1829 | 187 | if ((rc= memcached_vdo(instance, vector, 3, flush)) != MEMCACHED_SUCCESS) | 193 | if ((rc= memcached_vdo(instance, vector, 3, flush)) != MEMCACHED_SUCCESS) |
1830 | 188 | { | 194 | { |
1831 | @@ -194,7 +200,7 @@ | |||
1832 | 194 | { | 200 | { |
1833 | 195 | request.message.header.request.opcode= PROTOCOL_BINARY_CMD_DELETEQ; | 201 | request.message.header.request.opcode= PROTOCOL_BINARY_CMD_DELETEQ; |
1834 | 196 | 202 | ||
1836 | 197 | for (uint32_t x= 0; x < ptr->number_of_replicas; ++x) | 203 | for (x= 0; x < ptr->number_of_replicas; ++x) |
1837 | 198 | { | 204 | { |
1838 | 199 | memcached_server_write_instance_st replica; | 205 | memcached_server_write_instance_st replica; |
1839 | 200 | 206 | ||
1840 | 201 | 207 | ||
1841 | === modified file 'libmemcached/do.c' | |||
1842 | --- libmemcached/do.c 2010-09-13 12:26:17 +0000 | |||
1843 | +++ libmemcached/do.c 2011-01-13 03:40:43 +0000 | |||
1844 | @@ -56,6 +56,8 @@ | |||
1845 | 56 | { | 56 | { |
1846 | 57 | memcached_return_t rc; | 57 | memcached_return_t rc; |
1847 | 58 | ssize_t sent_length; | 58 | ssize_t sent_length; |
1848 | 59 | size_t command_length; | ||
1849 | 60 | uint32_t x; | ||
1850 | 59 | 61 | ||
1851 | 60 | WATCHPOINT_ASSERT(count); | 62 | WATCHPOINT_ASSERT(count); |
1852 | 61 | WATCHPOINT_ASSERT(vector); | 63 | WATCHPOINT_ASSERT(vector); |
1853 | @@ -78,8 +80,8 @@ | |||
1854 | 78 | 80 | ||
1855 | 79 | sent_length= memcached_io_writev(ptr, vector, count, with_flush); | 81 | sent_length= memcached_io_writev(ptr, vector, count, with_flush); |
1856 | 80 | 82 | ||
1859 | 81 | size_t command_length= 0; | 83 | command_length= 0; |
1860 | 82 | for (uint32_t x= 0; x < count; ++x, vector++) | 84 | for (x= 0; x < count; ++x, vector++) |
1861 | 83 | { | 85 | { |
1862 | 84 | command_length+= vector->length; | 86 | command_length+= vector->length; |
1863 | 85 | } | 87 | } |
1864 | 86 | 88 | ||
1865 | === modified file 'libmemcached/fetch.c' | |||
1866 | --- libmemcached/fetch.c 2010-04-01 21:30:52 +0000 | |||
1867 | +++ libmemcached/fetch.c 2011-01-13 03:40:43 +0000 | |||
1868 | @@ -91,12 +91,13 @@ | |||
1869 | 91 | { | 91 | { |
1870 | 92 | memcached_result_st *result= &ptr->result; | 92 | memcached_result_st *result= &ptr->result; |
1871 | 93 | memcached_return_t rc= MEMCACHED_FAILURE; | 93 | memcached_return_t rc= MEMCACHED_FAILURE; |
1872 | 94 | uint32_t x; | ||
1873 | 94 | 95 | ||
1874 | 95 | while ((result= memcached_fetch_result(ptr, result, &rc)) != NULL) | 96 | while ((result= memcached_fetch_result(ptr, result, &rc)) != NULL) |
1875 | 96 | { | 97 | { |
1876 | 97 | if (rc == MEMCACHED_SUCCESS) | 98 | if (rc == MEMCACHED_SUCCESS) |
1877 | 98 | { | 99 | { |
1879 | 99 | for (uint32_t x= 0; x < number_of_callbacks; x++) | 100 | for (x= 0; x < number_of_callbacks; x++) |
1880 | 100 | { | 101 | { |
1881 | 101 | rc= (*callback[x])(ptr, result, context); | 102 | rc= (*callback[x])(ptr, result, context); |
1882 | 102 | if (rc != MEMCACHED_SUCCESS) | 103 | if (rc != MEMCACHED_SUCCESS) |
1883 | 103 | 104 | ||
1884 | === modified file 'libmemcached/flush.c' | |||
1885 | --- libmemcached/flush.c 2010-04-02 19:55:21 +0000 | |||
1886 | +++ libmemcached/flush.c 2011-01-13 03:40:43 +0000 | |||
1887 | @@ -55,7 +55,10 @@ | |||
1888 | 55 | static memcached_return_t memcached_flush_binary(memcached_st *ptr, | 55 | static memcached_return_t memcached_flush_binary(memcached_st *ptr, |
1889 | 56 | time_t expiration) | 56 | time_t expiration) |
1890 | 57 | { | 57 | { |
1892 | 58 | protocol_binary_request_flush request= {.bytes= {0}}; | 58 | protocol_binary_request_flush request; |
1893 | 59 | uint32_t x; | ||
1894 | 60 | |||
1895 | 61 | memset(&request, 0, sizeof(request)); | ||
1896 | 59 | 62 | ||
1897 | 60 | unlikely (memcached_server_count(ptr) == 0) | 63 | unlikely (memcached_server_count(ptr) == 0) |
1898 | 61 | return MEMCACHED_NO_SERVERS; | 64 | return MEMCACHED_NO_SERVERS; |
1899 | @@ -67,7 +70,7 @@ | |||
1900 | 67 | request.message.header.request.bodylen= htonl(request.message.header.request.extlen); | 70 | request.message.header.request.bodylen= htonl(request.message.header.request.extlen); |
1901 | 68 | request.message.body.expiration= htonl((uint32_t) expiration); | 71 | request.message.body.expiration= htonl((uint32_t) expiration); |
1902 | 69 | 72 | ||
1904 | 70 | for (uint32_t x= 0; x < memcached_server_count(ptr); x++) | 73 | for (x= 0; x < memcached_server_count(ptr); x++) |
1905 | 71 | { | 74 | { |
1906 | 72 | memcached_server_write_instance_st instance= | 75 | memcached_server_write_instance_st instance= |
1907 | 73 | memcached_server_instance_fetch(ptr, x); | 76 | memcached_server_instance_fetch(ptr, x); |
1908 | @@ -88,7 +91,7 @@ | |||
1909 | 88 | } | 91 | } |
1910 | 89 | } | 92 | } |
1911 | 90 | 93 | ||
1913 | 91 | for (uint32_t x= 0; x < memcached_server_count(ptr); x++) | 94 | for (x= 0; x < memcached_server_count(ptr); x++) |
1914 | 92 | { | 95 | { |
1915 | 93 | memcached_server_write_instance_st instance= | 96 | memcached_server_write_instance_st instance= |
1916 | 94 | memcached_server_instance_fetch(ptr, x); | 97 | memcached_server_instance_fetch(ptr, x); |
1917 | 95 | 98 | ||
1918 | === modified file 'libmemcached/flush_buffers.c' | |||
1919 | --- libmemcached/flush_buffers.c 2010-02-13 02:23:49 +0000 | |||
1920 | +++ libmemcached/flush_buffers.c 2011-01-13 03:40:43 +0000 | |||
1921 | @@ -3,8 +3,9 @@ | |||
1922 | 3 | memcached_return_t memcached_flush_buffers(memcached_st *memc) | 3 | memcached_return_t memcached_flush_buffers(memcached_st *memc) |
1923 | 4 | { | 4 | { |
1924 | 5 | memcached_return_t ret= MEMCACHED_SUCCESS; | 5 | memcached_return_t ret= MEMCACHED_SUCCESS; |
1925 | 6 | uint32_t x; | ||
1926 | 6 | 7 | ||
1928 | 7 | for (uint32_t x= 0; x < memcached_server_count(memc); ++x) | 8 | for (x= 0; x < memcached_server_count(memc); ++x) |
1929 | 8 | { | 9 | { |
1930 | 9 | memcached_server_write_instance_st instance= | 10 | memcached_server_write_instance_st instance= |
1931 | 10 | memcached_server_instance_fetch(memc, x); | 11 | memcached_server_instance_fetch(memc, x); |
1932 | 11 | 12 | ||
1933 | === modified file 'libmemcached/get.c' | |||
1934 | --- libmemcached/get.c 2010-09-13 12:26:17 +0000 | |||
1935 | +++ libmemcached/get.c 2011-01-13 03:40:43 +0000 | |||
1936 | @@ -149,6 +149,8 @@ | |||
1937 | 149 | uint8_t get_command_length= 4; | 149 | uint8_t get_command_length= 4; |
1938 | 150 | unsigned int master_server_key= (unsigned int)-1; /* 0 is a valid server id! */ | 150 | unsigned int master_server_key= (unsigned int)-1; /* 0 is a valid server id! */ |
1939 | 151 | bool is_master_key_set= false; | 151 | bool is_master_key_set= false; |
1940 | 152 | uint32_t x; | ||
1941 | 153 | struct libmemcached_io_vector_st vector[4]; | ||
1942 | 152 | 154 | ||
1943 | 153 | unlikely (ptr->flags.use_udp) | 155 | unlikely (ptr->flags.use_udp) |
1944 | 154 | return MEMCACHED_NOT_SUPPORTED; | 156 | return MEMCACHED_NOT_SUPPORTED; |
1945 | @@ -178,7 +180,7 @@ | |||
1946 | 178 | 180 | ||
1947 | 179 | It might be optimum to bounce the connection if count > some number. | 181 | It might be optimum to bounce the connection if count > some number. |
1948 | 180 | */ | 182 | */ |
1950 | 181 | for (uint32_t x= 0; x < memcached_server_count(ptr); x++) | 183 | for (x= 0; x < memcached_server_count(ptr); x++) |
1951 | 182 | { | 184 | { |
1952 | 183 | memcached_server_write_instance_st instance= | 185 | memcached_server_write_instance_st instance= |
1953 | 184 | memcached_server_instance_fetch(ptr, x); | 186 | memcached_server_instance_fetch(ptr, x); |
1954 | @@ -211,7 +213,7 @@ | |||
1955 | 211 | If a server fails we warn about errors and start all over with sending keys | 213 | If a server fails we warn about errors and start all over with sending keys |
1956 | 212 | to the server. | 214 | to the server. |
1957 | 213 | */ | 215 | */ |
1959 | 214 | for (uint32_t x= 0; x < number_of_keys; x++) | 216 | for (x= 0; x < number_of_keys; x++) |
1960 | 215 | { | 217 | { |
1961 | 216 | memcached_server_write_instance_st instance; | 218 | memcached_server_write_instance_st instance; |
1962 | 217 | uint32_t server_key; | 219 | uint32_t server_key; |
1963 | @@ -227,14 +229,14 @@ | |||
1964 | 227 | 229 | ||
1965 | 228 | instance= memcached_server_instance_fetch(ptr, server_key); | 230 | instance= memcached_server_instance_fetch(ptr, server_key); |
1966 | 229 | 231 | ||
1975 | 230 | struct libmemcached_io_vector_st vector[]= | 232 | vector[0].length= get_command_length; |
1976 | 231 | { | 233 | vector[0].buffer= get_command; |
1977 | 232 | { .length= get_command_length, .buffer= get_command }, | 234 | vector[1].length= ptr->prefix_key_length; |
1978 | 233 | { .length= ptr->prefix_key_length, .buffer= ptr->prefix_key }, | 235 | vector[1].buffer= ptr->prefix_key; |
1979 | 234 | { .length= key_length[x], .buffer= keys[x] }, | 236 | vector[2].length= key_length[x]; |
1980 | 235 | { .length= 1, .buffer= " " } | 237 | vector[2].buffer= keys[x]; |
1981 | 236 | }; | 238 | vector[3].length= 1; |
1982 | 237 | 239 | vector[3].buffer= " "; | |
1983 | 238 | 240 | ||
1984 | 239 | if (memcached_server_response_count(instance) == 0) | 241 | if (memcached_server_response_count(instance) == 0) |
1985 | 240 | { | 242 | { |
1986 | @@ -266,7 +268,7 @@ | |||
1987 | 266 | /* | 268 | /* |
1988 | 267 | Should we muddle on if some servers are dead? | 269 | Should we muddle on if some servers are dead? |
1989 | 268 | */ | 270 | */ |
1991 | 269 | for (uint32_t x= 0; x < memcached_server_count(ptr); x++) | 271 | for (x= 0; x < memcached_server_count(ptr); x++) |
1992 | 270 | { | 272 | { |
1993 | 271 | memcached_server_write_instance_st instance= | 273 | memcached_server_write_instance_st instance= |
1994 | 272 | memcached_server_instance_fetch(ptr, x); | 274 | memcached_server_instance_fetch(ptr, x); |
1995 | @@ -319,16 +321,16 @@ | |||
1996 | 319 | void *context, | 321 | void *context, |
1997 | 320 | unsigned int number_of_callbacks) | 322 | unsigned int number_of_callbacks) |
1998 | 321 | { | 323 | { |
1999 | 324 | memcached_return_t rc; | ||
2000 | 325 | memcached_callback_st *original_callbacks= ptr->callbacks; | ||
2001 | 326 | memcached_callback_st cb; | ||
2002 | 327 | |||
2003 | 322 | if ((ptr->flags.binary_protocol) == 0) | 328 | if ((ptr->flags.binary_protocol) == 0) |
2004 | 323 | return MEMCACHED_NOT_SUPPORTED; | 329 | return MEMCACHED_NOT_SUPPORTED; |
2005 | 324 | 330 | ||
2013 | 325 | memcached_return_t rc; | 331 | cb.callback= callback; |
2014 | 326 | memcached_callback_st *original_callbacks= ptr->callbacks; | 332 | cb.context= context; |
2015 | 327 | memcached_callback_st cb= { | 333 | cb.number_of_callback= number_of_callbacks; |
2009 | 328 | .callback= callback, | ||
2010 | 329 | .context= context, | ||
2011 | 330 | .number_of_callback= number_of_callbacks | ||
2012 | 331 | }; | ||
2016 | 332 | 334 | ||
2017 | 333 | ptr->callbacks= &cb; | 335 | ptr->callbacks= &cb; |
2018 | 334 | rc= memcached_mget_by_key(ptr, master_key, master_key_length, keys, | 336 | rc= memcached_mget_by_key(ptr, master_key, master_key_length, keys, |
2019 | @@ -345,6 +347,7 @@ | |||
2020 | 345 | size_t number_of_keys, bool mget_mode) | 347 | size_t number_of_keys, bool mget_mode) |
2021 | 346 | { | 348 | { |
2022 | 347 | memcached_return_t rc= MEMCACHED_NOTFOUND; | 349 | memcached_return_t rc= MEMCACHED_NOTFOUND; |
2023 | 350 | uint32_t x; | ||
2024 | 348 | 351 | ||
2025 | 349 | int flush= number_of_keys == 1; | 352 | int flush= number_of_keys == 1; |
2026 | 350 | 353 | ||
2027 | @@ -352,10 +355,15 @@ | |||
2028 | 352 | If a server fails we warn about errors and start all over with sending keys | 355 | If a server fails we warn about errors and start all over with sending keys |
2029 | 353 | to the server. | 356 | to the server. |
2030 | 354 | */ | 357 | */ |
2032 | 355 | for (uint32_t x= 0; x < number_of_keys; ++x) | 358 | for (x= 0; x < number_of_keys; ++x) |
2033 | 356 | { | 359 | { |
2034 | 357 | uint32_t server_key; | 360 | uint32_t server_key; |
2035 | 358 | memcached_server_write_instance_st instance; | 361 | memcached_server_write_instance_st instance; |
2036 | 362 | protocol_binary_request_getk request; | ||
2037 | 363 | memcached_return_t vk; | ||
2038 | 364 | struct libmemcached_io_vector_st vector[3]; | ||
2039 | 365 | |||
2040 | 366 | memset(&request, 0, sizeof(request)); | ||
2041 | 359 | 367 | ||
2042 | 360 | if (is_master_key_set) | 368 | if (is_master_key_set) |
2043 | 361 | { | 369 | { |
2044 | @@ -375,14 +383,12 @@ | |||
2045 | 375 | continue; | 383 | continue; |
2046 | 376 | } | 384 | } |
2047 | 377 | 385 | ||
2048 | 378 | protocol_binary_request_getk request= {.bytes= {0}}; | ||
2049 | 379 | request.message.header.request.magic= PROTOCOL_BINARY_REQ; | 386 | request.message.header.request.magic= PROTOCOL_BINARY_REQ; |
2050 | 380 | if (mget_mode) | 387 | if (mget_mode) |
2051 | 381 | request.message.header.request.opcode= PROTOCOL_BINARY_CMD_GETKQ; | 388 | request.message.header.request.opcode= PROTOCOL_BINARY_CMD_GETKQ; |
2052 | 382 | else | 389 | else |
2053 | 383 | request.message.header.request.opcode= PROTOCOL_BINARY_CMD_GETK; | 390 | request.message.header.request.opcode= PROTOCOL_BINARY_CMD_GETK; |
2056 | 384 | 391 | ||
2055 | 385 | memcached_return_t vk; | ||
2057 | 386 | vk= memcached_validate_key_length(key_length[x], | 392 | vk= memcached_validate_key_length(key_length[x], |
2058 | 387 | ptr->flags.binary_protocol); | 393 | ptr->flags.binary_protocol); |
2059 | 388 | unlikely (vk != MEMCACHED_SUCCESS) | 394 | unlikely (vk != MEMCACHED_SUCCESS) |
2060 | @@ -399,12 +405,12 @@ | |||
2061 | 399 | request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; | 405 | request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; |
2062 | 400 | request.message.header.request.bodylen= htonl((uint32_t)( key_length[x] + ptr->prefix_key_length)); | 406 | request.message.header.request.bodylen= htonl((uint32_t)( key_length[x] + ptr->prefix_key_length)); |
2063 | 401 | 407 | ||
2070 | 402 | struct libmemcached_io_vector_st vector[]= | 408 | vector[0].length= sizeof(request.bytes); |
2071 | 403 | { | 409 | vector[0].buffer= request.bytes; |
2072 | 404 | { .length= sizeof(request.bytes), .buffer= request.bytes }, | 410 | vector[1].length= ptr->prefix_key_length; |
2073 | 405 | { .length= ptr->prefix_key_length, .buffer= ptr->prefix_key }, | 411 | vector[1].buffer= ptr->prefix_key; |
2074 | 406 | { .length= key_length[x], .buffer= keys[x] } | 412 | vector[2].length= key_length[x]; |
2075 | 407 | }; | 413 | vector[2].buffer= keys[x]; |
2076 | 408 | 414 | ||
2077 | 409 | if (memcached_io_writev(instance, vector, 3, flush) == -1) | 415 | if (memcached_io_writev(instance, vector, 3, flush) == -1) |
2078 | 410 | { | 416 | { |
2079 | @@ -427,12 +433,16 @@ | |||
2080 | 427 | /* | 433 | /* |
2081 | 428 | * Send a noop command to flush the buffers | 434 | * Send a noop command to flush the buffers |
2082 | 429 | */ | 435 | */ |
2084 | 430 | protocol_binary_request_noop request= {.bytes= {0}}; | 436 | uint32_t x; |
2085 | 437 | protocol_binary_request_noop request; | ||
2086 | 438 | |||
2087 | 439 | memset(&request, 0, sizeof(request)); | ||
2088 | 440 | |||
2089 | 431 | request.message.header.request.magic= PROTOCOL_BINARY_REQ; | 441 | request.message.header.request.magic= PROTOCOL_BINARY_REQ; |
2090 | 432 | request.message.header.request.opcode= PROTOCOL_BINARY_CMD_NOOP; | 442 | request.message.header.request.opcode= PROTOCOL_BINARY_CMD_NOOP; |
2091 | 433 | request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; | 443 | request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; |
2092 | 434 | 444 | ||
2094 | 435 | for (uint32_t x= 0; x < memcached_server_count(ptr); ++x) | 445 | for (x= 0; x < memcached_server_count(ptr); ++x) |
2095 | 436 | { | 446 | { |
2096 | 437 | memcached_server_write_instance_st instance= | 447 | memcached_server_write_instance_st instance= |
2097 | 438 | memcached_server_instance_fetch(ptr, x); | 448 | memcached_server_instance_fetch(ptr, x); |
2098 | @@ -471,23 +481,30 @@ | |||
2099 | 471 | memcached_return_t rc= MEMCACHED_NOTFOUND; | 481 | memcached_return_t rc= MEMCACHED_NOTFOUND; |
2100 | 472 | uint32_t start= 0; | 482 | uint32_t start= 0; |
2101 | 473 | uint64_t randomize_read= memcached_behavior_get(ptr, MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ); | 483 | uint64_t randomize_read= memcached_behavior_get(ptr, MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ); |
2102 | 484 | uint32_t replica; | ||
2103 | 474 | 485 | ||
2104 | 475 | if (randomize_read) | 486 | if (randomize_read) |
2105 | 476 | start= (uint32_t)random() % (uint32_t)(ptr->number_of_replicas + 1); | 487 | start= (uint32_t)random() % (uint32_t)(ptr->number_of_replicas + 1); |
2106 | 477 | 488 | ||
2107 | 478 | /* Loop for each replica */ | 489 | /* Loop for each replica */ |
2109 | 479 | for (uint32_t replica= 0; replica <= ptr->number_of_replicas; ++replica) | 490 | for (replica= 0; replica <= ptr->number_of_replicas; ++replica) |
2110 | 480 | { | 491 | { |
2111 | 481 | bool success= true; | 492 | bool success= true; |
2114 | 482 | 493 | uint32_t x; | |
2115 | 483 | for (uint32_t x= 0; x < number_of_keys; ++x) | 494 | protocol_binary_request_getk request; |
2116 | 495 | struct libmemcached_io_vector_st vector[3]; | ||
2117 | 496 | |||
2118 | 497 | memset(&request, 0, sizeof(request)); | ||
2119 | 498 | |||
2120 | 499 | for (x= 0; x < number_of_keys; ++x) | ||
2121 | 484 | { | 500 | { |
2122 | 485 | memcached_server_write_instance_st instance; | 501 | memcached_server_write_instance_st instance; |
2123 | 502 | uint32_t server; | ||
2124 | 486 | 503 | ||
2125 | 487 | if (hash[x] == memcached_server_count(ptr)) | 504 | if (hash[x] == memcached_server_count(ptr)) |
2126 | 488 | continue; /* Already successfully sent */ | 505 | continue; /* Already successfully sent */ |
2127 | 489 | 506 | ||
2129 | 490 | uint32_t server= hash[x] + replica; | 507 | server= hash[x] + replica; |
2130 | 491 | 508 | ||
2131 | 492 | /* In case of randomized reads */ | 509 | /* In case of randomized reads */ |
2132 | 493 | if (randomize_read && ((server + start) <= (hash[x] + ptr->number_of_replicas))) | 510 | if (randomize_read && ((server + start) <= (hash[x] + ptr->number_of_replicas))) |
2133 | @@ -512,16 +529,12 @@ | |||
2134 | 512 | continue; | 529 | continue; |
2135 | 513 | } | 530 | } |
2136 | 514 | } | 531 | } |
2147 | 515 | 532 | ||
2148 | 516 | protocol_binary_request_getk request= { | 533 | request.message.header.request.magic= PROTOCOL_BINARY_REQ; |
2149 | 517 | .message.header.request= { | 534 | request.message.header.request.opcode= PROTOCOL_BINARY_CMD_GETK; |
2150 | 518 | .magic= PROTOCOL_BINARY_REQ, | 535 | request.message.header.request.keylen= htons((uint16_t)(key_length[x] + ptr->prefix_key_length)); |
2151 | 519 | .opcode= PROTOCOL_BINARY_CMD_GETK, | 536 | request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; |
2152 | 520 | .keylen= htons((uint16_t)(key_length[x] + ptr->prefix_key_length)), | 537 | request.message.header.request.bodylen= htonl((uint32_t)(key_length[x] + ptr->prefix_key_length)); |
2143 | 521 | .datatype= PROTOCOL_BINARY_RAW_BYTES, | ||
2144 | 522 | .bodylen= htonl((uint32_t)(key_length[x] + ptr->prefix_key_length)) | ||
2145 | 523 | } | ||
2146 | 524 | }; | ||
2153 | 525 | 538 | ||
2154 | 526 | /* | 539 | /* |
2155 | 527 | * We need to disable buffering to actually know that the request was | 540 | * We need to disable buffering to actually know that the request was |
2156 | @@ -533,12 +546,12 @@ | |||
2157 | 533 | * that we might have processed some of the responses etc. For now, | 546 | * that we might have processed some of the responses etc. For now, |
2158 | 534 | * just make sure we work _correctly_ | 547 | * just make sure we work _correctly_ |
2159 | 535 | */ | 548 | */ |
2166 | 536 | struct libmemcached_io_vector_st vector[]= | 549 | vector[0].length= sizeof(request.bytes); |
2167 | 537 | { | 550 | vector[0].buffer= request.bytes; |
2168 | 538 | { .length= sizeof(request.bytes), .buffer= request.bytes }, | 551 | vector[1].length= ptr->prefix_key_length; |
2169 | 539 | { .length= ptr->prefix_key_length, .buffer= ptr->prefix_key }, | 552 | vector[1].buffer= ptr->prefix_key; |
2170 | 540 | { .length= key_length[x], .buffer= keys[x] } | 553 | vector[2].length= key_length[x]; |
2171 | 541 | }; | 554 | vector[2].buffer= keys[x]; |
2172 | 542 | 555 | ||
2173 | 543 | if (memcached_io_writev(instance, vector, 3, true) == -1) | 556 | if (memcached_io_writev(instance, vector, 3, true) == -1) |
2174 | 544 | { | 557 | { |
2175 | @@ -578,6 +591,7 @@ | |||
2176 | 578 | { | 591 | { |
2177 | 579 | uint32_t* hash; | 592 | uint32_t* hash; |
2178 | 580 | bool* dead_servers; | 593 | bool* dead_servers; |
2179 | 594 | size_t x; | ||
2180 | 581 | 595 | ||
2181 | 582 | hash= libmemcached_malloc(ptr, sizeof(uint32_t) * number_of_keys); | 596 | hash= libmemcached_malloc(ptr, sizeof(uint32_t) * number_of_keys); |
2182 | 583 | dead_servers= libmemcached_calloc(ptr, memcached_server_count(ptr), sizeof(bool)); | 597 | dead_servers= libmemcached_calloc(ptr, memcached_server_count(ptr), sizeof(bool)); |
2183 | @@ -591,14 +605,14 @@ | |||
2184 | 591 | 605 | ||
2185 | 592 | if (is_master_key_set) | 606 | if (is_master_key_set) |
2186 | 593 | { | 607 | { |
2188 | 594 | for (size_t x= 0; x < number_of_keys; x++) | 608 | for (x= 0; x < number_of_keys; x++) |
2189 | 595 | { | 609 | { |
2190 | 596 | hash[x]= master_server_key; | 610 | hash[x]= master_server_key; |
2191 | 597 | } | 611 | } |
2192 | 598 | } | 612 | } |
2193 | 599 | else | 613 | else |
2194 | 600 | { | 614 | { |
2196 | 601 | for (size_t x= 0; x < number_of_keys; x++) | 615 | for (x= 0; x < number_of_keys; x++) |
2197 | 602 | { | 616 | { |
2198 | 603 | hash[x]= memcached_generate_hash_with_redistribution(ptr, keys[x], key_length[x]); | 617 | hash[x]= memcached_generate_hash_with_redistribution(ptr, keys[x], key_length[x]); |
2199 | 604 | } | 618 | } |
2200 | 605 | 619 | ||
2201 | === modified file 'libmemcached/hash.c' | |||
2202 | --- libmemcached/hash.c 2010-03-02 22:16:10 +0000 | |||
2203 | +++ libmemcached/hash.c 2011-01-13 03:40:43 +0000 | |||
2204 | @@ -30,11 +30,12 @@ | |||
2205 | 30 | case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA: | 30 | case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA: |
2206 | 31 | case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY: | 31 | case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY: |
2207 | 32 | { | 32 | { |
2208 | 33 | memcached_continuum_item_st *begin, *end, *left, *right, *middle; | ||
2209 | 33 | uint32_t num= ptr->continuum_points_counter; | 34 | uint32_t num= ptr->continuum_points_counter; |
2210 | 34 | WATCHPOINT_ASSERT(ptr->continuum); | 35 | WATCHPOINT_ASSERT(ptr->continuum); |
2211 | 35 | 36 | ||
2212 | 36 | hash= hash; | 37 | hash= hash; |
2214 | 37 | memcached_continuum_item_st *begin, *end, *left, *right, *middle; | 38 | |
2215 | 38 | begin= left= ptr->continuum; | 39 | begin= left= ptr->continuum; |
2216 | 39 | end= right= ptr->continuum + num; | 40 | end= right= ptr->continuum + num; |
2217 | 40 | 41 | ||
2218 | @@ -75,7 +76,8 @@ | |||
2219 | 75 | if (ptr->flags.hash_with_prefix_key) | 76 | if (ptr->flags.hash_with_prefix_key) |
2220 | 76 | { | 77 | { |
2221 | 77 | size_t temp_length= ptr->prefix_key_length + key_length; | 78 | size_t temp_length= ptr->prefix_key_length + key_length; |
2223 | 78 | char temp[temp_length]; | 79 | char *temp = (char *) malloc(temp_length); |
2224 | 80 | uint32_t hash; | ||
2225 | 79 | 81 | ||
2226 | 80 | if (temp_length > MEMCACHED_MAX_KEY -1) | 82 | if (temp_length > MEMCACHED_MAX_KEY -1) |
2227 | 81 | return 0; | 83 | return 0; |
2228 | @@ -83,7 +85,11 @@ | |||
2229 | 83 | strncpy(temp, ptr->prefix_key, ptr->prefix_key_length); | 85 | strncpy(temp, ptr->prefix_key, ptr->prefix_key_length); |
2230 | 84 | strncpy(temp + ptr->prefix_key_length, key, key_length); | 86 | strncpy(temp + ptr->prefix_key_length, key, key_length); |
2231 | 85 | 87 | ||
2233 | 86 | return generate_hash(ptr, temp, temp_length); | 88 | hash = generate_hash(ptr, temp, temp_length); |
2234 | 89 | |||
2235 | 90 | free(temp); | ||
2236 | 91 | |||
2237 | 92 | return hash; | ||
2238 | 87 | } | 93 | } |
2239 | 88 | else | 94 | else |
2240 | 89 | { | 95 | { |
2241 | 90 | 96 | ||
2242 | === modified file 'libmemcached/hosts.c' | |||
2243 | --- libmemcached/hosts.c 2010-04-05 22:27:54 +0000 | |||
2244 | +++ libmemcached/hosts.c 2011-01-13 03:40:43 +0000 | |||
2245 | @@ -207,6 +207,7 @@ | |||
2246 | 207 | { | 207 | { |
2247 | 208 | char sort_host[MEMCACHED_MAX_HOST_SORT_LENGTH]= ""; | 208 | char sort_host[MEMCACHED_MAX_HOST_SORT_LENGTH]= ""; |
2248 | 209 | size_t sort_host_length; | 209 | size_t sort_host_length; |
2249 | 210 | uint32_t x; | ||
2250 | 210 | 211 | ||
2251 | 211 | // Spymemcached ketema key format is: hostname/ip:port-index | 212 | // Spymemcached ketema key format is: hostname/ip:port-index |
2252 | 212 | // If hostname is not available then: /ip:port-index | 213 | // If hostname is not available then: /ip:port-index |
2253 | @@ -223,7 +224,7 @@ | |||
2254 | 223 | 224 | ||
2255 | 224 | if (is_ketama_weighted) | 225 | if (is_ketama_weighted) |
2256 | 225 | { | 226 | { |
2258 | 226 | for (uint32_t x= 0; x < pointer_per_hash; x++) | 227 | for (x= 0; x < pointer_per_hash; x++) |
2259 | 227 | { | 228 | { |
2260 | 228 | value= ketama_server_hash(sort_host, sort_host_length, x); | 229 | value= ketama_server_hash(sort_host, sort_host_length, x); |
2261 | 229 | ptr->continuum[continuum_index].index= host_index; | 230 | ptr->continuum[continuum_index].index= host_index; |
2262 | @@ -246,6 +247,7 @@ | |||
2263 | 246 | { | 247 | { |
2264 | 247 | char sort_host[MEMCACHED_MAX_HOST_SORT_LENGTH]= ""; | 248 | char sort_host[MEMCACHED_MAX_HOST_SORT_LENGTH]= ""; |
2265 | 248 | size_t sort_host_length; | 249 | size_t sort_host_length; |
2266 | 250 | uint32_t x; | ||
2267 | 249 | 251 | ||
2268 | 250 | if (list[host_index].port == MEMCACHED_DEFAULT_PORT) | 252 | if (list[host_index].port == MEMCACHED_DEFAULT_PORT) |
2269 | 251 | { | 253 | { |
2270 | @@ -267,7 +269,7 @@ | |||
2271 | 267 | 269 | ||
2272 | 268 | if (is_ketama_weighted) | 270 | if (is_ketama_weighted) |
2273 | 269 | { | 271 | { |
2275 | 270 | for (uint32_t x = 0; x < pointer_per_hash; x++) | 272 | for (x = 0; x < pointer_per_hash; x++) |
2276 | 271 | { | 273 | { |
2277 | 272 | value= ketama_server_hash(sort_host, sort_host_length, x); | 274 | value= ketama_server_hash(sort_host, sort_host_length, x); |
2278 | 273 | ptr->continuum[continuum_index].index= host_index; | 275 | ptr->continuum[continuum_index].index= host_index; |
2279 | @@ -305,7 +307,7 @@ | |||
2280 | 305 | 307 | ||
2281 | 306 | memcached_return_t memcached_server_push(memcached_st *ptr, const memcached_server_list_st list) | 308 | memcached_return_t memcached_server_push(memcached_st *ptr, const memcached_server_list_st list) |
2282 | 307 | { | 309 | { |
2284 | 308 | uint32_t count; | 310 | uint32_t count, x; |
2285 | 309 | memcached_server_st *new_host_list; | 311 | memcached_server_st *new_host_list; |
2286 | 310 | 312 | ||
2287 | 311 | if (! list) | 313 | if (! list) |
2288 | @@ -320,7 +322,7 @@ | |||
2289 | 320 | 322 | ||
2290 | 321 | memcached_server_list_set(ptr, new_host_list); | 323 | memcached_server_list_set(ptr, new_host_list); |
2291 | 322 | 324 | ||
2293 | 323 | for (uint32_t x= 0; x < count; x++) | 325 | for (x= 0; x < count; x++) |
2294 | 324 | { | 326 | { |
2295 | 325 | memcached_server_write_instance_st instance; | 327 | memcached_server_write_instance_st instance; |
2296 | 326 | 328 | ||
2297 | 327 | 329 | ||
2298 | === modified file 'libmemcached/io.c' | |||
2299 | --- libmemcached/io.c 2010-09-15 00:44:32 +0000 | |||
2300 | +++ libmemcached/io.c 2011-01-13 03:40:43 +0000 | |||
2301 | @@ -24,12 +24,13 @@ | |||
2302 | 24 | static memcached_return_t io_wait(memcached_server_write_instance_st ptr, | 24 | static memcached_return_t io_wait(memcached_server_write_instance_st ptr, |
2303 | 25 | memc_read_or_write read_or_write) | 25 | memc_read_or_write read_or_write) |
2304 | 26 | { | 26 | { |
2310 | 27 | struct pollfd fds= { | 27 | struct pollfd fds; |
2311 | 28 | .fd= ptr->fd, | 28 | int error, timeout; |
2312 | 29 | .events = POLLIN | 29 | size_t loop_max; |
2308 | 30 | }; | ||
2309 | 31 | int error; | ||
2313 | 32 | 30 | ||
2314 | 31 | fds.fd= ptr->fd; | ||
2315 | 32 | fds.events = POLLIN; | ||
2316 | 33 | |||
2317 | 33 | if (read_or_write == MEM_WRITE) /* write */ | 34 | if (read_or_write == MEM_WRITE) /* write */ |
2318 | 34 | { | 35 | { |
2319 | 35 | fds.events= POLLOUT; | 36 | fds.events= POLLOUT; |
2320 | @@ -55,11 +56,11 @@ | |||
2321 | 55 | return MEMCACHED_FAILURE; | 56 | return MEMCACHED_FAILURE; |
2322 | 56 | } | 57 | } |
2323 | 57 | 58 | ||
2325 | 58 | int timeout= ptr->root->poll_timeout; | 59 | timeout= ptr->root->poll_timeout; |
2326 | 59 | if (ptr->root->flags.no_block == false) | 60 | if (ptr->root->flags.no_block == false) |
2327 | 60 | timeout= -1; | 61 | timeout= -1; |
2328 | 61 | 62 | ||
2330 | 62 | size_t loop_max= 5; | 63 | loop_max= 5; |
2331 | 63 | while (--loop_max) // While loop is for ERESTART or EINTR | 64 | while (--loop_max) // While loop is for ERESTART or EINTR |
2332 | 64 | { | 65 | { |
2333 | 65 | error= poll(&fds, 1, timeout); | 66 | error= poll(&fds, 1, timeout); |
2334 | @@ -164,6 +165,11 @@ | |||
2335 | 164 | */ | 165 | */ |
2336 | 165 | if (ptr->root->callbacks != NULL && ptr->root->flags.use_udp == false) | 166 | if (ptr->root->callbacks != NULL && ptr->root->flags.use_udp == false) |
2337 | 166 | { | 167 | { |
2338 | 168 | uint32_t x; | ||
2339 | 169 | char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; | ||
2340 | 170 | memcached_return_t error; | ||
2341 | 171 | memcached_st *root; | ||
2342 | 172 | |||
2343 | 167 | /* | 173 | /* |
2344 | 168 | * We might have responses... try to read them out and fire | 174 | * We might have responses... try to read them out and fire |
2345 | 169 | * callbacks | 175 | * callbacks |
2346 | @@ -171,10 +177,8 @@ | |||
2347 | 171 | memcached_callback_st cb= *ptr->root->callbacks; | 177 | memcached_callback_st cb= *ptr->root->callbacks; |
2348 | 172 | 178 | ||
2349 | 173 | memcached_set_processing_input((memcached_st *)ptr->root, true); | 179 | memcached_set_processing_input((memcached_st *)ptr->root, true); |
2354 | 174 | 180 | ||
2355 | 175 | char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; | 181 | root= (memcached_st *) ptr->root; |
2352 | 176 | memcached_return_t error; | ||
2353 | 177 | memcached_st *root= (memcached_st *)ptr->root; | ||
2356 | 178 | error= memcached_response(ptr, buffer, sizeof(buffer), | 182 | error= memcached_response(ptr, buffer, sizeof(buffer), |
2357 | 179 | &root->result); | 183 | &root->result); |
2358 | 180 | 184 | ||
2359 | @@ -182,7 +186,7 @@ | |||
2360 | 182 | 186 | ||
2361 | 183 | if (error == MEMCACHED_SUCCESS) | 187 | if (error == MEMCACHED_SUCCESS) |
2362 | 184 | { | 188 | { |
2364 | 185 | for (unsigned int x= 0; x < cb.number_of_callback; x++) | 189 | for (x= 0; x < cb.number_of_callback; x++) |
2365 | 186 | { | 190 | { |
2366 | 187 | error= (*cb.callback[x])(ptr->root, &root->result, cb.context); | 191 | error= (*cb.callback[x])(ptr->root, &root->result, cb.context); |
2367 | 188 | if (error != MEMCACHED_SUCCESS) | 192 | if (error != MEMCACHED_SUCCESS) |
2368 | @@ -281,8 +285,10 @@ | |||
2369 | 281 | } | 285 | } |
2370 | 282 | else if (data_read == SOCKET_ERROR) | 286 | else if (data_read == SOCKET_ERROR) |
2371 | 283 | { | 287 | { |
2372 | 284 | ptr->cached_errno= get_socket_errno(); | ||
2373 | 285 | memcached_return_t rc= MEMCACHED_ERRNO; | 288 | memcached_return_t rc= MEMCACHED_ERRNO; |
2374 | 289 | |||
2375 | 290 | ptr->cached_errno= get_socket_errno(); | ||
2376 | 291 | |||
2377 | 286 | switch (get_socket_errno()) | 292 | switch (get_socket_errno()) |
2378 | 287 | { | 293 | { |
2379 | 288 | case EWOULDBLOCK: | 294 | case EWOULDBLOCK: |
2380 | @@ -443,9 +449,10 @@ | |||
2381 | 443 | const struct libmemcached_io_vector_st *vector, | 449 | const struct libmemcached_io_vector_st *vector, |
2382 | 444 | size_t number_of, bool with_flush) | 450 | size_t number_of, bool with_flush) |
2383 | 445 | { | 451 | { |
2384 | 452 | size_t x; | ||
2385 | 446 | ssize_t total= 0; | 453 | ssize_t total= 0; |
2386 | 447 | 454 | ||
2388 | 448 | for (size_t x= 0; x < number_of; x++, vector++) | 455 | for (x= 0; x < number_of; x++, vector++) |
2389 | 449 | { | 456 | { |
2390 | 450 | ssize_t returnable; | 457 | ssize_t returnable; |
2391 | 451 | 458 | ||
2392 | @@ -496,8 +503,10 @@ | |||
2393 | 496 | #define MAX_SERVERS_TO_POLL 100 | 503 | #define MAX_SERVERS_TO_POLL 100 |
2394 | 497 | struct pollfd fds[MAX_SERVERS_TO_POLL]; | 504 | struct pollfd fds[MAX_SERVERS_TO_POLL]; |
2395 | 498 | unsigned int host_index= 0; | 505 | unsigned int host_index= 0; |
2396 | 506 | uint32_t x, y; | ||
2397 | 507 | int err; | ||
2398 | 499 | 508 | ||
2400 | 500 | for (uint32_t x= 0; | 509 | for (x= 0; |
2401 | 501 | x< memcached_server_count(memc) && host_index < MAX_SERVERS_TO_POLL; | 510 | x< memcached_server_count(memc) && host_index < MAX_SERVERS_TO_POLL; |
2402 | 502 | ++x) | 511 | ++x) |
2403 | 503 | { | 512 | { |
2404 | @@ -519,7 +528,7 @@ | |||
2405 | 519 | if (host_index < 2) | 528 | if (host_index < 2) |
2406 | 520 | { | 529 | { |
2407 | 521 | /* We have 0 or 1 server with pending events.. */ | 530 | /* We have 0 or 1 server with pending events.. */ |
2409 | 522 | for (uint32_t x= 0; x< memcached_server_count(memc); ++x) | 531 | for (x= 0; x< memcached_server_count(memc); ++x) |
2410 | 523 | { | 532 | { |
2411 | 524 | memcached_server_write_instance_st instance= | 533 | memcached_server_write_instance_st instance= |
2412 | 525 | memcached_server_instance_fetch(memc, x); | 534 | memcached_server_instance_fetch(memc, x); |
2413 | @@ -533,7 +542,7 @@ | |||
2414 | 533 | return NULL; | 542 | return NULL; |
2415 | 534 | } | 543 | } |
2416 | 535 | 544 | ||
2418 | 536 | int err= poll(fds, host_index, memc->poll_timeout); | 545 | err= poll(fds, host_index, memc->poll_timeout); |
2419 | 537 | switch (err) { | 546 | switch (err) { |
2420 | 538 | case -1: | 547 | case -1: |
2421 | 539 | memc->cached_errno = get_socket_errno(); | 548 | memc->cached_errno = get_socket_errno(); |
2422 | @@ -541,11 +550,11 @@ | |||
2423 | 541 | case 0: | 550 | case 0: |
2424 | 542 | break; | 551 | break; |
2425 | 543 | default: | 552 | default: |
2427 | 544 | for (size_t x= 0; x < host_index; ++x) | 553 | for (x= 0; x < host_index; ++x) |
2428 | 545 | { | 554 | { |
2429 | 546 | if (fds[x].revents & POLLIN) | 555 | if (fds[x].revents & POLLIN) |
2430 | 547 | { | 556 | { |
2432 | 548 | for (uint32_t y= 0; y < memcached_server_count(memc); ++y) | 557 | for (y= 0; y < memcached_server_count(memc); ++y) |
2433 | 549 | { | 558 | { |
2434 | 550 | memcached_server_write_instance_st instance= | 559 | memcached_server_write_instance_st instance= |
2435 | 551 | memcached_server_instance_fetch(memc, y); | 560 | memcached_server_instance_fetch(memc, y); |
2436 | @@ -563,6 +572,11 @@ | |||
2437 | 563 | static ssize_t io_flush(memcached_server_write_instance_st ptr, | 572 | static ssize_t io_flush(memcached_server_write_instance_st ptr, |
2438 | 564 | memcached_return_t *error) | 573 | memcached_return_t *error) |
2439 | 565 | { | 574 | { |
2440 | 575 | ssize_t sent_length; | ||
2441 | 576 | size_t return_length; | ||
2442 | 577 | char *local_write_ptr; | ||
2443 | 578 | size_t write_length; | ||
2444 | 579 | |||
2445 | 566 | /* | 580 | /* |
2446 | 567 | ** We might want to purge the input buffer if we haven't consumed | 581 | ** We might want to purge the input buffer if we haven't consumed |
2447 | 568 | ** any output yet... The test for the limits is the purge is inline | 582 | ** any output yet... The test for the limits is the purge is inline |
2448 | @@ -576,10 +590,9 @@ | |||
2449 | 576 | if (rc != MEMCACHED_SUCCESS && rc != MEMCACHED_STORED) | 590 | if (rc != MEMCACHED_SUCCESS && rc != MEMCACHED_STORED) |
2450 | 577 | return -1; | 591 | return -1; |
2451 | 578 | } | 592 | } |
2456 | 579 | ssize_t sent_length; | 593 | |
2457 | 580 | size_t return_length; | 594 | local_write_ptr= ptr->write_buffer; |
2458 | 581 | char *local_write_ptr= ptr->write_buffer; | 595 | write_length= ptr->write_buffer_offset; |
2455 | 582 | size_t write_length= ptr->write_buffer_offset; | ||
2459 | 583 | 596 | ||
2460 | 584 | *error= MEMCACHED_SUCCESS; | 597 | *error= MEMCACHED_SUCCESS; |
2461 | 585 | 598 | ||
2462 | @@ -626,6 +639,8 @@ | |||
2463 | 626 | case EAGAIN: | 639 | case EAGAIN: |
2464 | 627 | #endif | 640 | #endif |
2465 | 628 | { | 641 | { |
2466 | 642 | memcached_return_t rc; | ||
2467 | 643 | |||
2468 | 629 | /* | 644 | /* |
2469 | 630 | * We may be blocked on write because the input buffer | 645 | * We may be blocked on write because the input buffer |
2470 | 631 | * is full. Let's check if we have room in our input | 646 | * is full. Let's check if we have room in our input |
2471 | @@ -635,8 +650,7 @@ | |||
2472 | 635 | if (repack_input_buffer(ptr) || | 650 | if (repack_input_buffer(ptr) || |
2473 | 636 | process_input_buffer(ptr)) | 651 | process_input_buffer(ptr)) |
2474 | 637 | continue; | 652 | continue; |
2477 | 638 | 653 | ||
2476 | 639 | memcached_return_t rc; | ||
2478 | 640 | rc= io_wait(ptr, MEM_WRITE); | 654 | rc= io_wait(ptr, MEM_WRITE); |
2479 | 641 | 655 | ||
2480 | 642 | if (rc == MEMCACHED_SUCCESS || rc == MEMCACHED_TIMEOUT) | 656 | if (rc == MEMCACHED_SUCCESS || rc == MEMCACHED_TIMEOUT) |
2481 | @@ -786,10 +800,12 @@ | |||
2482 | 786 | 800 | ||
2483 | 787 | memcached_return_t memcached_io_init_udp_header(memcached_server_write_instance_st ptr, uint16_t thread_id) | 801 | memcached_return_t memcached_io_init_udp_header(memcached_server_write_instance_st ptr, uint16_t thread_id) |
2484 | 788 | { | 802 | { |
2485 | 803 | struct udp_datagram_header_st *header; | ||
2486 | 804 | |||
2487 | 789 | if (thread_id > UDP_REQUEST_ID_MAX_THREAD_ID) | 805 | if (thread_id > UDP_REQUEST_ID_MAX_THREAD_ID) |
2488 | 790 | return MEMCACHED_FAILURE; | 806 | return MEMCACHED_FAILURE; |
2489 | 791 | 807 | ||
2491 | 792 | struct udp_datagram_header_st *header= (struct udp_datagram_header_st *)ptr->write_buffer; | 808 | header= (struct udp_datagram_header_st *)ptr->write_buffer; |
2492 | 793 | header->request_id= htons((uint16_t) (generate_udp_request_thread_id(thread_id))); | 809 | header->request_id= htons((uint16_t) (generate_udp_request_thread_id(thread_id))); |
2493 | 794 | header->num_datagrams= htons(1); | 810 | header->num_datagrams= htons(1); |
2494 | 795 | header->sequence_number= htons(0); | 811 | header->sequence_number= htons(0); |
2495 | 796 | 812 | ||
2496 | === modified file 'libmemcached/memcached.c' | |||
2497 | --- libmemcached/memcached.c 2010-09-13 06:05:34 +0000 | |||
2498 | +++ libmemcached/memcached.c 2011-01-13 03:40:43 +0000 | |||
2499 | @@ -11,41 +11,29 @@ | |||
2500 | 11 | 11 | ||
2501 | 12 | #include "common.h" | 12 | #include "common.h" |
2502 | 13 | 13 | ||
2529 | 14 | static const memcached_st global_copy= { | 14 | const memcached_st *create_global_copy() |
2530 | 15 | .state= { | 15 | { |
2531 | 16 | .is_purging= false, | 16 | memcached_st *global = (memcached_st *) malloc(sizeof(memcached_st)); |
2532 | 17 | .is_processing_input= false, | 17 | |
2533 | 18 | .is_time_for_rebuild= false, | 18 | memset(global, 0, sizeof(memcached_st)); |
2534 | 19 | }, | 19 | |
2535 | 20 | .flags= { | 20 | return global; |
2536 | 21 | .auto_eject_hosts= false, | 21 | } |
2537 | 22 | .binary_protocol= false, | 22 | |
2538 | 23 | .buffer_requests= false, | 23 | static const memcached_st *global_copy = NULL; |
2513 | 24 | .cork= false, | ||
2514 | 25 | .hash_with_prefix_key= false, | ||
2515 | 26 | .ketama_weighted= false, | ||
2516 | 27 | .no_block= false, | ||
2517 | 28 | .no_reply= false, | ||
2518 | 29 | .randomize_replica_read= false, | ||
2519 | 30 | .reuse_memory= false, | ||
2520 | 31 | .support_cas= false, | ||
2521 | 32 | .tcp_nodelay= false, | ||
2522 | 33 | .use_cache_lookups= false, | ||
2523 | 34 | .use_sort_hosts= false, | ||
2524 | 35 | .use_udp= false, | ||
2525 | 36 | .verify_key= false, | ||
2526 | 37 | .tcp_keepalive= false | ||
2527 | 38 | } | ||
2528 | 39 | }; | ||
2539 | 40 | 24 | ||
2540 | 41 | static inline bool _memcached_init(memcached_st *self) | 25 | static inline bool _memcached_init(memcached_st *self) |
2541 | 42 | { | 26 | { |
2544 | 43 | self->state= global_copy.state; | 27 | hashkit_st *hash_ptr; |
2545 | 44 | self->flags= global_copy.flags; | 28 | |
2546 | 29 | if (global_copy == NULL) | ||
2547 | 30 | global_copy = create_global_copy(); | ||
2548 | 31 | |||
2549 | 32 | self->state= global_copy->state; | ||
2550 | 33 | self->flags= global_copy->flags; | ||
2551 | 45 | 34 | ||
2552 | 46 | self->distribution= MEMCACHED_DISTRIBUTION_MODULA; | 35 | self->distribution= MEMCACHED_DISTRIBUTION_MODULA; |
2555 | 47 | 36 | ||
2554 | 48 | hashkit_st *hash_ptr; | ||
2556 | 49 | hash_ptr= hashkit_create(&self->hashkit); | 37 | hash_ptr= hashkit_create(&self->hashkit); |
2557 | 50 | if (! hash_ptr) | 38 | if (! hash_ptr) |
2558 | 51 | return false; | 39 | return false; |
2559 | @@ -199,6 +187,7 @@ | |||
2560 | 199 | { | 187 | { |
2561 | 200 | memcached_return_t rc= MEMCACHED_SUCCESS; | 188 | memcached_return_t rc= MEMCACHED_SUCCESS; |
2562 | 201 | memcached_st *new_clone; | 189 | memcached_st *new_clone; |
2563 | 190 | hashkit_st *hash_ptr; | ||
2564 | 202 | 191 | ||
2565 | 203 | if (source == NULL) | 192 | if (source == NULL) |
2566 | 204 | return memcached_create(clone); | 193 | return memcached_create(clone); |
2567 | @@ -221,8 +210,6 @@ | |||
2568 | 221 | new_clone->retry_timeout= source->retry_timeout; | 210 | new_clone->retry_timeout= source->retry_timeout; |
2569 | 222 | new_clone->distribution= source->distribution; | 211 | new_clone->distribution= source->distribution; |
2570 | 223 | 212 | ||
2571 | 224 | hashkit_st *hash_ptr; | ||
2572 | 225 | |||
2573 | 226 | hash_ptr= hashkit_clone(&new_clone->hashkit, &source->hashkit); | 213 | hash_ptr= hashkit_clone(&new_clone->hashkit, &source->hashkit); |
2574 | 227 | if (! hash_ptr) | 214 | if (! hash_ptr) |
2575 | 228 | { | 215 | { |
2576 | 229 | 216 | ||
2577 | === modified file 'libmemcached/memcached.h' | |||
2578 | --- libmemcached/memcached.h 2010-09-13 06:05:34 +0000 | |||
2579 | +++ libmemcached/memcached.h 2011-01-13 03:40:43 +0000 | |||
2580 | @@ -111,13 +111,7 @@ | |||
2581 | 111 | memcached_result_st result; | 111 | memcached_result_st result; |
2582 | 112 | memcached_continuum_item_st *continuum; // Ketama | 112 | memcached_continuum_item_st *continuum; // Ketama |
2583 | 113 | 113 | ||
2591 | 114 | struct _allocators_st { | 114 | allocators_st *allocators; |
2585 | 115 | memcached_calloc_fn calloc; | ||
2586 | 116 | memcached_free_fn free; | ||
2587 | 117 | memcached_malloc_fn malloc; | ||
2588 | 118 | memcached_realloc_fn realloc; | ||
2589 | 119 | void *context; | ||
2590 | 120 | } allocators; | ||
2592 | 121 | 115 | ||
2593 | 122 | memcached_clone_fn on_clone; | 116 | memcached_clone_fn on_clone; |
2594 | 123 | memcached_cleanup_fn on_cleanup; | 117 | memcached_cleanup_fn on_cleanup; |
2595 | 124 | 118 | ||
2596 | === modified file 'libmemcached/purge.c' | |||
2597 | --- libmemcached/purge.c 2010-02-13 02:23:49 +0000 | |||
2598 | +++ libmemcached/purge.c 2011-01-13 03:40:43 +0000 | |||
2599 | @@ -2,7 +2,7 @@ | |||
2600 | 2 | 2 | ||
2601 | 3 | memcached_return_t memcached_purge(memcached_server_write_instance_st ptr) | 3 | memcached_return_t memcached_purge(memcached_server_write_instance_st ptr) |
2602 | 4 | { | 4 | { |
2604 | 5 | uint32_t x; | 5 | uint32_t x, no_msg; |
2605 | 6 | memcached_return_t ret= MEMCACHED_SUCCESS; | 6 | memcached_return_t ret= MEMCACHED_SUCCESS; |
2606 | 7 | memcached_st *root= (memcached_st *)ptr->root; | 7 | memcached_st *root= (memcached_st *)ptr->root; |
2607 | 8 | 8 | ||
2608 | @@ -30,7 +30,7 @@ | |||
2609 | 30 | } | 30 | } |
2610 | 31 | WATCHPOINT_ASSERT(ptr->fd != -1); | 31 | WATCHPOINT_ASSERT(ptr->fd != -1); |
2611 | 32 | 32 | ||
2613 | 33 | uint32_t no_msg= memcached_server_response_count(ptr) - 1; | 33 | no_msg= memcached_server_response_count(ptr) - 1; |
2614 | 34 | if (no_msg > 0) | 34 | if (no_msg > 0) |
2615 | 35 | { | 35 | { |
2616 | 36 | memcached_result_st result; | 36 | memcached_result_st result; |
2617 | @@ -50,10 +50,10 @@ | |||
2618 | 50 | 50 | ||
2619 | 51 | for (x= 0; x < no_msg; x++) | 51 | for (x= 0; x < no_msg; x++) |
2620 | 52 | { | 52 | { |
2621 | 53 | memcached_return_t rc; | ||
2622 | 54 | |||
2623 | 53 | memcached_result_reset(result_ptr); | 55 | memcached_result_reset(result_ptr); |
2627 | 54 | memcached_return_t rc= memcached_read_one_response(ptr, buffer, | 56 | rc= memcached_read_one_response(ptr, buffer, sizeof (buffer), result_ptr); |
2625 | 55 | sizeof (buffer), | ||
2626 | 56 | result_ptr); | ||
2628 | 57 | /* | 57 | /* |
2629 | 58 | * Purge doesn't care for what kind of command results that is received. | 58 | * Purge doesn't care for what kind of command results that is received. |
2630 | 59 | * The only kind of errors I care about if is I'm out of sync with the | 59 | * The only kind of errors I care about if is I'm out of sync with the |
2631 | @@ -69,9 +69,11 @@ | |||
2632 | 69 | if (ptr->root->callbacks != NULL) | 69 | if (ptr->root->callbacks != NULL) |
2633 | 70 | { | 70 | { |
2634 | 71 | memcached_callback_st cb = *ptr->root->callbacks; | 71 | memcached_callback_st cb = *ptr->root->callbacks; |
2635 | 72 | uint32_t y; | ||
2636 | 73 | |||
2637 | 72 | if (rc == MEMCACHED_SUCCESS) | 74 | if (rc == MEMCACHED_SUCCESS) |
2638 | 73 | { | 75 | { |
2640 | 74 | for (uint32_t y= 0; y < cb.number_of_callback; y++) | 76 | for (y= 0; y < cb.number_of_callback; y++) |
2641 | 75 | { | 77 | { |
2642 | 76 | rc = (*cb.callback[y])(ptr->root, result_ptr, cb.context); | 78 | rc = (*cb.callback[y])(ptr->root, result_ptr, cb.context); |
2643 | 77 | if (rc != MEMCACHED_SUCCESS) | 79 | if (rc != MEMCACHED_SUCCESS) |
2644 | 78 | 80 | ||
2645 | === modified file 'libmemcached/quit.c' | |||
2646 | --- libmemcached/quit.c 2010-04-22 00:49:09 +0000 | |||
2647 | +++ libmemcached/quit.c 2011-01-13 03:40:43 +0000 | |||
2648 | @@ -22,7 +22,10 @@ | |||
2649 | 22 | 22 | ||
2650 | 23 | if (ptr->root->flags.binary_protocol) | 23 | if (ptr->root->flags.binary_protocol) |
2651 | 24 | { | 24 | { |
2653 | 25 | protocol_binary_request_quit request = {.bytes= {0}}; | 25 | protocol_binary_request_quit request; |
2654 | 26 | |||
2655 | 27 | memset(&request, 0, sizeof(request)); | ||
2656 | 28 | |||
2657 | 26 | request.message.header.request.magic = PROTOCOL_BINARY_REQ; | 29 | request.message.header.request.magic = PROTOCOL_BINARY_REQ; |
2658 | 27 | request.message.header.request.opcode = PROTOCOL_BINARY_CMD_QUIT; | 30 | request.message.header.request.opcode = PROTOCOL_BINARY_CMD_QUIT; |
2659 | 28 | request.message.header.request.datatype = PROTOCOL_BINARY_RAW_BYTES; | 31 | request.message.header.request.datatype = PROTOCOL_BINARY_RAW_BYTES; |
2660 | 29 | 32 | ||
2661 | === modified file 'libmemcached/response.c' | |||
2662 | --- libmemcached/response.c 2010-07-16 03:54:57 +0000 | |||
2663 | +++ libmemcached/response.c 2011-01-13 03:40:43 +0000 | |||
2664 | @@ -22,6 +22,8 @@ | |||
2665 | 22 | char *buffer, size_t buffer_length, | 22 | char *buffer, size_t buffer_length, |
2666 | 23 | memcached_result_st *result) | 23 | memcached_result_st *result) |
2667 | 24 | { | 24 | { |
2668 | 25 | memcached_return_t rc; | ||
2669 | 26 | |||
2670 | 25 | memcached_server_response_decrement(ptr); | 27 | memcached_server_response_decrement(ptr); |
2671 | 26 | 28 | ||
2672 | 27 | if (result == NULL) | 29 | if (result == NULL) |
2673 | @@ -29,8 +31,7 @@ | |||
2674 | 29 | memcached_st *root= (memcached_st *)ptr->root; | 31 | memcached_st *root= (memcached_st *)ptr->root; |
2675 | 30 | result = &root->result; | 32 | result = &root->result; |
2676 | 31 | } | 33 | } |
2679 | 32 | 34 | ||
2678 | 33 | memcached_return_t rc; | ||
2680 | 34 | if (ptr->root->flags.binary_protocol) | 35 | if (ptr->root->flags.binary_protocol) |
2681 | 35 | rc= binary_read_one_response(ptr, buffer, buffer_length, result); | 36 | rc= binary_read_one_response(ptr, buffer, buffer_length, result); |
2682 | 36 | else | 37 | else |
2683 | @@ -341,6 +342,7 @@ | |||
2684 | 341 | { | 342 | { |
2685 | 342 | memcached_return_t rc; | 343 | memcached_return_t rc; |
2686 | 343 | protocol_binary_response_header header; | 344 | protocol_binary_response_header header; |
2687 | 345 | uint32_t bodylen; | ||
2688 | 344 | 346 | ||
2689 | 345 | if ((rc= memcached_safe_read(ptr, &header.bytes, sizeof(header.bytes))) != MEMCACHED_SUCCESS) | 347 | if ((rc= memcached_safe_read(ptr, &header.bytes, sizeof(header.bytes))) != MEMCACHED_SUCCESS) |
2690 | 346 | { | 348 | { |
2691 | @@ -360,7 +362,7 @@ | |||
2692 | 360 | header.response.status= ntohs(header.response.status); | 362 | header.response.status= ntohs(header.response.status); |
2693 | 361 | header.response.bodylen= ntohl(header.response.bodylen); | 363 | header.response.bodylen= ntohl(header.response.bodylen); |
2694 | 362 | header.response.cas= ntohll(header.response.cas); | 364 | header.response.cas= ntohll(header.response.cas); |
2696 | 363 | uint32_t bodylen= header.response.bodylen; | 365 | bodylen= header.response.bodylen; |
2697 | 364 | 366 | ||
2698 | 365 | if (header.response.status == PROTOCOL_BINARY_RESPONSE_SUCCESS || | 367 | if (header.response.status == PROTOCOL_BINARY_RESPONSE_SUCCESS || |
2699 | 366 | header.response.status == PROTOCOL_BINARY_RESPONSE_AUTH_CONTINUE) | 368 | header.response.status == PROTOCOL_BINARY_RESPONSE_AUTH_CONTINUE) |
2700 | @@ -376,6 +378,7 @@ | |||
2701 | 376 | /* FALLTHROUGH */ | 378 | /* FALLTHROUGH */ |
2702 | 377 | case PROTOCOL_BINARY_CMD_GETK: | 379 | case PROTOCOL_BINARY_CMD_GETK: |
2703 | 378 | { | 380 | { |
2704 | 381 | char *vptr; | ||
2705 | 379 | uint16_t keylen= header.response.keylen; | 382 | uint16_t keylen= header.response.keylen; |
2706 | 380 | memcached_result_reset(result); | 383 | memcached_result_reset(result); |
2707 | 381 | result->item_cas= header.response.cas; | 384 | result->item_cas= header.response.cas; |
2708 | @@ -401,7 +404,7 @@ | |||
2709 | 401 | bodylen) != MEMCACHED_SUCCESS) | 404 | bodylen) != MEMCACHED_SUCCESS) |
2710 | 402 | return MEMCACHED_MEMORY_ALLOCATION_FAILURE; | 405 | return MEMCACHED_MEMORY_ALLOCATION_FAILURE; |
2711 | 403 | 406 | ||
2713 | 404 | char *vptr= memcached_string_value_mutable(&result->value); | 407 | vptr= memcached_string_value_mutable(&result->value); |
2714 | 405 | if ((rc= memcached_safe_read(ptr, vptr, bodylen)) != MEMCACHED_SUCCESS) | 408 | if ((rc= memcached_safe_read(ptr, vptr, bodylen)) != MEMCACHED_SUCCESS) |
2715 | 406 | { | 409 | { |
2716 | 407 | WATCHPOINT_ERROR(rc); | 410 | WATCHPOINT_ERROR(rc); |
2717 | @@ -414,11 +417,13 @@ | |||
2718 | 414 | case PROTOCOL_BINARY_CMD_INCREMENT: | 417 | case PROTOCOL_BINARY_CMD_INCREMENT: |
2719 | 415 | case PROTOCOL_BINARY_CMD_DECREMENT: | 418 | case PROTOCOL_BINARY_CMD_DECREMENT: |
2720 | 416 | { | 419 | { |
2721 | 420 | uint64_t val; | ||
2722 | 421 | |||
2723 | 417 | if (bodylen != sizeof(uint64_t) || buffer_length != sizeof(uint64_t)) | 422 | if (bodylen != sizeof(uint64_t) || buffer_length != sizeof(uint64_t)) |
2724 | 418 | return MEMCACHED_PROTOCOL_ERROR; | 423 | return MEMCACHED_PROTOCOL_ERROR; |
2725 | 419 | 424 | ||
2726 | 420 | WATCHPOINT_ASSERT(bodylen == buffer_length); | 425 | WATCHPOINT_ASSERT(bodylen == buffer_length); |
2728 | 421 | uint64_t val; | 426 | |
2729 | 422 | if ((rc= memcached_safe_read(ptr, &val, sizeof(val))) != MEMCACHED_SUCCESS) | 427 | if ((rc= memcached_safe_read(ptr, &val, sizeof(val))) != MEMCACHED_SUCCESS) |
2730 | 423 | { | 428 | { |
2731 | 424 | WATCHPOINT_ERROR(rc); | 429 | WATCHPOINT_ERROR(rc); |
2732 | @@ -490,6 +495,8 @@ | |||
2733 | 490 | case PROTOCOL_BINARY_CMD_SASL_AUTH: | 495 | case PROTOCOL_BINARY_CMD_SASL_AUTH: |
2734 | 491 | case PROTOCOL_BINARY_CMD_SASL_STEP: | 496 | case PROTOCOL_BINARY_CMD_SASL_STEP: |
2735 | 492 | { | 497 | { |
2736 | 498 | char * vptr; | ||
2737 | 499 | |||
2738 | 493 | memcached_result_reset(result); | 500 | memcached_result_reset(result); |
2739 | 494 | result->item_cas= header.response.cas; | 501 | result->item_cas= header.response.cas; |
2740 | 495 | 502 | ||
2741 | @@ -497,7 +504,7 @@ | |||
2742 | 497 | bodylen) != MEMCACHED_SUCCESS) | 504 | bodylen) != MEMCACHED_SUCCESS) |
2743 | 498 | return MEMCACHED_MEMORY_ALLOCATION_FAILURE; | 505 | return MEMCACHED_MEMORY_ALLOCATION_FAILURE; |
2744 | 499 | 506 | ||
2746 | 500 | char *vptr= memcached_string_value_mutable(&result->value); | 507 | vptr= memcached_string_value_mutable(&result->value); |
2747 | 501 | if ((rc= memcached_safe_read(ptr, vptr, bodylen)) != MEMCACHED_SUCCESS) | 508 | if ((rc= memcached_safe_read(ptr, vptr, bodylen)) != MEMCACHED_SUCCESS) |
2748 | 502 | { | 509 | { |
2749 | 503 | WATCHPOINT_ERROR(rc); | 510 | WATCHPOINT_ERROR(rc); |
2750 | 504 | 511 | ||
2751 | === modified file 'libmemcached/sasl.c' | |||
2752 | --- libmemcached/sasl.c 2010-09-13 12:26:17 +0000 | |||
2753 | +++ libmemcached/sasl.c 2011-01-13 03:40:43 +0000 | |||
2754 | @@ -11,6 +11,8 @@ | |||
2755 | 11 | */ | 11 | */ |
2756 | 12 | #include "common.h" | 12 | #include "common.h" |
2757 | 13 | 13 | ||
2758 | 14 | #ifdef LIBMEMCACHED_WITH_SASL_SUPPORT | ||
2759 | 15 | |||
2760 | 14 | void memcached_set_sasl_callbacks(memcached_st *ptr, | 16 | void memcached_set_sasl_callbacks(memcached_st *ptr, |
2761 | 15 | const sasl_callback_t *callbacks) | 17 | const sasl_callback_t *callbacks) |
2762 | 16 | { | 18 | { |
2763 | @@ -373,3 +375,5 @@ | |||
2764 | 373 | 375 | ||
2765 | 374 | return MEMCACHED_SUCCESS; | 376 | return MEMCACHED_SUCCESS; |
2766 | 375 | } | 377 | } |
2767 | 378 | |||
2768 | 379 | #endif | ||
2769 | 376 | 380 | ||
2770 | === modified file 'libmemcached/server.c' | |||
2771 | --- libmemcached/server.c 2010-07-16 02:33:19 +0000 | |||
2772 | +++ libmemcached/server.c 2011-01-13 03:40:43 +0000 | |||
2773 | @@ -153,12 +153,14 @@ | |||
2774 | 153 | void *context, | 153 | void *context, |
2775 | 154 | uint32_t number_of_callbacks) | 154 | uint32_t number_of_callbacks) |
2776 | 155 | { | 155 | { |
2778 | 156 | for (uint32_t x= 0; x < memcached_server_count(ptr); x++) | 156 | uint32_t x, y; |
2779 | 157 | |||
2780 | 158 | for (x= 0; x < memcached_server_count(ptr); x++) | ||
2781 | 157 | { | 159 | { |
2782 | 158 | memcached_server_instance_st instance= | 160 | memcached_server_instance_st instance= |
2783 | 159 | memcached_server_instance_by_position(ptr, x); | 161 | memcached_server_instance_by_position(ptr, x); |
2784 | 160 | 162 | ||
2786 | 161 | for (uint32_t y= 0; y < number_of_callbacks; y++) | 163 | for (y= 0; y < number_of_callbacks; y++) |
2787 | 162 | { | 164 | { |
2788 | 163 | unsigned int iferror; | 165 | unsigned int iferror; |
2789 | 164 | 166 | ||
2790 | @@ -176,7 +178,9 @@ | |||
2791 | 176 | memcached_server_execute_fn callback, | 178 | memcached_server_execute_fn callback, |
2792 | 177 | void *context) | 179 | void *context) |
2793 | 178 | { | 180 | { |
2795 | 179 | for (uint32_t x= 0; x < memcached_server_count(ptr); x++) | 181 | uint32_t x; |
2796 | 182 | |||
2797 | 183 | for (x= 0; x < memcached_server_count(ptr); x++) | ||
2798 | 180 | { | 184 | { |
2799 | 181 | memcached_server_write_instance_st instance= | 185 | memcached_server_write_instance_st instance= |
2800 | 182 | memcached_server_instance_fetch(ptr, x); | 186 | memcached_server_instance_fetch(ptr, x); |
2801 | @@ -236,12 +240,15 @@ | |||
2802 | 236 | 240 | ||
2803 | 237 | void memcached_server_list_free(memcached_server_list_st self) | 241 | void memcached_server_list_free(memcached_server_list_st self) |
2804 | 238 | { | 242 | { |
2805 | 243 | const memcached_st *root; | ||
2806 | 244 | uint32_t x; | ||
2807 | 245 | |||
2808 | 239 | if (self == NULL) | 246 | if (self == NULL) |
2809 | 240 | return; | 247 | return; |
2810 | 241 | 248 | ||
2812 | 242 | const memcached_st *root= self->root; | 249 | root= self->root; |
2813 | 243 | 250 | ||
2815 | 244 | for (uint32_t x= 0; x < memcached_server_list_count(self); x++) | 251 | for (x= 0; x < memcached_server_list_count(self); x++) |
2816 | 245 | { | 252 | { |
2817 | 246 | if (self[x].address_info) | 253 | if (self[x].address_info) |
2818 | 247 | { | 254 | { |
2819 | 248 | 255 | ||
2820 | === modified file 'libmemcached/stats.c' | |||
2821 | --- libmemcached/stats.c 2010-09-13 12:26:17 +0000 | |||
2822 | +++ libmemcached/stats.c 2011-01-13 03:40:43 +0000 | |||
2823 | @@ -242,13 +242,18 @@ | |||
2824 | 242 | memcached_return_t rc; | 242 | memcached_return_t rc; |
2825 | 243 | 243 | ||
2826 | 244 | char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; | 244 | char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; |
2828 | 245 | protocol_binary_request_stats request= {.bytes= {0}}; | 245 | protocol_binary_request_stats request; |
2829 | 246 | |||
2830 | 247 | memset(&request, 0, sizeof(request)); | ||
2831 | 248 | |||
2832 | 246 | request.message.header.request.magic= PROTOCOL_BINARY_REQ; | 249 | request.message.header.request.magic= PROTOCOL_BINARY_REQ; |
2833 | 247 | request.message.header.request.opcode= PROTOCOL_BINARY_CMD_STAT; | 250 | request.message.header.request.opcode= PROTOCOL_BINARY_CMD_STAT; |
2834 | 248 | request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; | 251 | request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; |
2835 | 249 | 252 | ||
2836 | 250 | if (args != NULL) | 253 | if (args != NULL) |
2837 | 251 | { | 254 | { |
2838 | 255 | struct libmemcached_io_vector_st vector[2]; | ||
2839 | 256 | |||
2840 | 252 | size_t len= strlen(args); | 257 | size_t len= strlen(args); |
2841 | 253 | 258 | ||
2842 | 254 | rc= memcached_validate_key_length(len, true); | 259 | rc= memcached_validate_key_length(len, true); |
2843 | @@ -258,11 +263,10 @@ | |||
2844 | 258 | request.message.header.request.keylen= htons((uint16_t)len); | 263 | request.message.header.request.keylen= htons((uint16_t)len); |
2845 | 259 | request.message.header.request.bodylen= htonl((uint32_t) len); | 264 | request.message.header.request.bodylen= htonl((uint32_t) len); |
2846 | 260 | 265 | ||
2852 | 261 | struct libmemcached_io_vector_st vector[]= | 266 | vector[0].length= sizeof(request.bytes); |
2853 | 262 | { | 267 | vector[0].buffer= request.bytes; |
2854 | 263 | { .length= sizeof(request.bytes), .buffer= request.bytes }, | 268 | vector[1].length= len; |
2855 | 264 | { .length= len, .buffer= args } | 269 | vector[1].buffer= args; |
2851 | 265 | }; | ||
2856 | 266 | 270 | ||
2857 | 267 | if (memcached_vdo(instance, vector, 2, true) != MEMCACHED_SUCCESS) | 271 | if (memcached_vdo(instance, vector, 2, true) != MEMCACHED_SUCCESS) |
2858 | 268 | { | 272 | { |
2859 | @@ -397,6 +401,7 @@ | |||
2860 | 397 | { | 401 | { |
2861 | 398 | memcached_return_t rc; | 402 | memcached_return_t rc; |
2862 | 399 | memcached_stat_st *stats; | 403 | memcached_stat_st *stats; |
2863 | 404 | uint32_t x; | ||
2864 | 400 | 405 | ||
2865 | 401 | unlikely (ptr->flags.use_udp) | 406 | unlikely (ptr->flags.use_udp) |
2866 | 402 | { | 407 | { |
2867 | @@ -413,7 +418,7 @@ | |||
2868 | 413 | } | 418 | } |
2869 | 414 | 419 | ||
2870 | 415 | rc= MEMCACHED_SUCCESS; | 420 | rc= MEMCACHED_SUCCESS; |
2872 | 416 | for (uint32_t x= 0; x < memcached_server_count(ptr); x++) | 421 | for (x= 0; x < memcached_server_count(ptr); x++) |
2873 | 417 | { | 422 | { |
2874 | 418 | memcached_return_t temp_return; | 423 | memcached_return_t temp_return; |
2875 | 419 | memcached_server_write_instance_st instance; | 424 | memcached_server_write_instance_st instance; |
2876 | @@ -544,9 +549,13 @@ | |||
2877 | 544 | 549 | ||
2878 | 545 | memcached_return_t memcached_stat_execute(memcached_st *memc, const char *args, memcached_stat_fn func, void *context) | 550 | memcached_return_t memcached_stat_execute(memcached_st *memc, const char *args, memcached_stat_fn func, void *context) |
2879 | 546 | { | 551 | { |
2880 | 552 | struct local_context check; | ||
2881 | 553 | |||
2882 | 547 | memcached_version(memc); | 554 | memcached_version(memc); |
2883 | 548 | 555 | ||
2885 | 549 | struct local_context check= { .func= func, .context= context, .args= args }; | 556 | check.func= func; |
2886 | 557 | check.context= context; | ||
2887 | 558 | check.args= args; | ||
2888 | 550 | 559 | ||
2889 | 551 | return memcached_server_execute(memc, call_stat_fn, (void *)&check); | 560 | return memcached_server_execute(memc, call_stat_fn, (void *)&check); |
2890 | 552 | } | 561 | } |
2891 | 553 | 562 | ||
2892 | === modified file 'libmemcached/storage.c' | |||
2893 | --- libmemcached/storage.c 2010-09-13 12:26:17 +0000 | |||
2894 | +++ libmemcached/storage.c 2011-01-13 03:40:43 +0000 | |||
2895 | @@ -105,12 +105,13 @@ | |||
2896 | 105 | if (cas) | 105 | if (cas) |
2897 | 106 | { | 106 | { |
2898 | 107 | write_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, | 107 | write_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, |
2900 | 108 | "%s %.*s%.*s %u %llu %zu %llu%s\r\n", | 108 | "%s %.*s%.*s %u %llu %lu %llu%s\r\n", |
2901 | 109 | storage_op_string(verb), | 109 | storage_op_string(verb), |
2902 | 110 | (int)ptr->prefix_key_length, | 110 | (int)ptr->prefix_key_length, |
2903 | 111 | ptr->prefix_key, | 111 | ptr->prefix_key, |
2904 | 112 | (int)key_length, key, flags, | 112 | (int)key_length, key, flags, |
2906 | 113 | (unsigned long long)expiration, value_length, | 113 | (unsigned long long)expiration, |
2907 | 114 | (unsigned long)value_length, | ||
2908 | 114 | (unsigned long long)cas, | 115 | (unsigned long long)cas, |
2909 | 115 | (ptr->flags.no_reply) ? " noreply" : ""); | 116 | (ptr->flags.no_reply) ? " noreply" : ""); |
2910 | 116 | } | 117 | } |
2911 | @@ -134,9 +135,10 @@ | |||
2912 | 134 | 135 | ||
2913 | 135 | write_length= (size_t)(buffer_ptr - buffer); | 136 | write_length= (size_t)(buffer_ptr - buffer); |
2914 | 136 | write_length+= (size_t) snprintf(buffer_ptr, MEMCACHED_DEFAULT_COMMAND_SIZE, | 137 | write_length+= (size_t) snprintf(buffer_ptr, MEMCACHED_DEFAULT_COMMAND_SIZE, |
2916 | 137 | "%u %llu %zu%s\r\n", | 138 | "%u %llu %lu%s\r\n", |
2917 | 138 | flags, | 139 | flags, |
2919 | 139 | (unsigned long long)expiration, value_length, | 140 | (unsigned long long)expiration, |
2920 | 141 | (unsigned long)value_length, | ||
2921 | 140 | ptr->flags.no_reply ? " noreply" : ""); | 142 | ptr->flags.no_reply ? " noreply" : ""); |
2922 | 141 | } | 143 | } |
2923 | 142 | 144 | ||
2924 | @@ -155,12 +157,14 @@ | |||
2925 | 155 | } | 157 | } |
2926 | 156 | else | 158 | else |
2927 | 157 | { | 159 | { |
2934 | 158 | struct libmemcached_io_vector_st vector[]= | 160 | struct libmemcached_io_vector_st vector[3]; |
2935 | 159 | { | 161 | |
2936 | 160 | { .length= write_length, .buffer= buffer }, | 162 | vector[0].length= write_length; |
2937 | 161 | { .length= value_length, .buffer= value }, | 163 | vector[0].buffer= buffer; |
2938 | 162 | { .length= 2, .buffer= "\r\n" } | 164 | vector[1].length= value_length; |
2939 | 163 | }; | 165 | vector[1].buffer= value; |
2940 | 166 | vector[2].length= 2; | ||
2941 | 167 | vector[2].buffer= "\r\n"; | ||
2942 | 164 | 168 | ||
2943 | 165 | if (ptr->flags.buffer_requests && verb == SET_OP) | 169 | if (ptr->flags.buffer_requests && verb == SET_OP) |
2944 | 166 | { | 170 | { |
2945 | @@ -452,11 +456,15 @@ | |||
2946 | 452 | memcached_storage_action_t verb) | 456 | memcached_storage_action_t verb) |
2947 | 453 | { | 457 | { |
2948 | 454 | bool flush; | 458 | bool flush; |
2950 | 455 | protocol_binary_request_set request= {.bytes= {0}}; | 459 | protocol_binary_request_set request; |
2951 | 456 | size_t send_length= sizeof(request.bytes); | 460 | size_t send_length= sizeof(request.bytes); |
2953 | 457 | 461 | memcached_return_t rc; | |
2954 | 462 | struct libmemcached_io_vector_st vector[4]; | ||
2955 | 463 | |||
2956 | 458 | bool noreply= server->root->flags.no_reply; | 464 | bool noreply= server->root->flags.no_reply; |
2957 | 459 | 465 | ||
2958 | 466 | memset(&request, 0, sizeof(request)); | ||
2959 | 467 | |||
2960 | 460 | request.message.header.request.magic= PROTOCOL_BINARY_REQ; | 468 | request.message.header.request.magic= PROTOCOL_BINARY_REQ; |
2961 | 461 | request.message.header.request.opcode= get_com_code(verb, noreply); | 469 | request.message.header.request.opcode= get_com_code(verb, noreply); |
2962 | 462 | request.message.header.request.keylen= htons((uint16_t)(key_length + ptr->prefix_key_length)); | 470 | request.message.header.request.keylen= htons((uint16_t)(key_length + ptr->prefix_key_length)); |
2963 | @@ -492,16 +500,17 @@ | |||
2964 | 492 | } | 500 | } |
2965 | 493 | } | 501 | } |
2966 | 494 | 502 | ||
2974 | 495 | struct libmemcached_io_vector_st vector[]= | 503 | |
2975 | 496 | { | 504 | vector[0].length= send_length; |
2976 | 497 | { .length= send_length, .buffer= request.bytes }, | 505 | vector[0].buffer= request.bytes; |
2977 | 498 | { .length= ptr->prefix_key_length, .buffer= ptr->prefix_key }, | 506 | vector[1].length= ptr->prefix_key_length; |
2978 | 499 | { .length= key_length, .buffer= key }, | 507 | vector[1].buffer= ptr->prefix_key; |
2979 | 500 | { .length= value_length, .buffer= value } | 508 | vector[2].length= key_length; |
2980 | 501 | }; | 509 | vector[2].buffer= key; |
2981 | 510 | vector[3].length= value_length; | ||
2982 | 511 | vector[3].buffer= value; | ||
2983 | 502 | 512 | ||
2986 | 503 | /* write the header */ | 513 | /* write the header */ |
2985 | 504 | memcached_return_t rc; | ||
2987 | 505 | if ((rc= memcached_vdo(server, vector, 4, flush)) != MEMCACHED_SUCCESS) | 514 | if ((rc= memcached_vdo(server, vector, 4, flush)) != MEMCACHED_SUCCESS) |
2988 | 506 | { | 515 | { |
2989 | 507 | memcached_io_reset(server); | 516 | memcached_io_reset(server); |
2990 | @@ -510,10 +519,12 @@ | |||
2991 | 510 | 519 | ||
2992 | 511 | if (verb == SET_OP && ptr->number_of_replicas > 0) | 520 | if (verb == SET_OP && ptr->number_of_replicas > 0) |
2993 | 512 | { | 521 | { |
2994 | 522 | uint32_t x; | ||
2995 | 523 | |||
2996 | 513 | request.message.header.request.opcode= PROTOCOL_BINARY_CMD_SETQ; | 524 | request.message.header.request.opcode= PROTOCOL_BINARY_CMD_SETQ; |
2997 | 514 | WATCHPOINT_STRING("replicating"); | 525 | WATCHPOINT_STRING("replicating"); |
2998 | 515 | 526 | ||
3000 | 516 | for (uint32_t x= 0; x < ptr->number_of_replicas; x++) | 527 | for (x= 0; x < ptr->number_of_replicas; x++) |
3001 | 517 | { | 528 | { |
3002 | 518 | memcached_server_write_instance_st instance; | 529 | memcached_server_write_instance_st instance; |
3003 | 519 | 530 | ||
3004 | 520 | 531 | ||
3005 | === modified file 'libmemcached/types.h' | |||
3006 | --- libmemcached/types.h 2010-07-16 02:33:19 +0000 | |||
3007 | +++ libmemcached/types.h 2011-01-13 03:40:43 +0000 | |||
3008 | @@ -44,6 +44,13 @@ | |||
3009 | 44 | typedef void *(*memcached_realloc_fn)(const memcached_st *ptr, void *mem, const size_t size, void *context); | 44 | typedef void *(*memcached_realloc_fn)(const memcached_st *ptr, void *mem, const size_t size, void *context); |
3010 | 45 | typedef void *(*memcached_calloc_fn)(const memcached_st *ptr, size_t nelem, const size_t elsize, void *context); | 45 | typedef void *(*memcached_calloc_fn)(const memcached_st *ptr, size_t nelem, const size_t elsize, void *context); |
3011 | 46 | 46 | ||
3012 | 47 | typedef struct _allocators_st { | ||
3013 | 48 | memcached_calloc_fn calloc; | ||
3014 | 49 | memcached_free_fn free; | ||
3015 | 50 | memcached_malloc_fn malloc; | ||
3016 | 51 | memcached_realloc_fn realloc; | ||
3017 | 52 | void *context; | ||
3018 | 53 | } allocators_st; | ||
3019 | 47 | 54 | ||
3020 | 48 | typedef memcached_return_t (*memcached_execute_fn)(const memcached_st *ptr, memcached_result_st *result, void *context); | 55 | typedef memcached_return_t (*memcached_execute_fn)(const memcached_st *ptr, memcached_result_st *result, void *context); |
3021 | 49 | typedef memcached_return_t (*memcached_server_fn)(const memcached_st *ptr, memcached_server_instance_st server, void *context); | 56 | typedef memcached_return_t (*memcached_server_fn)(const memcached_st *ptr, memcached_server_instance_st server, void *context); |
3022 | 50 | 57 | ||
3023 | === modified file 'libmemcached/verbosity.c' | |||
3024 | --- libmemcached/verbosity.c 2010-04-04 21:53:03 +0000 | |||
3025 | +++ libmemcached/verbosity.c 2011-01-13 03:40:43 +0000 | |||
3026 | @@ -43,6 +43,7 @@ | |||
3027 | 43 | { | 43 | { |
3028 | 44 | size_t send_length; | 44 | size_t send_length; |
3029 | 45 | memcached_server_fn callbacks[1]; | 45 | memcached_server_fn callbacks[1]; |
3030 | 46 | struct context_st context; | ||
3031 | 46 | 47 | ||
3032 | 47 | char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; | 48 | char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; |
3033 | 48 | 49 | ||
3034 | @@ -51,7 +52,8 @@ | |||
3035 | 51 | unlikely (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE) | 52 | unlikely (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE) |
3036 | 52 | return MEMCACHED_WRITE_FAILURE; | 53 | return MEMCACHED_WRITE_FAILURE; |
3037 | 53 | 54 | ||
3039 | 54 | struct context_st context = { .length= send_length, .buffer= buffer }; | 55 | context.length= send_length; |
3040 | 56 | context.buffer= buffer; | ||
3041 | 55 | 57 | ||
3042 | 56 | callbacks[0]= _set_verbosity; | 58 | callbacks[0]= _set_verbosity; |
3043 | 57 | 59 | ||
3044 | 58 | 60 | ||
3045 | === modified file 'libmemcached/version.c' | |||
3046 | --- libmemcached/version.c 2010-07-16 03:54:57 +0000 | |||
3047 | +++ libmemcached/version.c 2011-01-13 03:40:43 +0000 | |||
3048 | @@ -10,11 +10,13 @@ | |||
3049 | 10 | 10 | ||
3050 | 11 | memcached_return_t memcached_version(memcached_st *ptr) | 11 | memcached_return_t memcached_version(memcached_st *ptr) |
3051 | 12 | { | 12 | { |
3052 | 13 | bool was_blocking; | ||
3053 | 14 | memcached_return_t rc; | ||
3054 | 15 | |||
3055 | 13 | if (ptr->flags.use_udp) | 16 | if (ptr->flags.use_udp) |
3056 | 14 | return MEMCACHED_NOT_SUPPORTED; | 17 | return MEMCACHED_NOT_SUPPORTED; |
3057 | 15 | 18 | ||
3060 | 16 | bool was_blocking= ptr->flags.no_block; | 19 | was_blocking= ptr->flags.no_block; |
3059 | 17 | memcached_return_t rc; | ||
3061 | 18 | 20 | ||
3062 | 19 | ptr->flags.no_block= false; | 21 | ptr->flags.no_block= false; |
3063 | 20 | 22 | ||
3064 | @@ -35,11 +37,12 @@ | |||
3065 | 35 | char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; | 37 | char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; |
3066 | 36 | char *response_ptr; | 38 | char *response_ptr; |
3067 | 37 | const char *command= "version\r\n"; | 39 | const char *command= "version\r\n"; |
3068 | 40 | uint32_t x; | ||
3069 | 38 | 41 | ||
3070 | 39 | send_length= strlen(command); | 42 | send_length= strlen(command); |
3071 | 40 | 43 | ||
3072 | 41 | rc= MEMCACHED_SUCCESS; | 44 | rc= MEMCACHED_SUCCESS; |
3074 | 42 | for (uint32_t x= 0; x < memcached_server_count(ptr); x++) | 45 | for (x= 0; x < memcached_server_count(ptr); x++) |
3075 | 43 | { | 46 | { |
3076 | 44 | memcached_return_t rrc; | 47 | memcached_return_t rrc; |
3077 | 45 | memcached_server_write_instance_st instance= | 48 | memcached_server_write_instance_st instance= |
3078 | @@ -78,13 +81,17 @@ | |||
3079 | 78 | static inline memcached_return_t memcached_version_binary(memcached_st *ptr) | 81 | static inline memcached_return_t memcached_version_binary(memcached_st *ptr) |
3080 | 79 | { | 82 | { |
3081 | 80 | memcached_return_t rc; | 83 | memcached_return_t rc; |
3083 | 81 | protocol_binary_request_version request= { .bytes= {0}}; | 84 | uint32_t x; |
3084 | 85 | protocol_binary_request_version request; | ||
3085 | 86 | |||
3086 | 87 | memset(&request, 0, sizeof(request)); | ||
3087 | 88 | |||
3088 | 82 | request.message.header.request.magic= PROTOCOL_BINARY_REQ; | 89 | request.message.header.request.magic= PROTOCOL_BINARY_REQ; |
3089 | 83 | request.message.header.request.opcode= PROTOCOL_BINARY_CMD_VERSION; | 90 | request.message.header.request.opcode= PROTOCOL_BINARY_CMD_VERSION; |
3090 | 84 | request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; | 91 | request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; |
3091 | 85 | 92 | ||
3092 | 86 | rc= MEMCACHED_SUCCESS; | 93 | rc= MEMCACHED_SUCCESS; |
3094 | 87 | for (uint32_t x= 0; x < memcached_server_count(ptr); x++) | 94 | for (x= 0; x < memcached_server_count(ptr); x++) |
3095 | 88 | { | 95 | { |
3096 | 89 | memcached_return_t rrc; | 96 | memcached_return_t rrc; |
3097 | 90 | 97 | ||
3098 | @@ -100,7 +107,7 @@ | |||
3099 | 100 | } | 107 | } |
3100 | 101 | } | 108 | } |
3101 | 102 | 109 | ||
3103 | 103 | for (uint32_t x= 0; x < memcached_server_count(ptr); x++) | 110 | for (x= 0; x < memcached_server_count(ptr); x++) |
3104 | 104 | { | 111 | { |
3105 | 105 | memcached_server_write_instance_st instance= | 112 | memcached_server_write_instance_st instance= |
3106 | 106 | memcached_server_instance_fetch(ptr, x); | 113 | memcached_server_instance_fetch(ptr, x); |
3107 | 107 | 114 | ||
3108 | === modified file 'libmemcached/visibility.h' | |||
3109 | --- libmemcached/visibility.h 2010-01-21 23:45:12 +0000 | |||
3110 | +++ libmemcached/visibility.h 2011-01-13 03:40:43 +0000 | |||
3111 | @@ -35,16 +35,26 @@ | |||
3112 | 35 | # define LIBMEMCACHED_API __global | 35 | # define LIBMEMCACHED_API __global |
3113 | 36 | # define LIBMEMCACHED_LOCAL __hidden | 36 | # define LIBMEMCACHED_LOCAL __hidden |
3114 | 37 | # elif defined(_MSC_VER) | 37 | # elif defined(_MSC_VER) |
3117 | 38 | # define LIBMEMCACHED_API extern __declspec(dllexport) | 38 | # if defined(LIBMEMCACHED_STATIC) |
3118 | 39 | # define LIBMEMCACHED_LOCAL | 39 | # define LIBMEMCACHED_API |
3119 | 40 | # define LIBMEMCACHED_LOCAL | ||
3120 | 41 | # else | ||
3121 | 42 | # define LIBMEMCACHED_API extern __declspec(dllexport) | ||
3122 | 43 | # define LIBMEMCACHED_LOCAL | ||
3123 | 44 | # endif | ||
3124 | 40 | # else | 45 | # else |
3125 | 41 | # define LIBMEMCACHED_API | 46 | # define LIBMEMCACHED_API |
3126 | 42 | # define LIBMEMCACHED_LOCAL | 47 | # define LIBMEMCACHED_LOCAL |
3127 | 43 | # endif /* defined(HAVE_VISIBILITY) */ | 48 | # endif /* defined(HAVE_VISIBILITY) */ |
3128 | 44 | #else /* defined(BUILDING_LIBMEMCACHED) */ | 49 | #else /* defined(BUILDING_LIBMEMCACHED) */ |
3129 | 45 | # if defined(_MSC_VER) | 50 | # if defined(_MSC_VER) |
3132 | 46 | # define LIBMEMCACHED_API extern __declspec(dllimport) | 51 | # if defined(LIBMEMCACHED_STATIC) |
3133 | 47 | # define LIBMEMCACHED_LOCAL | 52 | # define LIBMEMCACHED_API |
3134 | 53 | # define LIBMEMCACHED_LOCAL | ||
3135 | 54 | # else | ||
3136 | 55 | # define LIBMEMCACHED_API extern __declspec(dllimport) | ||
3137 | 56 | # define LIBMEMCACHED_LOCAL | ||
3138 | 57 | # endif | ||
3139 | 48 | # else | 58 | # else |
3140 | 49 | # define LIBMEMCACHED_API | 59 | # define LIBMEMCACHED_API |
3141 | 50 | # define LIBMEMCACHED_LOCAL | 60 | # define LIBMEMCACHED_LOCAL |
3142 | 51 | 61 | ||
3143 | === modified file 'libmemcached/watchpoint.h' | |||
3144 | --- libmemcached/watchpoint.h 2010-09-13 12:31:19 +0000 | |||
3145 | +++ libmemcached/watchpoint.h 2011-01-13 03:40:43 +0000 | |||
3146 | @@ -58,9 +58,9 @@ | |||
3147 | 58 | #define WATCHPOINT_IFERROR(A) do { if(A != MEMCACHED_SUCCESS)fprintf(stderr, "\nWATCHPOINT %s:%d %s\n", __FILE__, __LINE__, memcached_strerror(NULL, A));fflush(stdout); } while (0) | 58 | #define WATCHPOINT_IFERROR(A) do { if(A != MEMCACHED_SUCCESS)fprintf(stderr, "\nWATCHPOINT %s:%d %s\n", __FILE__, __LINE__, memcached_strerror(NULL, A));fflush(stdout); } while (0) |
3148 | 59 | #define WATCHPOINT_STRING(A) do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %s\n", __FILE__, __LINE__,__func__,A);fflush(stdout); } while (0) | 59 | #define WATCHPOINT_STRING(A) do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %s\n", __FILE__, __LINE__,__func__,A);fflush(stdout); } while (0) |
3149 | 60 | #define WATCHPOINT_STRING_LENGTH(A,B) do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %.*s\n", __FILE__, __LINE__,__func__,(int)B,A);fflush(stdout); } while (0) | 60 | #define WATCHPOINT_STRING_LENGTH(A,B) do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %.*s\n", __FILE__, __LINE__,__func__,(int)B,A);fflush(stdout); } while (0) |
3153 | 61 | #define WATCHPOINT_NUMBER(A) do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %zu\n", __FILE__, __LINE__,__func__,(size_t)(A));fflush(stdout); } while (0) | 61 | #define WATCHPOINT_NUMBER(A) do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %lu\n", __FILE__, __LINE__,__func__,(long unsigned int)(A));fflush(stdout); } while (0) |
3154 | 62 | #define WATCHPOINT_LABELED_NUMBER(A,B) do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %s:%zu\n", __FILE__, __LINE__,__func__,(A),(size_t)(B));fflush(stdout); } while (0) | 62 | #define WATCHPOINT_LABELED_NUMBER(A,B) do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %s:%lu\n", __FILE__, __LINE__,__func__,(A),(long unsigned int)(B));fflush(stdout); } while (0) |
3155 | 63 | #define WATCHPOINT_IF_LABELED_NUMBER(A,B,C) do { if(A) {fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %s:%zu\n", __FILE__, __LINE__,__func__,(B),(size_t)(C));fflush(stdout);} } while (0) | 63 | #define WATCHPOINT_IF_LABELED_NUMBER(A,B,C) do { if(A) {fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %s:%lu\n", __FILE__, __LINE__,__func__,(B),(long unsigned int)(C));fflush(stdout);} } while (0) |
3156 | 64 | #define WATCHPOINT_ERRNO(A) do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %s\n", __FILE__, __LINE__,__func__, strerror(A));fflush(stdout); } while (0) | 64 | #define WATCHPOINT_ERRNO(A) do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %s\n", __FILE__, __LINE__,__func__, strerror(A));fflush(stdout); } while (0) |
3157 | 65 | #define WATCHPOINT_ASSERT_PRINT(A,B,C) do { if(!(A)){fprintf(stderr, "\nWATCHPOINT ASSERT %s:%d (%s) ", __FILE__, __LINE__,__func__);fprintf(stderr, (B),(C));fprintf(stderr,"\n");fflush(stdout); libmemcached_stack_dump(); } assert((A)); } while (0) | 65 | #define WATCHPOINT_ASSERT_PRINT(A,B,C) do { if(!(A)){fprintf(stderr, "\nWATCHPOINT ASSERT %s:%d (%s) ", __FILE__, __LINE__,__func__);fprintf(stderr, (B),(C));fprintf(stderr,"\n");fflush(stdout); libmemcached_stack_dump(); } assert((A)); } while (0) |
3158 | 66 | #define WATCHPOINT_ASSERT(A) do { if (! (A)) {libmemcached_stack_dump();} assert((A)); } while (0) | 66 | #define WATCHPOINT_ASSERT(A) do { if (! (A)) {libmemcached_stack_dump();} assert((A)); } while (0) |
3159 | 67 | 67 | ||
3160 | === modified file 'poll/poll.c' | |||
3161 | --- poll/poll.c 2010-07-28 18:48:00 +0000 | |||
3162 | +++ poll/poll.c 2011-01-13 03:40:43 +0000 | |||
3163 | @@ -9,19 +9,27 @@ | |||
3164 | 9 | * | 9 | * |
3165 | 10 | */ | 10 | */ |
3166 | 11 | #include "config.h" | 11 | #include "config.h" |
3169 | 12 | #include <sys/time.h> | 12 | |
3170 | 13 | #include <strings.h> | 13 | #ifdef WIN32 |
3171 | 14 | # include <ws2tcpip.h> | ||
3172 | 15 | #else | ||
3173 | 16 | # include <sys/time.h> | ||
3174 | 17 | # include <strings.h> | ||
3175 | 18 | #endif | ||
3176 | 14 | 19 | ||
3177 | 15 | int poll(struct pollfd fds[], nfds_t nfds, int tmo) | 20 | int poll(struct pollfd fds[], nfds_t nfds, int tmo) |
3178 | 16 | { | 21 | { |
3179 | 22 | int maxfd= 0, ret; | ||
3180 | 23 | nfds_t x; | ||
3181 | 24 | struct timeval timeout; | ||
3182 | 25 | struct timeval *tp; | ||
3183 | 26 | |||
3184 | 17 | fd_set readfds, writefds, errorfds; | 27 | fd_set readfds, writefds, errorfds; |
3185 | 18 | FD_ZERO(&readfds); | 28 | FD_ZERO(&readfds); |
3186 | 19 | FD_ZERO(&writefds); | 29 | FD_ZERO(&writefds); |
3192 | 20 | FD_ZERO(&errorfds); | 30 | FD_ZERO(&errorfds); |
3193 | 21 | 31 | ||
3194 | 22 | int maxfd= 0; | 32 | for (x= 0; x < nfds; ++x) |
3190 | 23 | |||
3191 | 24 | for (nfds_t x= 0; x < nfds; ++x) | ||
3195 | 25 | { | 33 | { |
3196 | 26 | if (fds[x].events & (POLLIN | POLLOUT)) | 34 | if (fds[x].events & (POLLIN | POLLOUT)) |
3197 | 27 | { | 35 | { |
3198 | @@ -42,21 +50,22 @@ | |||
3199 | 42 | } | 50 | } |
3200 | 43 | } | 51 | } |
3201 | 44 | 52 | ||
3205 | 45 | struct timeval timeout= { .tv_sec = tmo / 1000, | 53 | timeout.tv_sec = tmo / 1000; |
3206 | 46 | .tv_usec= (tmo % 1000) * 1000 }; | 54 | timeout.tv_usec= (tmo % 1000) * 1000; |
3207 | 47 | struct timeval *tp= &timeout; | 55 | |
3208 | 56 | tp= &timeout; | ||
3209 | 48 | if (tmo == -1) | 57 | if (tmo == -1) |
3210 | 49 | { | 58 | { |
3211 | 50 | tp= NULL; | 59 | tp= NULL; |
3212 | 51 | } | 60 | } |
3214 | 52 | int ret= select(maxfd + 1, &readfds, &writefds, &errorfds, tp); | 61 | ret= select(maxfd + 1, &readfds, &writefds, &errorfds, tp); |
3215 | 53 | if (ret <= 0) | 62 | if (ret <= 0) |
3216 | 54 | { | 63 | { |
3217 | 55 | return ret; | 64 | return ret; |
3218 | 56 | } | 65 | } |
3219 | 57 | 66 | ||
3220 | 58 | /* Iterate through all of them because I need to clear the revent map */ | 67 | /* Iterate through all of them because I need to clear the revent map */ |
3222 | 59 | for (nfds_t x= 0; x < nfds; ++x) | 68 | for (x= 0; x < nfds; ++x) |
3223 | 60 | { | 69 | { |
3224 | 61 | fds[x].revents= 0; | 70 | fds[x].revents= 0; |
3225 | 62 | if (FD_ISSET(fds[x].fd, &readfds)) | 71 | if (FD_ISSET(fds[x].fd, &readfds)) |
3226 | 63 | 72 | ||
3227 | === added file 'win32/common.vsprops' | |||
3228 | --- win32/common.vsprops 1970-01-01 00:00:00 +0000 | |||
3229 | +++ win32/common.vsprops 2011-01-13 03:40:43 +0000 | |||
3230 | @@ -0,0 +1,25 @@ | |||
3231 | 1 | <?xml version="1.0" encoding="gb2312"?> | ||
3232 | 2 | <VisualStudioPropertySheet | ||
3233 | 3 | ProjectType="Visual C++" | ||
3234 | 4 | Version="8.00" | ||
3235 | 5 | Name="essential" | ||
3236 | 6 | CharacterSet="2" | ||
3237 | 7 | > | ||
3238 | 8 | <Tool | ||
3239 | 9 | Name="VCCLCompilerTool" | ||
3240 | 10 | AdditionalIncludeDirectories="..;..\win32;" | ||
3241 | 11 | PreprocessorDefinitions="WIN32;_WINDOWS;_USRDLL;LIBMEMCACHED_STATIC" | ||
3242 | 12 | MinimalRebuild="true" | ||
3243 | 13 | RuntimeLibrary="3" | ||
3244 | 14 | WarningLevel="3" | ||
3245 | 15 | DebugInformationFormat="4" | ||
3246 | 16 | /> | ||
3247 | 17 | <Tool | ||
3248 | 18 | Name="VCLinkerTool" | ||
3249 | 19 | AdditionalDependencies="ws2_32.lib libmemcached-win32.lib" | ||
3250 | 20 | AdditionalLibraryDirectories=""$(OutDir)"" | ||
3251 | 21 | GenerateDebugInformation="true" | ||
3252 | 22 | TargetMachine="1" | ||
3253 | 23 | /> | ||
3254 | 24 | </VisualStudioPropertySheet> | ||
3255 | 25 | |||
3256 | 0 | \ No newline at end of file | 26 | \ No newline at end of file |
3257 | 1 | 27 | ||
3258 | === added file 'win32/debug.vsprops' | |||
3259 | --- win32/debug.vsprops 1970-01-01 00:00:00 +0000 | |||
3260 | +++ win32/debug.vsprops 2011-01-13 03:40:43 +0000 | |||
3261 | @@ -0,0 +1,12 @@ | |||
3262 | 1 | <?xml version="1.0" encoding="gb2312"?> | ||
3263 | 2 | <VisualStudioPropertySheet | ||
3264 | 3 | ProjectType="Visual C++" | ||
3265 | 4 | Version="8.00" | ||
3266 | 5 | Name="essential" | ||
3267 | 6 | CharacterSet="2" | ||
3268 | 7 | > | ||
3269 | 8 | <Tool | ||
3270 | 9 | Name="VCCLCompilerTool" | ||
3271 | 10 | PreprocessorDefinitions="_DEBUG" | ||
3272 | 11 | /> | ||
3273 | 12 | </VisualStudioPropertySheet> | ||
3274 | 0 | \ No newline at end of file | 13 | \ No newline at end of file |
3275 | 1 | 14 | ||
3276 | === added file 'win32/getopt.c' | |||
3277 | --- win32/getopt.c 1970-01-01 00:00:00 +0000 | |||
3278 | +++ win32/getopt.c 2011-01-13 03:40:43 +0000 | |||
3279 | @@ -0,0 +1,1067 @@ | |||
3280 | 1 | /* Getopt for GNU. | ||
3281 | 2 | NOTE: getopt is now part of the C library, so if you don't know what | ||
3282 | 3 | "Keep this file name-space clean" means, talk to drepper@gnu.org | ||
3283 | 4 | before changing it! | ||
3284 | 5 | |||
3285 | 6 | Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000 | ||
3286 | 7 | Free Software Foundation, Inc. | ||
3287 | 8 | |||
3288 | 9 | The GNU C Library is free software; you can redistribute it and/or | ||
3289 | 10 | modify it under the terms of the GNU Library General Public License as | ||
3290 | 11 | published by the Free Software Foundation; either version 2 of the | ||
3291 | 12 | License, or (at your option) any later version. | ||
3292 | 13 | |||
3293 | 14 | The GNU C Library is distributed in the hope that it will be useful, | ||
3294 | 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3295 | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
3296 | 17 | Library General Public License for more details. | ||
3297 | 18 | |||
3298 | 19 | You should have received a copy of the GNU Library General Public | ||
3299 | 20 | License along with the GNU C Library; see the file COPYING.LIB. If not, | ||
3300 | 21 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
3301 | 22 | Boston, MA 02111-1307, USA. */ | ||
3302 | 23 | |||
3303 | 0 | 24 | ||
3304 | 25 | /* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>. | ||
3305 | 26 | Ditto for AIX 3.2 and <stdlib.h>. */ | ||
3306 | 27 | #ifndef _NO_PROTO | ||
3307 | 28 | # define _NO_PROTO | ||
3308 | 29 | #endif | ||
3309 | 30 | |||
3310 | 31 | #ifdef HAVE_CONFIG_H | ||
3311 | 32 | # include <config.h> | ||
3312 | 33 | #endif | ||
3313 | 34 | |||
3314 | 35 | #if !defined __STDC__ || !__STDC__ | ||
3315 | 36 | /* This is a separate conditional since some stdc systems | ||
3316 | 37 | reject `defined (const)'. */ | ||
3317 | 38 | # ifndef const | ||
3318 | 39 | # define const | ||
3319 | 40 | # endif | ||
3320 | 41 | #endif | ||
3321 | 42 | |||
3322 | 43 | #include <stdio.h> | ||
3323 | 44 | |||
3324 | 45 | /* Comment out all this code if we are using the GNU C Library, and are not | ||
3325 | 46 | actually compiling the library itself. This code is part of the GNU C | ||
3326 | 47 | Library, but also included in many other GNU distributions. Compiling | ||
3327 | 48 | and linking in this code is a waste when using the GNU C library | ||
3328 | 49 | (especially if it is a shared library). Rather than having every GNU | ||
3329 | 50 | program understand `configure --with-gnu-libc' and omit the object files, | ||
3330 | 51 | it is simpler to just do this in the source for each such file. */ | ||
3331 | 52 | |||
3332 | 53 | #define GETOPT_INTERFACE_VERSION 2 | ||
3333 | 54 | #if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2 | ||
3334 | 55 | # include <gnu-versions.h> | ||
3335 | 56 | # if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION | ||
3336 | 57 | # define ELIDE_CODE | ||
3337 | 58 | # endif | ||
3338 | 59 | #endif | ||
3339 | 60 | |||
3340 | 61 | #ifndef ELIDE_CODE | ||
3341 | 62 | |||
3342 | 63 | |||
3343 | 64 | /* This needs to come after some library #include | ||
3344 | 65 | to get __GNU_LIBRARY__ defined. */ | ||
3345 | 66 | #ifdef __GNU_LIBRARY__ | ||
3346 | 67 | /* Don't include stdlib.h for non-GNU C libraries because some of them | ||
3347 | 68 | contain conflicting prototypes for getopt. */ | ||
3348 | 69 | # include <stdlib.h> | ||
3349 | 70 | # include <unistd.h> | ||
3350 | 71 | #endif /* GNU C library. */ | ||
3351 | 72 | |||
3352 | 73 | #ifdef VMS | ||
3353 | 74 | # include <unixlib.h> | ||
3354 | 75 | # if HAVE_STRING_H - 0 | ||
3355 | 76 | # include <string.h> | ||
3356 | 77 | # endif | ||
3357 | 78 | #endif | ||
3358 | 79 | |||
3359 | 80 | #ifdef WIN32 | ||
3360 | 81 | # define HAVE_STRING_H 1 | ||
3361 | 82 | #endif | ||
3362 | 83 | |||
3363 | 84 | #ifndef _ | ||
3364 | 85 | /* This is for other GNU distributions with internationalized messages. | ||
3365 | 86 | When compiling libc, the _ macro is predefined. */ | ||
3366 | 87 | # ifdef HAVE_LIBINTL_H | ||
3367 | 88 | # include <libintl.h> | ||
3368 | 89 | # define _(msgid) gettext (msgid) | ||
3369 | 90 | # else | ||
3370 | 91 | # define _(msgid) (msgid) | ||
3371 | 92 | # endif | ||
3372 | 93 | #endif | ||
3373 | 94 | |||
3374 | 95 | /* This version of `getopt' appears to the caller like standard Unix `getopt' | ||
3375 | 96 | but it behaves differently for the user, since it allows the user | ||
3376 | 97 | to intersperse the options with the other arguments. | ||
3377 | 98 | |||
3378 | 99 | As `getopt' works, it permutes the elements of ARGV so that, | ||
3379 | 100 | when it is done, all the options precede everything else. Thus | ||
3380 | 101 | all application programs are extended to handle flexible argument order. | ||
3381 | 102 | |||
3382 | 103 | Setting the environment variable POSIXLY_CORRECT disables permutation. | ||
3383 | 104 | Then the behavior is completely standard. | ||
3384 | 105 | |||
3385 | 106 | GNU application programs can use a third alternative mode in which | ||
3386 | 107 | they can distinguish the relative order of options and other arguments. */ | ||
3387 | 108 | |||
3388 | 109 | #include "getopt.h" | ||
3389 | 110 | |||
3390 | 111 | /* For communication from `getopt' to the caller. | ||
3391 | 112 | When `getopt' finds an option that takes an argument, | ||
3392 | 113 | the argument value is returned here. | ||
3393 | 114 | Also, when `ordering' is RETURN_IN_ORDER, | ||
3394 | 115 | each non-option ARGV-element is returned here. */ | ||
3395 | 116 | |||
3396 | 117 | char *optarg; | ||
3397 | 118 | |||
3398 | 119 | /* Index in ARGV of the next element to be scanned. | ||
3399 | 120 | This is used for communication to and from the caller | ||
3400 | 121 | and for communication between successive calls to `getopt'. | ||
3401 | 122 | |||
3402 | 123 | On entry to `getopt', zero means this is the first call; initialize. | ||
3403 | 124 | |||
3404 | 125 | When `getopt' returns -1, this is the index of the first of the | ||
3405 | 126 | non-option elements that the caller should itself scan. | ||
3406 | 127 | |||
3407 | 128 | Otherwise, `optind' communicates from one call to the next | ||
3408 | 129 | how much of ARGV has been scanned so far. */ | ||
3409 | 130 | |||
3410 | 131 | /* 1003.2 says this must be 1 before any call. */ | ||
3411 | 132 | int optind = 1; | ||
3412 | 133 | |||
3413 | 134 | /* Formerly, initialization of getopt depended on optind==0, which | ||
3414 | 135 | causes problems with re-calling getopt as programs generally don't | ||
3415 | 136 | know that. */ | ||
3416 | 137 | |||
3417 | 138 | int __getopt_initialized; | ||
3418 | 139 | |||
3419 | 140 | /* The next char to be scanned in the option-element | ||
3420 | 141 | in which the last option character we returned was found. | ||
3421 | 142 | This allows us to pick up the scan where we left off. | ||
3422 | 143 | |||
3423 | 144 | If this is zero, or a null string, it means resume the scan | ||
3424 | 145 | by advancing to the next ARGV-element. */ | ||
3425 | 146 | |||
3426 | 147 | static char *nextchar; | ||
3427 | 148 | |||
3428 | 149 | /* Callers store zero here to inhibit the error message | ||
3429 | 150 | for unrecognized options. */ | ||
3430 | 151 | |||
3431 | 152 | int opterr = 1; | ||
3432 | 153 | |||
3433 | 154 | /* Set to an option character which was unrecognized. | ||
3434 | 155 | This must be initialized on some systems to avoid linking in the | ||
3435 | 156 | system's own getopt implementation. */ | ||
3436 | 157 | |||
3437 | 158 | int optopt = '?'; | ||
3438 | 159 | |||
3439 | 160 | /* Describe how to deal with options that follow non-option ARGV-elements. | ||
3440 | 161 | |||
3441 | 162 | If the caller did not specify anything, | ||
3442 | 163 | the default is REQUIRE_ORDER if the environment variable | ||
3443 | 164 | POSIXLY_CORRECT is defined, PERMUTE otherwise. | ||
3444 | 165 | |||
3445 | 166 | REQUIRE_ORDER means don't recognize them as options; | ||
3446 | 167 | stop option processing when the first non-option is seen. | ||
3447 | 168 | This is what Unix does. | ||
3448 | 169 | This mode of operation is selected by either setting the environment | ||
3449 | 170 | variable POSIXLY_CORRECT, or using `+' as the first character | ||
3450 | 171 | of the list of option characters. | ||
3451 | 172 | |||
3452 | 173 | PERMUTE is the default. We permute the contents of ARGV as we scan, | ||
3453 | 174 | so that eventually all the non-options are at the end. This allows options | ||
3454 | 175 | to be given in any order, even with programs that were not written to | ||
3455 | 176 | expect this. | ||
3456 | 177 | |||
3457 | 178 | RETURN_IN_ORDER is an option available to programs that were written | ||
3458 | 179 | to expect options and other ARGV-elements in any order and that care about | ||
3459 | 180 | the ordering of the two. We describe each non-option ARGV-element | ||
3460 | 181 | as if it were the argument of an option with character code 1. | ||
3461 | 182 | Using `-' as the first character of the list of option characters | ||
3462 | 183 | selects this mode of operation. | ||
3463 | 184 | |||
3464 | 185 | The special argument `--' forces an end of option-scanning regardless | ||
3465 | 186 | of the value of `ordering'. In the case of RETURN_IN_ORDER, only | ||
3466 | 187 | `--' can cause `getopt' to return -1 with `optind' != ARGC. */ | ||
3467 | 188 | |||
3468 | 189 | static enum | ||
3469 | 190 | { | ||
3470 | 191 | REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER | ||
3471 | 192 | } ordering; | ||
3472 | 193 | |||
3473 | 194 | /* Value of POSIXLY_CORRECT environment variable. */ | ||
3474 | 195 | static char *posixly_correct; | ||
3475 | 196 | |||
3476 | 1 | 197 | ||
3477 | 198 | #ifdef __GNU_LIBRARY__ | ||
3478 | 199 | /* We want to avoid inclusion of string.h with non-GNU libraries | ||
3479 | 200 | because there are many ways it can cause trouble. | ||
3480 | 201 | On some systems, it contains special magic macros that don't work | ||
3481 | 202 | in GCC. */ | ||
3482 | 203 | # include <string.h> | ||
3483 | 204 | # define my_index strchr | ||
3484 | 205 | #else | ||
3485 | 206 | |||
3486 | 207 | # if HAVE_STRING_H | ||
3487 | 208 | # include <string.h> | ||
3488 | 209 | # else | ||
3489 | 210 | # include <strings.h> | ||
3490 | 211 | # endif | ||
3491 | 212 | |||
3492 | 213 | /* Avoid depending on library functions or files | ||
3493 | 214 | whose names are inconsistent. */ | ||
3494 | 215 | |||
3495 | 216 | #ifndef getenv | ||
3496 | 217 | extern char *getenv (); | ||
3497 | 218 | #endif | ||
3498 | 219 | |||
3499 | 220 | static char * | ||
3500 | 221 | my_index (str, chr) | ||
3501 | 222 | const char *str; | ||
3502 | 223 | int chr; | ||
3503 | 224 | { | ||
3504 | 225 | while (*str) | ||
3505 | 226 | { | ||
3506 | 227 | if (*str == chr) | ||
3507 | 228 | return (char *) str; | ||
3508 | 229 | str++; | ||
3509 | 230 | } | ||
3510 | 231 | return 0; | ||
3511 | 232 | } | ||
3512 | 233 | |||
3513 | 234 | /* If using GCC, we can safely declare strlen this way. | ||
3514 | 235 | If not using GCC, it is ok not to declare it. */ | ||
3515 | 236 | #ifdef __GNUC__ | ||
3516 | 237 | /* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h. | ||
3517 | 238 | That was relevant to code that was here before. */ | ||
3518 | 239 | # if (!defined __STDC__ || !__STDC__) && !defined strlen | ||
3519 | 240 | /* gcc with -traditional declares the built-in strlen to return int, | ||
3520 | 241 | and has done so at least since version 2.4.5. -- rms. */ | ||
3521 | 242 | extern int strlen (const char *); | ||
3522 | 243 | # endif /* not __STDC__ */ | ||
3523 | 244 | #endif /* __GNUC__ */ | ||
3524 | 245 | |||
3525 | 246 | #endif /* not __GNU_LIBRARY__ */ | ||
3526 | 247 | |||
3527 | 2 | 248 | ||
3528 | 249 | /* Handle permutation of arguments. */ | ||
3529 | 250 | |||
3530 | 251 | /* Describe the part of ARGV that contains non-options that have | ||
3531 | 252 | been skipped. `first_nonopt' is the index in ARGV of the first of them; | ||
3532 | 253 | `last_nonopt' is the index after the last of them. */ | ||
3533 | 254 | |||
3534 | 255 | static int first_nonopt; | ||
3535 | 256 | static int last_nonopt; | ||
3536 | 257 | |||
3537 | 258 | #ifdef _LIBC | ||
3538 | 259 | /* Bash 2.0 gives us an environment variable containing flags | ||
3539 | 260 | indicating ARGV elements that should not be considered arguments. */ | ||
3540 | 261 | |||
3541 | 262 | /* Defined in getopt_init.c */ | ||
3542 | 263 | extern char *__getopt_nonoption_flags; | ||
3543 | 264 | |||
3544 | 265 | static int nonoption_flags_max_len; | ||
3545 | 266 | static int nonoption_flags_len; | ||
3546 | 267 | |||
3547 | 268 | static int original_argc; | ||
3548 | 269 | static char *const *original_argv; | ||
3549 | 270 | |||
3550 | 271 | /* Make sure the environment variable bash 2.0 puts in the environment | ||
3551 | 272 | is valid for the getopt call we must make sure that the ARGV passed | ||
3552 | 273 | to getopt is that one passed to the process. */ | ||
3553 | 274 | static void | ||
3554 | 275 | __attribute__ ((unused)) | ||
3555 | 276 | store_args_and_env (int argc, char *const *argv) | ||
3556 | 277 | { | ||
3557 | 278 | /* XXX This is no good solution. We should rather copy the args so | ||
3558 | 279 | that we can compare them later. But we must not use malloc(3). */ | ||
3559 | 280 | original_argc = argc; | ||
3560 | 281 | original_argv = argv; | ||
3561 | 282 | } | ||
3562 | 283 | # ifdef text_set_element | ||
3563 | 284 | text_set_element (__libc_subinit, store_args_and_env); | ||
3564 | 285 | # endif /* text_set_element */ | ||
3565 | 286 | |||
3566 | 287 | # define SWAP_FLAGS(ch1, ch2) \ | ||
3567 | 288 | if (nonoption_flags_len > 0) \ | ||
3568 | 289 | { \ | ||
3569 | 290 | char __tmp = __getopt_nonoption_flags[ch1]; \ | ||
3570 | 291 | __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \ | ||
3571 | 292 | __getopt_nonoption_flags[ch2] = __tmp; \ | ||
3572 | 293 | } | ||
3573 | 294 | #else /* !_LIBC */ | ||
3574 | 295 | # define SWAP_FLAGS(ch1, ch2) | ||
3575 | 296 | #endif /* _LIBC */ | ||
3576 | 297 | |||
3577 | 298 | /* Exchange two adjacent subsequences of ARGV. | ||
3578 | 299 | One subsequence is elements [first_nonopt,last_nonopt) | ||
3579 | 300 | which contains all the non-options that have been skipped so far. | ||
3580 | 301 | The other is elements [last_nonopt,optind), which contains all | ||
3581 | 302 | the options processed since those non-options were skipped. | ||
3582 | 303 | |||
3583 | 304 | `first_nonopt' and `last_nonopt' are relocated so that they describe | ||
3584 | 305 | the new indices of the non-options in ARGV after they are moved. */ | ||
3585 | 306 | |||
3586 | 307 | #if defined __STDC__ && __STDC__ | ||
3587 | 308 | static void exchange (char **); | ||
3588 | 309 | #endif | ||
3589 | 310 | |||
3590 | 311 | static void | ||
3591 | 312 | exchange (argv) | ||
3592 | 313 | char **argv; | ||
3593 | 314 | { | ||
3594 | 315 | int bottom = first_nonopt; | ||
3595 | 316 | int middle = last_nonopt; | ||
3596 | 317 | int top = optind; | ||
3597 | 318 | char *tem; | ||
3598 | 319 | |||
3599 | 320 | /* Exchange the shorter segment with the far end of the longer segment. | ||
3600 | 321 | That puts the shorter segment into the right place. | ||
3601 | 322 | It leaves the longer segment in the right place overall, | ||
3602 | 323 | but it consists of two parts that need to be swapped next. */ | ||
3603 | 324 | |||
3604 | 325 | #ifdef _LIBC | ||
3605 | 326 | /* First make sure the handling of the `__getopt_nonoption_flags' | ||
3606 | 327 | string can work normally. Our top argument must be in the range | ||
3607 | 328 | of the string. */ | ||
3608 | 329 | if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len) | ||
3609 | 330 | { | ||
3610 | 331 | /* We must extend the array. The user plays games with us and | ||
3611 | 332 | presents new arguments. */ | ||
3612 | 333 | char *new_str = malloc (top + 1); | ||
3613 | 334 | if (new_str == NULL) | ||
3614 | 335 | nonoption_flags_len = nonoption_flags_max_len = 0; | ||
3615 | 336 | else | ||
3616 | 337 | { | ||
3617 | 338 | memset (__mempcpy (new_str, __getopt_nonoption_flags, | ||
3618 | 339 | nonoption_flags_max_len), | ||
3619 | 340 | '\0', top + 1 - nonoption_flags_max_len); | ||
3620 | 341 | nonoption_flags_max_len = top + 1; | ||
3621 | 342 | __getopt_nonoption_flags = new_str; | ||
3622 | 343 | } | ||
3623 | 344 | } | ||
3624 | 345 | #endif | ||
3625 | 346 | |||
3626 | 347 | while (top > middle && middle > bottom) | ||
3627 | 348 | { | ||
3628 | 349 | if (top - middle > middle - bottom) | ||
3629 | 350 | { | ||
3630 | 351 | /* Bottom segment is the short one. */ | ||
3631 | 352 | int len = middle - bottom; | ||
3632 | 353 | register int i; | ||
3633 | 354 | |||
3634 | 355 | /* Swap it with the top part of the top segment. */ | ||
3635 | 356 | for (i = 0; i < len; i++) | ||
3636 | 357 | { | ||
3637 | 358 | tem = argv[bottom + i]; | ||
3638 | 359 | argv[bottom + i] = argv[top - (middle - bottom) + i]; | ||
3639 | 360 | argv[top - (middle - bottom) + i] = tem; | ||
3640 | 361 | SWAP_FLAGS (bottom + i, top - (middle - bottom) + i); | ||
3641 | 362 | } | ||
3642 | 363 | /* Exclude the moved bottom segment from further swapping. */ | ||
3643 | 364 | top -= len; | ||
3644 | 365 | } | ||
3645 | 366 | else | ||
3646 | 367 | { | ||
3647 | 368 | /* Top segment is the short one. */ | ||
3648 | 369 | int len = top - middle; | ||
3649 | 370 | register int i; | ||
3650 | 371 | |||
3651 | 372 | /* Swap it with the bottom part of the bottom segment. */ | ||
3652 | 373 | for (i = 0; i < len; i++) | ||
3653 | 374 | { | ||
3654 | 375 | tem = argv[bottom + i]; | ||
3655 | 376 | argv[bottom + i] = argv[middle + i]; | ||
3656 | 377 | argv[middle + i] = tem; | ||
3657 | 378 | SWAP_FLAGS (bottom + i, middle + i); | ||
3658 | 379 | } | ||
3659 | 380 | /* Exclude the moved top segment from further swapping. */ | ||
3660 | 381 | bottom += len; | ||
3661 | 382 | } | ||
3662 | 383 | } | ||
3663 | 384 | |||
3664 | 385 | /* Update records for the slots the non-options now occupy. */ | ||
3665 | 386 | |||
3666 | 387 | first_nonopt += (optind - last_nonopt); | ||
3667 | 388 | last_nonopt = optind; | ||
3668 | 389 | } | ||
3669 | 390 | |||
3670 | 391 | /* Initialize the internal data when the first call is made. */ | ||
3671 | 392 | |||
3672 | 393 | #if defined __STDC__ && __STDC__ | ||
3673 | 394 | static const char *_getopt_initialize (int, char *const *, const char *); | ||
3674 | 395 | #endif | ||
3675 | 396 | static const char * | ||
3676 | 397 | _getopt_initialize (argc, argv, optstring) | ||
3677 | 398 | int argc; | ||
3678 | 399 | char *const *argv; | ||
3679 | 400 | const char *optstring; | ||
3680 | 401 | { | ||
3681 | 402 | /* Start processing options with ARGV-element 1 (since ARGV-element 0 | ||
3682 | 403 | is the program name); the sequence of previously skipped | ||
3683 | 404 | non-option ARGV-elements is empty. */ | ||
3684 | 405 | |||
3685 | 406 | first_nonopt = last_nonopt = optind; | ||
3686 | 407 | |||
3687 | 408 | nextchar = NULL; | ||
3688 | 409 | |||
3689 | 410 | posixly_correct = getenv ("POSIXLY_CORRECT"); | ||
3690 | 411 | |||
3691 | 412 | /* Determine how to handle the ordering of options and nonoptions. */ | ||
3692 | 413 | |||
3693 | 414 | if (optstring[0] == '-') | ||
3694 | 415 | { | ||
3695 | 416 | ordering = RETURN_IN_ORDER; | ||
3696 | 417 | ++optstring; | ||
3697 | 418 | } | ||
3698 | 419 | else if (optstring[0] == '+') | ||
3699 | 420 | { | ||
3700 | 421 | ordering = REQUIRE_ORDER; | ||
3701 | 422 | ++optstring; | ||
3702 | 423 | } | ||
3703 | 424 | else if (posixly_correct != NULL) | ||
3704 | 425 | ordering = REQUIRE_ORDER; | ||
3705 | 426 | else | ||
3706 | 427 | ordering = PERMUTE; | ||
3707 | 428 | |||
3708 | 429 | #ifdef _LIBC | ||
3709 | 430 | if (posixly_correct == NULL | ||
3710 | 431 | && argc == original_argc && argv == original_argv) | ||
3711 | 432 | { | ||
3712 | 433 | if (nonoption_flags_max_len == 0) | ||
3713 | 434 | { | ||
3714 | 435 | if (__getopt_nonoption_flags == NULL | ||
3715 | 436 | || __getopt_nonoption_flags[0] == '\0') | ||
3716 | 437 | nonoption_flags_max_len = -1; | ||
3717 | 438 | else | ||
3718 | 439 | { | ||
3719 | 440 | const char *orig_str = __getopt_nonoption_flags; | ||
3720 | 441 | int len = nonoption_flags_max_len = strlen (orig_str); | ||
3721 | 442 | if (nonoption_flags_max_len < argc) | ||
3722 | 443 | nonoption_flags_max_len = argc; | ||
3723 | 444 | __getopt_nonoption_flags = | ||
3724 | 445 | (char *) malloc (nonoption_flags_max_len); | ||
3725 | 446 | if (__getopt_nonoption_flags == NULL) | ||
3726 | 447 | nonoption_flags_max_len = -1; | ||
3727 | 448 | else | ||
3728 | 449 | memset (__mempcpy (__getopt_nonoption_flags, orig_str, len), | ||
3729 | 450 | '\0', nonoption_flags_max_len - len); | ||
3730 | 451 | } | ||
3731 | 452 | } | ||
3732 | 453 | nonoption_flags_len = nonoption_flags_max_len; | ||
3733 | 454 | } | ||
3734 | 455 | else | ||
3735 | 456 | nonoption_flags_len = 0; | ||
3736 | 457 | #endif | ||
3737 | 458 | |||
3738 | 459 | return optstring; | ||
3739 | 460 | } | ||
3740 | 461 | |||
3741 | 3 | 462 | ||
3742 | 463 | /* Scan elements of ARGV (whose length is ARGC) for option characters | ||
3743 | 464 | given in OPTSTRING. | ||
3744 | 465 | |||
3745 | 466 | If an element of ARGV starts with '-', and is not exactly "-" or "--", | ||
3746 | 467 | then it is an option element. The characters of this element | ||
3747 | 468 | (aside from the initial '-') are option characters. If `getopt' | ||
3748 | 469 | is called repeatedly, it returns successively each of the option characters | ||
3749 | 470 | from each of the option elements. | ||
3750 | 471 | |||
3751 | 472 | If `getopt' finds another option character, it returns that character, | ||
3752 | 473 | updating `optind' and `nextchar' so that the next call to `getopt' can | ||
3753 | 474 | resume the scan with the following option character or ARGV-element. | ||
3754 | 475 | |||
3755 | 476 | If there are no more option characters, `getopt' returns -1. | ||
3756 | 477 | Then `optind' is the index in ARGV of the first ARGV-element | ||
3757 | 478 | that is not an option. (The ARGV-elements have been permuted | ||
3758 | 479 | so that those that are not options now come last.) | ||
3759 | 480 | |||
3760 | 481 | OPTSTRING is a string containing the legitimate option characters. | ||
3761 | 482 | If an option character is seen that is not listed in OPTSTRING, | ||
3762 | 483 | return '?' after printing an error message. If you set `opterr' to | ||
3763 | 484 | zero, the error message is suppressed but we still return '?'. | ||
3764 | 485 | |||
3765 | 486 | If a char in OPTSTRING is followed by a colon, that means it wants an arg, | ||
3766 | 487 | so the following text in the same ARGV-element, or the text of the following | ||
3767 | 488 | ARGV-element, is returned in `optarg'. Two colons mean an option that | ||
3768 | 489 | wants an optional arg; if there is text in the current ARGV-element, | ||
3769 | 490 | it is returned in `optarg', otherwise `optarg' is set to zero. | ||
3770 | 491 | |||
3771 | 492 | If OPTSTRING starts with `-' or `+', it requests different methods of | ||
3772 | 493 | handling the non-option ARGV-elements. | ||
3773 | 494 | See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. | ||
3774 | 495 | |||
3775 | 496 | Long-named options begin with `--' instead of `-'. | ||
3776 | 497 | Their names may be abbreviated as long as the abbreviation is unique | ||
3777 | 498 | or is an exact match for some defined option. If they have an | ||
3778 | 499 | argument, it follows the option name in the same ARGV-element, separated | ||
3779 | 500 | from the option name by a `=', or else the in next ARGV-element. | ||
3780 | 501 | When `getopt' finds a long-named option, it returns 0 if that option's | ||
3781 | 502 | `flag' field is nonzero, the value of the option's `val' field | ||
3782 | 503 | if the `flag' field is zero. | ||
3783 | 504 | |||
3784 | 505 | The elements of ARGV aren't really const, because we permute them. | ||
3785 | 506 | But we pretend they're const in the prototype to be compatible | ||
3786 | 507 | with other systems. | ||
3787 | 508 | |||
3788 | 509 | LONGOPTS is a vector of `struct option' terminated by an | ||
3789 | 510 | element containing a name which is zero. | ||
3790 | 511 | |||
3791 | 512 | LONGIND returns the index in LONGOPT of the long-named option found. | ||
3792 | 513 | It is only valid when a long-named option has been found by the most | ||
3793 | 514 | recent call. | ||
3794 | 515 | |||
3795 | 516 | If LONG_ONLY is nonzero, '-' as well as '--' can introduce | ||
3796 | 517 | long-named options. */ | ||
3797 | 518 | |||
3798 | 519 | int | ||
3799 | 520 | _getopt_internal (argc, argv, optstring, longopts, longind, long_only) | ||
3800 | 521 | int argc; | ||
3801 | 522 | char *const *argv; | ||
3802 | 523 | const char *optstring; | ||
3803 | 524 | const struct option *longopts; | ||
3804 | 525 | int *longind; | ||
3805 | 526 | int long_only; | ||
3806 | 527 | { | ||
3807 | 528 | int print_errors = opterr; | ||
3808 | 529 | if (optstring[0] == ':') | ||
3809 | 530 | print_errors = 0; | ||
3810 | 531 | |||
3811 | 532 | optarg = NULL; | ||
3812 | 533 | |||
3813 | 534 | if (optind == 0 || !__getopt_initialized) | ||
3814 | 535 | { | ||
3815 | 536 | if (optind == 0) | ||
3816 | 537 | optind = 1; /* Don't scan ARGV[0], the program name. */ | ||
3817 | 538 | optstring = _getopt_initialize (argc, argv, optstring); | ||
3818 | 539 | __getopt_initialized = 1; | ||
3819 | 540 | } | ||
3820 | 541 | |||
3821 | 542 | /* Test whether ARGV[optind] points to a non-option argument. | ||
3822 | 543 | Either it does not have option syntax, or there is an environment flag | ||
3823 | 544 | from the shell indicating it is not an option. The later information | ||
3824 | 545 | is only used when the used in the GNU libc. */ | ||
3825 | 546 | #ifdef _LIBC | ||
3826 | 547 | # define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' \ | ||
3827 | 548 | || (optind < nonoption_flags_len \ | ||
3828 | 549 | && __getopt_nonoption_flags[optind] == '1')) | ||
3829 | 550 | #else | ||
3830 | 551 | # define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0') | ||
3831 | 552 | #endif | ||
3832 | 553 | |||
3833 | 554 | if (nextchar == NULL || *nextchar == '\0') | ||
3834 | 555 | { | ||
3835 | 556 | /* Advance to the next ARGV-element. */ | ||
3836 | 557 | |||
3837 | 558 | /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been | ||
3838 | 559 | moved back by the user (who may also have changed the arguments). */ | ||
3839 | 560 | if (last_nonopt > optind) | ||
3840 | 561 | last_nonopt = optind; | ||
3841 | 562 | if (first_nonopt > optind) | ||
3842 | 563 | first_nonopt = optind; | ||
3843 | 564 | |||
3844 | 565 | if (ordering == PERMUTE) | ||
3845 | 566 | { | ||
3846 | 567 | /* If we have just processed some options following some non-options, | ||
3847 | 568 | exchange them so that the options come first. */ | ||
3848 | 569 | |||
3849 | 570 | if (first_nonopt != last_nonopt && last_nonopt != optind) | ||
3850 | 571 | exchange ((char **) argv); | ||
3851 | 572 | else if (last_nonopt != optind) | ||
3852 | 573 | first_nonopt = optind; | ||
3853 | 574 | |||
3854 | 575 | /* Skip any additional non-options | ||
3855 | 576 | and extend the range of non-options previously skipped. */ | ||
3856 | 577 | |||
3857 | 578 | while (optind < argc && NONOPTION_P) | ||
3858 | 579 | optind++; | ||
3859 | 580 | last_nonopt = optind; | ||
3860 | 581 | } | ||
3861 | 582 | |||
3862 | 583 | /* The special ARGV-element `--' means premature end of options. | ||
3863 | 584 | Skip it like a null option, | ||
3864 | 585 | then exchange with previous non-options as if it were an option, | ||
3865 | 586 | then skip everything else like a non-option. */ | ||
3866 | 587 | |||
3867 | 588 | if (optind != argc && !strcmp (argv[optind], "--")) | ||
3868 | 589 | { | ||
3869 | 590 | optind++; | ||
3870 | 591 | |||
3871 | 592 | if (first_nonopt != last_nonopt && last_nonopt != optind) | ||
3872 | 593 | exchange ((char **) argv); | ||
3873 | 594 | else if (first_nonopt == last_nonopt) | ||
3874 | 595 | first_nonopt = optind; | ||
3875 | 596 | last_nonopt = argc; | ||
3876 | 597 | |||
3877 | 598 | optind = argc; | ||
3878 | 599 | } | ||
3879 | 600 | |||
3880 | 601 | /* If we have done all the ARGV-elements, stop the scan | ||
3881 | 602 | and back over any non-options that we skipped and permuted. */ | ||
3882 | 603 | |||
3883 | 604 | if (optind == argc) | ||
3884 | 605 | { | ||
3885 | 606 | /* Set the next-arg-index to point at the non-options | ||
3886 | 607 | that we previously skipped, so the caller will digest them. */ | ||
3887 | 608 | if (first_nonopt != last_nonopt) | ||
3888 | 609 | optind = first_nonopt; | ||
3889 | 610 | return -1; | ||
3890 | 611 | } | ||
3891 | 612 | |||
3892 | 613 | /* If we have come to a non-option and did not permute it, | ||
3893 | 614 | either stop the scan or describe it to the caller and pass it by. */ | ||
3894 | 615 | |||
3895 | 616 | if (NONOPTION_P) | ||
3896 | 617 | { | ||
3897 | 618 | if (ordering == REQUIRE_ORDER) | ||
3898 | 619 | return -1; | ||
3899 | 620 | optarg = argv[optind++]; | ||
3900 | 621 | return 1; | ||
3901 | 622 | } | ||
3902 | 623 | |||
3903 | 624 | /* We have found another option-ARGV-element. | ||
3904 | 625 | Skip the initial punctuation. */ | ||
3905 | 626 | |||
3906 | 627 | nextchar = (argv[optind] + 1 | ||
3907 | 628 | + (longopts != NULL && argv[optind][1] == '-')); | ||
3908 | 629 | } | ||
3909 | 630 | |||
3910 | 631 | /* Decode the current option-ARGV-element. */ | ||
3911 | 632 | |||
3912 | 633 | /* Check whether the ARGV-element is a long option. | ||
3913 | 634 | |||
3914 | 635 | If long_only and the ARGV-element has the form "-f", where f is | ||
3915 | 636 | a valid short option, don't consider it an abbreviated form of | ||
3916 | 637 | a long option that starts with f. Otherwise there would be no | ||
3917 | 638 | way to give the -f short option. | ||
3918 | 639 | |||
3919 | 640 | On the other hand, if there's a long option "fubar" and | ||
3920 | 641 | the ARGV-element is "-fu", do consider that an abbreviation of | ||
3921 | 642 | the long option, just like "--fu", and not "-f" with arg "u". | ||
3922 | 643 | |||
3923 | 644 | This distinction seems to be the most useful approach. */ | ||
3924 | 645 | |||
3925 | 646 | if (longopts != NULL | ||
3926 | 647 | && (argv[optind][1] == '-' | ||
3927 | 648 | || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1]))))) | ||
3928 | 649 | { | ||
3929 | 650 | char *nameend; | ||
3930 | 651 | const struct option *p; | ||
3931 | 652 | const struct option *pfound = NULL; | ||
3932 | 653 | int exact = 0; | ||
3933 | 654 | int ambig = 0; | ||
3934 | 655 | int indfound = -1; | ||
3935 | 656 | int option_index; | ||
3936 | 657 | |||
3937 | 658 | for (nameend = nextchar; *nameend && *nameend != '='; nameend++) | ||
3938 | 659 | /* Do nothing. */ ; | ||
3939 | 660 | |||
3940 | 661 | /* Test all long options for either exact match | ||
3941 | 662 | or abbreviated matches. */ | ||
3942 | 663 | for (p = longopts, option_index = 0; p->name; p++, option_index++) | ||
3943 | 664 | if (!strncmp (p->name, nextchar, nameend - nextchar)) | ||
3944 | 665 | { | ||
3945 | 666 | if ((unsigned int) (nameend - nextchar) | ||
3946 | 667 | == (unsigned int) strlen (p->name)) | ||
3947 | 668 | { | ||
3948 | 669 | /* Exact match found. */ | ||
3949 | 670 | pfound = p; | ||
3950 | 671 | indfound = option_index; | ||
3951 | 672 | exact = 1; | ||
3952 | 673 | break; | ||
3953 | 674 | } | ||
3954 | 675 | else if (pfound == NULL) | ||
3955 | 676 | { | ||
3956 | 677 | /* First nonexact match found. */ | ||
3957 | 678 | pfound = p; | ||
3958 | 679 | indfound = option_index; | ||
3959 | 680 | } | ||
3960 | 681 | else | ||
3961 | 682 | /* Second or later nonexact match found. */ | ||
3962 | 683 | ambig = 1; | ||
3963 | 684 | } | ||
3964 | 685 | |||
3965 | 686 | if (ambig && !exact) | ||
3966 | 687 | { | ||
3967 | 688 | if (print_errors) | ||
3968 | 689 | fprintf (stderr, _("%s: option `%s' is ambiguous\n"), | ||
3969 | 690 | argv[0], argv[optind]); | ||
3970 | 691 | nextchar += strlen (nextchar); | ||
3971 | 692 | optind++; | ||
3972 | 693 | optopt = 0; | ||
3973 | 694 | return '?'; | ||
3974 | 695 | } | ||
3975 | 696 | |||
3976 | 697 | if (pfound != NULL) | ||
3977 | 698 | { | ||
3978 | 699 | option_index = indfound; | ||
3979 | 700 | optind++; | ||
3980 | 701 | if (*nameend) | ||
3981 | 702 | { | ||
3982 | 703 | /* Don't test has_arg with >, because some C compilers don't | ||
3983 | 704 | allow it to be used on enums. */ | ||
3984 | 705 | if (pfound->has_arg) | ||
3985 | 706 | optarg = nameend + 1; | ||
3986 | 707 | else | ||
3987 | 708 | { | ||
3988 | 709 | if (print_errors) | ||
3989 | 710 | { | ||
3990 | 711 | if (argv[optind - 1][1] == '-') | ||
3991 | 712 | /* --option */ | ||
3992 | 713 | fprintf (stderr, | ||
3993 | 714 | _("%s: option `--%s' doesn't allow an argument\n"), | ||
3994 | 715 | argv[0], pfound->name); | ||
3995 | 716 | else | ||
3996 | 717 | /* +option or -option */ | ||
3997 | 718 | fprintf (stderr, | ||
3998 | 719 | _("%s: option `%c%s' doesn't allow an argument\n"), | ||
3999 | 720 | argv[0], argv[optind - 1][0], pfound->name); | ||
4000 | 721 | } | ||
4001 | 722 | |||
4002 | 723 | nextchar += strlen (nextchar); | ||
4003 | 724 | |||
4004 | 725 | optopt = pfound->val; | ||
4005 | 726 | return '?'; | ||
4006 | 727 | } | ||
4007 | 728 | } | ||
4008 | 729 | else if (pfound->has_arg == 1) | ||
4009 | 730 | { | ||
4010 | 731 | if (optind < argc) | ||
4011 | 732 | optarg = argv[optind++]; | ||
4012 | 733 | else | ||
4013 | 734 | { | ||
4014 | 735 | if (print_errors) | ||
4015 | 736 | fprintf (stderr, | ||
4016 | 737 | _("%s: option `%s' requires an argument\n"), | ||
4017 | 738 | argv[0], argv[optind - 1]); | ||
4018 | 739 | nextchar += strlen (nextchar); | ||
4019 | 740 | optopt = pfound->val; | ||
4020 | 741 | return optstring[0] == ':' ? ':' : '?'; | ||
4021 | 742 | } | ||
4022 | 743 | } | ||
4023 | 744 | nextchar += strlen (nextchar); | ||
4024 | 745 | if (longind != NULL) | ||
4025 | 746 | *longind = option_index; | ||
4026 | 747 | if (pfound->flag) | ||
4027 | 748 | { | ||
4028 | 749 | *(pfound->flag) = pfound->val; | ||
4029 | 750 | return 0; | ||
4030 | 751 | } | ||
4031 | 752 | return pfound->val; | ||
4032 | 753 | } | ||
4033 | 754 | |||
4034 | 755 | /* Can't find it as a long option. If this is not getopt_long_only, | ||
4035 | 756 | or the option starts with '--' or is not a valid short | ||
4036 | 757 | option, then it's an error. | ||
4037 | 758 | Otherwise interpret it as a short option. */ | ||
4038 | 759 | if (!long_only || argv[optind][1] == '-' | ||
4039 | 760 | || my_index (optstring, *nextchar) == NULL) | ||
4040 | 761 | { | ||
4041 | 762 | if (print_errors) | ||
4042 | 763 | { | ||
4043 | 764 | if (argv[optind][1] == '-') | ||
4044 | 765 | /* --option */ | ||
4045 | 766 | fprintf (stderr, _("%s: unrecognized option `--%s'\n"), | ||
4046 | 767 | argv[0], nextchar); | ||
4047 | 768 | else | ||
4048 | 769 | /* +option or -option */ | ||
4049 | 770 | fprintf (stderr, _("%s: unrecognized option `%c%s'\n"), | ||
4050 | 771 | argv[0], argv[optind][0], nextchar); | ||
4051 | 772 | } | ||
4052 | 773 | nextchar = (char *) ""; | ||
4053 | 774 | optind++; | ||
4054 | 775 | optopt = 0; | ||
4055 | 776 | return '?'; | ||
4056 | 777 | } | ||
4057 | 778 | } | ||
4058 | 779 | |||
4059 | 780 | /* Look at and handle the next short option-character. */ | ||
4060 | 781 | |||
4061 | 782 | { | ||
4062 | 783 | char c = *nextchar++; | ||
4063 | 784 | char *temp = my_index (optstring, c); | ||
4064 | 785 | |||
4065 | 786 | /* Increment `optind' when we start to process its last character. */ | ||
4066 | 787 | if (*nextchar == '\0') | ||
4067 | 788 | ++optind; | ||
4068 | 789 | |||
4069 | 790 | if (temp == NULL || c == ':') | ||
4070 | 791 | { | ||
4071 | 792 | if (print_errors) | ||
4072 | 793 | { | ||
4073 | 794 | if (posixly_correct) | ||
4074 | 795 | /* 1003.2 specifies the format of this message. */ | ||
4075 | 796 | fprintf (stderr, _("%s: illegal option -- %c\n"), | ||
4076 | 797 | argv[0], c); | ||
4077 | 798 | else | ||
4078 | 799 | fprintf (stderr, _("%s: invalid option -- %c\n"), | ||
4079 | 800 | argv[0], c); | ||
4080 | 801 | } | ||
4081 | 802 | optopt = c; | ||
4082 | 803 | return '?'; | ||
4083 | 804 | } | ||
4084 | 805 | /* Convenience. Treat POSIX -W foo same as long option --foo */ | ||
4085 | 806 | if (temp[0] == 'W' && temp[1] == ';') | ||
4086 | 807 | { | ||
4087 | 808 | char *nameend; | ||
4088 | 809 | const struct option *p; | ||
4089 | 810 | const struct option *pfound = NULL; | ||
4090 | 811 | int exact = 0; | ||
4091 | 812 | int ambig = 0; | ||
4092 | 813 | int indfound = 0; | ||
4093 | 814 | int option_index; | ||
4094 | 815 | |||
4095 | 816 | /* This is an option that requires an argument. */ | ||
4096 | 817 | if (*nextchar != '\0') | ||
4097 | 818 | { | ||
4098 | 819 | optarg = nextchar; | ||
4099 | 820 | /* If we end this ARGV-element by taking the rest as an arg, | ||
4100 | 821 | we must advance to the next element now. */ | ||
4101 | 822 | optind++; | ||
4102 | 823 | } | ||
4103 | 824 | else if (optind == argc) | ||
4104 | 825 | { | ||
4105 | 826 | if (print_errors) | ||
4106 | 827 | { | ||
4107 | 828 | /* 1003.2 specifies the format of this message. */ | ||
4108 | 829 | fprintf (stderr, _("%s: option requires an argument -- %c\n"), | ||
4109 | 830 | argv[0], c); | ||
4110 | 831 | } | ||
4111 | 832 | optopt = c; | ||
4112 | 833 | if (optstring[0] == ':') | ||
4113 | 834 | c = ':'; | ||
4114 | 835 | else | ||
4115 | 836 | c = '?'; | ||
4116 | 837 | return c; | ||
4117 | 838 | } | ||
4118 | 839 | else | ||
4119 | 840 | /* We already incremented `optind' once; | ||
4120 | 841 | increment it again when taking next ARGV-elt as argument. */ | ||
4121 | 842 | optarg = argv[optind++]; | ||
4122 | 843 | |||
4123 | 844 | /* optarg is now the argument, see if it's in the | ||
4124 | 845 | table of longopts. */ | ||
4125 | 846 | |||
4126 | 847 | for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++) | ||
4127 | 848 | /* Do nothing. */ ; | ||
4128 | 849 | |||
4129 | 850 | /* Test all long options for either exact match | ||
4130 | 851 | or abbreviated matches. */ | ||
4131 | 852 | for (p = longopts, option_index = 0; p->name; p++, option_index++) | ||
4132 | 853 | if (!strncmp (p->name, nextchar, nameend - nextchar)) | ||
4133 | 854 | { | ||
4134 | 855 | if ((unsigned int) (nameend - nextchar) == strlen (p->name)) | ||
4135 | 856 | { | ||
4136 | 857 | /* Exact match found. */ | ||
4137 | 858 | pfound = p; | ||
4138 | 859 | indfound = option_index; | ||
4139 | 860 | exact = 1; | ||
4140 | 861 | break; | ||
4141 | 862 | } | ||
4142 | 863 | else if (pfound == NULL) | ||
4143 | 864 | { | ||
4144 | 865 | /* First nonexact match found. */ | ||
4145 | 866 | pfound = p; | ||
4146 | 867 | indfound = option_index; | ||
4147 | 868 | } | ||
4148 | 869 | else | ||
4149 | 870 | /* Second or later nonexact match found. */ | ||
4150 | 871 | ambig = 1; | ||
4151 | 872 | } | ||
4152 | 873 | if (ambig && !exact) | ||
4153 | 874 | { | ||
4154 | 875 | if (print_errors) | ||
4155 | 876 | fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), | ||
4156 | 877 | argv[0], argv[optind]); | ||
4157 | 878 | nextchar += strlen (nextchar); | ||
4158 | 879 | optind++; | ||
4159 | 880 | return '?'; | ||
4160 | 881 | } | ||
4161 | 882 | if (pfound != NULL) | ||
4162 | 883 | { | ||
4163 | 884 | option_index = indfound; | ||
4164 | 885 | if (*nameend) | ||
4165 | 886 | { | ||
4166 | 887 | /* Don't test has_arg with >, because some C compilers don't | ||
4167 | 888 | allow it to be used on enums. */ | ||
4168 | 889 | if (pfound->has_arg) | ||
4169 | 890 | optarg = nameend + 1; | ||
4170 | 891 | else | ||
4171 | 892 | { | ||
4172 | 893 | if (print_errors) | ||
4173 | 894 | fprintf (stderr, _("\ | ||
4174 | 895 | %s: option `-W %s' doesn't allow an argument\n"), | ||
4175 | 896 | argv[0], pfound->name); | ||
4176 | 897 | |||
4177 | 898 | nextchar += strlen (nextchar); | ||
4178 | 899 | return '?'; | ||
4179 | 900 | } | ||
4180 | 901 | } | ||
4181 | 902 | else if (pfound->has_arg == 1) | ||
4182 | 903 | { | ||
4183 | 904 | if (optind < argc) | ||
4184 | 905 | optarg = argv[optind++]; | ||
4185 | 906 | else | ||
4186 | 907 | { | ||
4187 | 908 | if (print_errors) | ||
4188 | 909 | fprintf (stderr, | ||
4189 | 910 | _("%s: option `%s' requires an argument\n"), | ||
4190 | 911 | argv[0], argv[optind - 1]); | ||
4191 | 912 | nextchar += strlen (nextchar); | ||
4192 | 913 | return optstring[0] == ':' ? ':' : '?'; | ||
4193 | 914 | } | ||
4194 | 915 | } | ||
4195 | 916 | nextchar += strlen (nextchar); | ||
4196 | 917 | if (longind != NULL) | ||
4197 | 918 | *longind = option_index; | ||
4198 | 919 | if (pfound->flag) | ||
4199 | 920 | { | ||
4200 | 921 | *(pfound->flag) = pfound->val; | ||
4201 | 922 | return 0; | ||
4202 | 923 | } | ||
4203 | 924 | return pfound->val; | ||
4204 | 925 | } | ||
4205 | 926 | nextchar = NULL; | ||
4206 | 927 | return 'W'; /* Let the application handle it. */ | ||
4207 | 928 | } | ||
4208 | 929 | if (temp[1] == ':') | ||
4209 | 930 | { | ||
4210 | 931 | if (temp[2] == ':') | ||
4211 | 932 | { | ||
4212 | 933 | /* This is an option that accepts an argument optionally. */ | ||
4213 | 934 | if (*nextchar != '\0') | ||
4214 | 935 | { | ||
4215 | 936 | optarg = nextchar; | ||
4216 | 937 | optind++; | ||
4217 | 938 | } | ||
4218 | 939 | else | ||
4219 | 940 | optarg = NULL; | ||
4220 | 941 | nextchar = NULL; | ||
4221 | 942 | } | ||
4222 | 943 | else | ||
4223 | 944 | { | ||
4224 | 945 | /* This is an option that requires an argument. */ | ||
4225 | 946 | if (*nextchar != '\0') | ||
4226 | 947 | { | ||
4227 | 948 | optarg = nextchar; | ||
4228 | 949 | /* If we end this ARGV-element by taking the rest as an arg, | ||
4229 | 950 | we must advance to the next element now. */ | ||
4230 | 951 | optind++; | ||
4231 | 952 | } | ||
4232 | 953 | else if (optind == argc) | ||
4233 | 954 | { | ||
4234 | 955 | if (print_errors) | ||
4235 | 956 | { | ||
4236 | 957 | /* 1003.2 specifies the format of this message. */ | ||
4237 | 958 | fprintf (stderr, | ||
4238 | 959 | _("%s: option requires an argument -- %c\n"), | ||
4239 | 960 | argv[0], c); | ||
4240 | 961 | } | ||
4241 | 962 | optopt = c; | ||
4242 | 963 | if (optstring[0] == ':') | ||
4243 | 964 | c = ':'; | ||
4244 | 965 | else | ||
4245 | 966 | c = '?'; | ||
4246 | 967 | } | ||
4247 | 968 | else | ||
4248 | 969 | /* We already incremented `optind' once; | ||
4249 | 970 | increment it again when taking next ARGV-elt as argument. */ | ||
4250 | 971 | optarg = argv[optind++]; | ||
4251 | 972 | nextchar = NULL; | ||
4252 | 973 | } | ||
4253 | 974 | } | ||
4254 | 975 | return c; | ||
4255 | 976 | } | ||
4256 | 977 | } | ||
4257 | 978 | |||
4258 | 979 | int | ||
4259 | 980 | getopt ( int argc, char *const *argv, const char *optstring) | ||
4260 | 981 | { | ||
4261 | 982 | return _getopt_internal (argc, argv, optstring, | ||
4262 |