X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=example%2Fmemcached_light.c;h=86087c5a9b7010140a4de95a0ade3b1e2c5fb72f;hb=7ed5aa2c6673ab92559e52a29e83c0a44f3beebc;hp=cac0cf9a9112dd6896c23c6a872b4415f2a1f712;hpb=2fc27acf7d450bbae9e90467f5931dece550d3fb;p=m6w6%2Flibmemcached diff --git a/example/memcached_light.c b/example/memcached_light.c index cac0cf9a..86087c5a 100644 --- a/example/memcached_light.c +++ b/example/memcached_light.c @@ -40,9 +40,10 @@ #include #include #include "storage.h" +#include "memcached_light.h" -extern struct memcached_binary_protocol_callback_st interface_v0_impl; -extern struct memcached_binary_protocol_callback_st interface_v1_impl; +extern memcached_binary_protocol_callback_st interface_v0_impl; +extern memcached_binary_protocol_callback_st interface_v1_impl; static int server_sockets[1024]; static int num_server_sockets= 0; @@ -227,7 +228,13 @@ int main(int argc, char **argv) { bool port_specified= false; int cmd; - struct memcached_binary_protocol_callback_st *interface= &interface_v0_impl; + memcached_binary_protocol_callback_st *interface= &interface_v0_impl; + + /* + * We need to initialize the handlers manually due to a bug in the + * warnings generated by struct initialization in gcc (all the way up to 4.4) + */ + initialize_iterface_v0_handler(); while ((cmd= getopt(argc, argv, "v1p:?")) != EOF) { @@ -364,17 +371,16 @@ static void work(void) assert(c != NULL); fds[max_poll].events= 0; - switch (memcached_protocol_client_work(c)) - { - case WRITE_EVENT: - case READ_WRITE_EVENT: + memcached_protocol_event_t events= memcached_protocol_client_work(c); + if (events & MEMCACHED_PROTOCOL_WRITE_EVENT) fds[max_poll].events= POLLOUT; - /* FALLTHROUGH */ - case READ_EVENT: - fds[max_poll].events |= POLLIN; - break; - case ERROR_EVENT: - default: /* ERROR or unknown state.. close */ + + if (events & MEMCACHED_PROTOCOL_READ_EVENT) + fds[max_poll].events= POLLIN; + + if (!(events & MEMCACHED_PROTOCOL_PAUSE_EVENT || + fds[max_poll].events != 0)) + { memcached_protocol_client_destroy(c); close(fds[x].fd); fds[x].events= 0;