4 #include "memcached_io.h"
6 void memcached_purge(memcached_server_st
*ptr
)
9 size_t buffer_length
= sizeof(buffer
);
10 memcached_result_st result
;
12 if (ptr
->root
->purging
|| /* already purging */
13 (memcached_server_response_count(ptr
) < ptr
->root
->io_msg_watermark
&&
14 ptr
->io_bytes_sent
< ptr
->root
->io_bytes_watermark
) ||
15 (ptr
->io_bytes_sent
> ptr
->root
->io_bytes_watermark
&&
16 memcached_server_response_count(ptr
) < 10)) {
20 /* memcached_io_write and memcached_response may call memcached_purge
21 so we need to be able stop any recursion.. */
22 ptr
->root
->purging
= 1;
24 /* Force a flush of the buffer to ensure that we don't have the n-1 pending
25 requests buffered up.. */
26 memcached_io_write(ptr
, NULL
, 0, 1);
28 /* we have already incremented the response counter, and memcached_response
29 will read out all messages.. To avoid memcached_response to wait forever
30 for a response to a command I have in my buffer, let's decrement the
31 response counter :) */
32 memcached_server_response_decrement(ptr
);
34 /* memcached_response may call memcached_io_read, but let's use a short
35 timeout if there is no data yet */
36 int32_t timeout
= ptr
->root
->poll_timeout
;
37 ptr
->root
->poll_timeout
= 1;
38 memcached_response(ptr
, buffer
, sizeof(buffer
), &result
);
39 ptr
->root
->poll_timeout
= timeout
;
40 memcached_server_response_increment(ptr
);
41 ptr
->root
->purging
= 0;