Added tag 0.2 for changeset 72b98d8bc30e
[awesomized/libmemcached] / lib / memcached_flush.c
1 #include <memcached.h>
2
3 memcached_return memcached_flush(memcached_st *ptr, time_t expiration)
4 {
5 unsigned int x;
6 size_t send_length, sent_length;
7 memcached_return rc;
8 char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
9
10 rc= memcached_connect(ptr);
11
12 if (rc != MEMCACHED_SUCCESS)
13 rc= MEMCACHED_SOME_ERRORS;
14
15 memset(buffer, 0, MEMCACHED_DEFAULT_COMMAND_SIZE);
16 for (x= 0; x < ptr->number_of_hosts; x++)
17 {
18 if (expiration)
19 send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
20 "flush_all %llu\r\n", (unsigned long long)expiration);
21 else
22 send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
23 "flush_all\r\n");
24
25 if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
26 return MEMCACHED_WRITE_FAILURE;
27
28 sent_length= write(ptr->hosts[x].fd, buffer, send_length);
29
30 if (sent_length == -1 || sent_length != send_length)
31 return MEMCACHED_WRITE_FAILURE;
32
33 rc= memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, x);
34
35 if (rc != MEMCACHED_SUCCESS)
36 rc= MEMCACHED_SOME_ERRORS;
37 }
38
39 return rc;
40 }