8538aaa0cc753f7e6c963d542d140b1f8cb32a2a
[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, sent_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_SUCCESS)
14 rc= MEMCACHED_SOME_ERRORS;
15
16 memset(buffer, 0, MEMCACHED_DEFAULT_COMMAND_SIZE);
17 for (x= 0; x < ptr->number_of_hosts; x++)
18 {
19 if (expiration)
20 send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
21 "flush_all %llu\r\n", (unsigned long long)expiration);
22 else
23 send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
24 "flush_all\r\n");
25
26 if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
27 return MEMCACHED_WRITE_FAILURE;
28
29 sent_length= memcached_io_write(ptr, x, buffer, send_length, 1);
30
31 if (sent_length == -1 || sent_length != send_length)
32 return MEMCACHED_WRITE_FAILURE;
33
34 rc= memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, x);
35
36 if (rc != MEMCACHED_SUCCESS)
37 rc= MEMCACHED_SOME_ERRORS;
38 }
39
40 LIBMEMCACHED_MEMCACHED_FLUSH_END();
41 return rc;
42 }