Concurrent memcached_verbosity().
[awesomized/libmemcached] / libmemcached / verbosity.c
1 #include "common.h"
2
3 struct context_st
4 {
5 size_t length;
6 const char *buffer;
7 };
8
9 static memcached_return_t _set_verbosity(const memcached_st *ptr __attribute__((unused)),
10 const memcached_server_st *server,
11 void *context)
12 {
13 memcached_return_t rc;
14 memcached_st local_memc;
15 memcached_st *memc_ptr;
16 char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
17
18 struct context_st *execute= (struct context_st *)context;
19
20 memc_ptr= memcached_create(&local_memc);
21
22 rc= memcached_server_add(memc_ptr, memcached_server_name(server), memcached_server_port(server));
23
24 if (rc == MEMCACHED_SUCCESS)
25 {
26 memcached_server_write_instance_st instance=
27 memcached_server_instance_fetch(memc_ptr, 0);
28
29 rc= memcached_do(instance, execute->buffer, execute->length, true);
30
31 if (rc == MEMCACHED_SUCCESS)
32 {
33 rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
34 }
35 }
36
37 memcached_free(memc_ptr);
38
39 return rc;
40 }
41
42 memcached_return_t memcached_verbosity(memcached_st *ptr, uint32_t verbosity)
43 {
44 size_t send_length;
45 memcached_server_fn callbacks[1];
46
47 char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
48
49 send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
50 "verbosity %u\r\n", verbosity);
51 unlikely (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
52 return MEMCACHED_WRITE_FAILURE;
53
54 struct context_st context = { .length= send_length, .buffer= buffer };
55
56 callbacks[0]= _set_verbosity;
57
58 return memcached_server_cursor(ptr, callbacks, &context, 1);
59 }