author | Tero Marttila <terom@fixme.fi> |
Thu, 28 Aug 2008 00:29:39 +0300 | |
changeset 43 | e5b714190dee |
parent 38 | 9894df13b779 |
child 44 | 03a7e064f833 |
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; |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
12 |
|
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
13 |
int _memcache_cb (struct memcache_req *req, void *arg) { |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
14 |
return 0; |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
15 |
} |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
16 |
|
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
17 |
void begin_test () { |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
18 |
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
|
19 |
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
|
20 |
|
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
21 |
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
|
22 |
|
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
23 |
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
|
24 |
ERROR("config_endpoint_parse"); |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
25 |
|
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
26 |
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
|
27 |
ERROR("memcache_add_server"); |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
28 |
|
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
29 |
// XXX: we should have a connect() running now |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
30 |
|
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
31 |
error: |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
32 |
return; |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
33 |
} |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
34 |
|
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
35 |
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
|
36 |
// libevent init |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
37 |
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
|
38 |
|
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
39 |
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
|
40 |
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
|
41 |
|
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
42 |
begin_test(); |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
43 |
|
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
44 |
// 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
|
45 |
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
|
46 |
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
|
47 |
|
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
48 |
INFO("SHUTDOWN"); |
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 |
// clean up |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
51 |
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
|
52 |
|
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
53 |
// successfull exit |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
54 |
return 0; |
9894df13b779
added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
55 |
} |