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