author | Tero Marttila <terom@fixme.fi> |
Thu, 28 Aug 2008 03:12:11 +0300 | |
changeset 46 | 8a832c0e01ee |
parent 44 | 03a7e064f833 |
child 48 | 1c67f512779b |
permissions | -rw-r--r-- |
38
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1 |
|
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
2 |
#include <event2/event.h> |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
3 |
#include <event2/event_compat.h> |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
4 |
#include <event2/event_struct.h> |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
5 |
|
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
6 |
#include "memcache.h" |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
7 |
#include "config.h" |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
8 |
#include "common.h" |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
9 |
|
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
10 |
static struct memcache *mc; |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
11 |
static struct config_endpoint server_endpoint; |
46
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
12 |
static char *data_1 = "rei4quohV8Oocio1ua0co8ni4Ae1re4houcheixahchoh3ioghie0aShooShoh6Ahboequ9eiX5eashuu6Chu1quo" |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
13 |
"o0suph7cheiyai1ea0ooh7Aevoo4feihubupohDeephahwee2Ooz7chiediec7neit7keTh6xuheash8chaeKa5vi" |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
14 |
"ekooqu7ooj6Eezooroi6Nequ9ca2yi6iSoigh3loowaey9eiphaphaiJ0souy7wohpa9eXo5Ahu2sa"; |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
15 |
static char *data_2 = "iefaek7ighi5UpueThageish5ieshohyeil1raiceerahjahng5ui7vuzie9quu4dai5ar2aiXi5ieth4looweigi" |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
16 |
"e3fo5ieri1queengaiphuaghaic1xahvoo9joo6baiNaig8puCootheowah4moocohDoiquoh3quieka5ao3aeNg9" |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
17 |
"Aimei1soangu4Duch5pho5buu2ohzaich4chahz9iTh3Pei4beep1ongie6au1aafoosh2vierei5E"; |
38
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
18 |
|
46
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
19 |
void _memcache_cb (struct memcache_req *req, void *arg) { |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
20 |
char *key = arg; |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
21 |
const struct memcache_obj *obj; |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
22 |
const struct memcache_buf *buf; |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
23 |
|
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
24 |
INFO("[%s]: cmd=%15s state=%15s reply=%15s", key, |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
25 |
memcache_command_str(memcache_req_cmd(req)), |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
26 |
memcache_state_str(memcache_req_state(req)), |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
27 |
memcache_reply_str(memcache_req_reply(req)) |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
28 |
); |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
29 |
|
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
30 |
if ((obj = memcache_req_obj(req))) |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
31 |
INFO("\tobj: flags=0x%04X exptime=%9zu bytes=%6zu cas=%llu", obj->flags, obj->exptime, obj->bytes, obj->cas); |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
32 |
|
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
33 |
if ((buf = memcache_req_buf(req))) |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
34 |
INFO("\tbuf: data=%p len=%6zu offset=%6zu", buf->data, buf->len, buf->offset); |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
35 |
|
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
36 |
INFO("%s", ""); |
38
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
37 |
} |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
38 |
|
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
39 |
void begin_test () { |
46
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
40 |
struct memcache_key key_1, key_2; |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
41 |
struct memcache_obj obj_1, obj_2; |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
42 |
struct memcache_buf buf_1, buf_2; |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
43 |
|
38
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
44 |
if ((mc = memcache_alloc(&_memcache_cb)) == NULL) |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
45 |
ERROR("memcache_alloc"); |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
46 |
|
44
03a7e064f833
stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents:
38
diff
changeset
|
47 |
// fix up the endpoint |
38
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
48 |
endpoint_init(&server_endpoint, 11211); |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
49 |
|
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
50 |
if (endpoint_parse(&server_endpoint, "localhost")) |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
51 |
ERROR("config_endpoint_parse"); |
44
03a7e064f833
stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents:
38
diff
changeset
|
52 |
|
03a7e064f833
stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents:
38
diff
changeset
|
53 |
// add the server |
38
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
54 |
if (memcache_add_server(mc, &server_endpoint, 1)) |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
55 |
ERROR("memcache_add_server"); |
44
03a7e064f833
stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents:
38
diff
changeset
|
56 |
|
03a7e064f833
stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents:
38
diff
changeset
|
57 |
// add a request or two |
46
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
58 |
key_1.buf = "memcache_test_k1"; |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
59 |
key_2.buf = "memcache_test_k2"; |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
60 |
key_1.len = key_2.len = 0; |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
61 |
|
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
62 |
obj_1.flags = 0x1A; |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
63 |
obj_2.flags = 0x2B; |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
64 |
|
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
65 |
obj_1.exptime = 0; |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
66 |
obj_2.exptime = 3600; |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
67 |
|
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
68 |
obj_1.bytes = strlen(data_1); |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
69 |
obj_2.bytes = strlen(data_2); |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
70 |
|
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
71 |
buf_1.data = data_1; |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
72 |
buf_1.len = strlen(data_1); |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
73 |
buf_1.offset = buf_1.len; |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
74 |
|
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
75 |
buf_2.data = data_2; |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
76 |
buf_2.len = strlen(data_2); |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
77 |
buf_2.offset = buf_2.len; |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
78 |
|
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
79 |
if (memcache_store(mc, MEMCACHE_CMD_STORE_SET, &key_1, &obj_1, &buf_1, key_1.buf)) |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
80 |
ERROR("memcache_store: key_1"); |
38
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
81 |
|
46
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
82 |
if (memcache_store(mc, MEMCACHE_CMD_STORE_ADD, &key_2, &obj_2, &buf_2, key_2.buf)) |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
83 |
ERROR("memcache_store: key_2"); |
44
03a7e064f833
stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents:
38
diff
changeset
|
84 |
|
46
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
85 |
if (memcache_fetch(mc, &key_1, key_1.buf)) |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
86 |
ERROR("memcache_fetch: key_1"); |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
87 |
|
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
88 |
if (memcache_fetch(mc, &key_2, key_2.buf)) |
8a832c0e01ee
bugfixed, enum->string mappings, test does requests
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
89 |
ERROR("memcache_fetch: key_2"); |
38
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
90 |
|
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
91 |
error: |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
92 |
return; |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
93 |
} |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
94 |
|
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
95 |
int main (int argc, char **argv) { |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
96 |
// libevent init |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
97 |
struct event_base *ev_base = event_init(); |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
98 |
|
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
99 |
if (!ev_base) |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
100 |
FATAL("event_init"); |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
101 |
|
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
102 |
begin_test(); |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
103 |
|
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
104 |
// run the libevent mainloop |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
105 |
if (event_base_dispatch(ev_base)) |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
106 |
WARNING("event_dispatch"); |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
107 |
|
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
108 |
INFO("SHUTDOWN"); |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
109 |
|
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
110 |
// clean up |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
111 |
event_base_free(ev_base); |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
112 |
|
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
113 |
// successfull exit |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
114 |
return 0; |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
115 |
} |