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