8c51cdf1f85f8e9e44d3fa7a67fb673aac42aa52
[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;
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 for (x= 0; x < ptr->number_of_hosts; x++)
16 {
17 if (expiration)
18 send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
19 "flush_all %llu\r\n", (unsigned long long)expiration);
20 else
21 send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
22 "flush_all\r\n");
23 if ((write(ptr->hosts[x].fd, buffer, send_length) == -1))
24 return MEMCACHED_WRITE_FAILURE;
25
26 rc= memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, x);
27
28 if (rc != MEMCACHED_SUCCESS)
29 rc= MEMCACHED_SOME_ERRORS;
30 }
31
32 return rc;
33 }