4 #include "memcached_io.h"
6 memcached_return
memcached_purge(memcached_server_st
*ptr
)
11 memcached_result_st result
;
12 memcached_result_st
*result_ptr
;
14 if (ptr
->root
->purging
|| /* already purging */
15 (memcached_server_response_count(ptr
) < ptr
->root
->io_msg_watermark
&&
16 ptr
->io_bytes_sent
< ptr
->root
->io_bytes_watermark
) ||
17 (ptr
->io_bytes_sent
> ptr
->root
->io_bytes_watermark
&&
18 memcached_server_response_count(ptr
) < 10))
20 return MEMCACHED_SUCCESS
;
23 /* memcached_io_write and memcached_response may call memcached_purge
24 so we need to be able stop any recursion.. */
25 ptr
->root
->purging
= 1;
27 WATCHPOINT_ASSERT(ptr
->fd
!= -1);
28 /* Force a flush of the buffer to ensure that we don't have the n-1 pending
29 requests buffered up.. */
30 if (memcached_io_write(ptr
, NULL
, 0, 1) == -1)
31 return MEMCACHED_FAILURE
;
32 WATCHPOINT_ASSERT(ptr
->fd
!= -1);
34 /* we have already incremented the response counter, and memcached_response
35 will read out all messages.. To avoid memcached_response to wait forever
36 for a response to a command I have in my buffer, let's decrement the
37 response counter :) */
38 memcached_server_response_decrement(ptr
);
40 /* memcached_response may call memcached_io_read, but let's use a short
41 timeout if there is no data yet */
42 timeout
= ptr
->root
->poll_timeout
;
43 ptr
->root
->poll_timeout
= 1;
44 result_ptr
= memcached_result_create(ptr
->root
, &result
);
46 if (result_ptr
== NULL
)
47 return MEMCACHED_FAILURE
;
49 WATCHPOINT_ASSERT(ptr
->fd
!= -1);
50 rc
= memcached_response(ptr
, buffer
, sizeof(buffer
), &result
);
52 WATCHPOINT_ASSERT(ptr
->fd
!= -1);
53 ptr
->root
->poll_timeout
= timeout
;
54 memcached_server_response_increment(ptr
);
55 ptr
->root
->purging
= 0;
57 memcached_result_free(&result
);