X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=example%2Fmemcached_light.c;h=743f2d1c9ff2ca9f5dde12cb19da680c0785b9a8;hb=d292bcb63666dad0277e9658916514f64b7200b0;hp=b373a12f7fe7050945187142e8164aa75ef90b5a;hpb=90f605b1e1472f5c4400f862e4236be7670cae13;p=m6w6%2Flibmemcached diff --git a/example/memcached_light.c b/example/memcached_light.c index b373a12f..743f2d1c 100644 --- a/example/memcached_light.c +++ b/example/memcached_light.c @@ -31,7 +31,7 @@ #include #include -#include "common.h" +#include #include "storage.h" extern struct memcached_binary_protocol_callback_st interface_v0_impl; @@ -40,6 +40,7 @@ extern struct memcached_binary_protocol_callback_st interface_v1_impl; static int server_sockets[1024]; static int num_server_sockets= 0; static void* socket_userdata_map[1024]; +static bool verbose= false; /** * Create a socket and bind it to a specific port number @@ -153,25 +154,33 @@ static const char* comcode2str(uint8_t cmd) /** * Print out the command we are about to execute */ -static void pre_execute(const void *cookie, protocol_binary_request_header *header) +static void pre_execute(const void *cookie __attribute__((unused)), + protocol_binary_request_header *header __attribute__((unused))) { - const char *cmd= comcode2str(header->request.opcode); - if (cmd != NULL) - fprintf(stderr, "pre_execute from %p: %s\n", cookie, cmd); - else - fprintf(stderr, "pre_execute from %p: 0x%02x\n", cookie, header->request.opcode); + if (verbose) + { + const char *cmd= comcode2str(header->request.opcode); + if (cmd != NULL) + fprintf(stderr, "pre_execute from %p: %s\n", cookie, cmd); + else + fprintf(stderr, "pre_execute from %p: 0x%02x\n", cookie, header->request.opcode); + } } /** * Print out the command we just executed */ -static void post_execute(const void *cookie, protocol_binary_request_header *header) +static void post_execute(const void *cookie __attribute__((unused)), + protocol_binary_request_header *header __attribute__((unused))) { - const char *cmd= comcode2str(header->request.opcode); - if (cmd != NULL) - fprintf(stderr, "post_execute from %p: %s\n", cookie, cmd); - else - fprintf(stderr, "post_execute from %p: 0x%02x\n", cookie, header->request.opcode); + if (verbose) + { + const char *cmd= comcode2str(header->request.opcode); + if (cmd != NULL) + fprintf(stderr, "post_execute from %p: %s\n", cookie, cmd); + else + fprintf(stderr, "post_execute from %p: 0x%02x\n", cookie, header->request.opcode); + } } /** @@ -211,7 +220,7 @@ int main(int argc, char **argv) int cmd; struct memcached_binary_protocol_callback_st *interface= &interface_v0_impl; - while ((cmd= getopt(argc, argv, "1p:?")) != EOF) + while ((cmd= getopt(argc, argv, "v1p:?")) != EOF) { switch (cmd) { case '1': @@ -221,13 +230,22 @@ int main(int argc, char **argv) port_specified= true; (void)server_socket(optarg); break; + case 'v': + verbose= true; + break; case '?': /* FALLTHROUGH */ default: - (void)fprintf(stderr, "Usage: %s [-p port]\n", argv[0]); + (void)fprintf(stderr, "Usage: %s [-p port] [-v] [-1]\n", argv[0]); return 1; } } + if (!initialize_storage()) + { + /* Error message already printed */ + return 1; + } + if (!port_specified) (void)server_socket("9999");