Removed more then a handfull of memset() calls.
[awesomized/libmemcached] / lib / memcached_flush.c
1 #include "common.h"
2
3 memcached_return memcached_flush(memcached_st *ptr, time_t expiration)
4 {
5 unsigned int x;
6 size_t send_length;
7 memcached_return rc;
8 char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
9 LIBMEMCACHED_MEMCACHED_FLUSH_START();
10
11 rc= memcached_connect(ptr, 0);
12
13 if (rc == MEMCACHED_NO_SERVERS)
14 return rc;
15
16 if (rc != MEMCACHED_SUCCESS)
17 rc= MEMCACHED_SOME_ERRORS;
18
19 for (x= 0; x < ptr->number_of_hosts; x++)
20 {
21 if (expiration)
22 send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
23 "flush_all %llu\r\n", (unsigned long long)expiration);
24 else
25 send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
26 "flush_all\r\n");
27
28 if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
29 return MEMCACHED_WRITE_FAILURE;
30
31 rc= memcached_do(ptr, x, buffer, send_length, 1);
32 if (rc != MEMCACHED_SUCCESS)
33 goto error;
34
35 rc= memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, x);
36
37 if (rc != MEMCACHED_SUCCESS)
38 rc= MEMCACHED_SOME_ERRORS;
39 }
40
41 error:
42 LIBMEMCACHED_MEMCACHED_FLUSH_END();
43 return rc;
44 }