3 memcached_return
memcached_flush(memcached_st
*ptr
, time_t expiration
)
6 size_t send_length
, sent_length
;
8 char buffer
[MEMCACHED_DEFAULT_COMMAND_SIZE
];
10 rc
= memcached_connect(ptr
);
12 if (rc
!= MEMCACHED_SUCCESS
)
13 rc
= MEMCACHED_SOME_ERRORS
;
15 for (x
= 0; x
< ptr
->number_of_hosts
; x
++)
18 send_length
= snprintf(buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
,
19 "flush_all %llu\r\n", (unsigned long long)expiration
);
21 send_length
= snprintf(buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
,
24 if (send_length
>= MEMCACHED_DEFAULT_COMMAND_SIZE
)
25 return MEMCACHED_WRITE_FAILURE
;
27 sent_length
= write(ptr
->hosts
[x
].fd
, buffer
, send_length
);
29 if (sent_length
== -1)
31 fprintf(stderr
, "error %s: write: %m\n", __FUNCTION__
);
32 return MEMCACHED_WRITE_FAILURE
;
35 if (sent_length
!= send_length
)
37 fprintf(stderr
, "error %s: short write %d %d: %m\n",
38 __FUNCTION__
, sent_length
, send_length
);
39 return MEMCACHED_WRITE_FAILURE
;
42 rc
= memcached_response(ptr
, buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
, x
);
44 if (rc
!= MEMCACHED_SUCCESS
)
45 rc
= MEMCACHED_SOME_ERRORS
;