3 memcached_return_t
memcached_purge(memcached_server_st
*ptr
)
6 memcached_return_t ret
= MEMCACHED_SUCCESS
;
8 if (ptr
->root
->options
.is_purging
|| /* already purging */
9 (memcached_server_response_count(ptr
) < ptr
->root
->io_msg_watermark
&&
10 ptr
->io_bytes_sent
< ptr
->root
->io_bytes_watermark
) ||
11 (ptr
->io_bytes_sent
>= ptr
->root
->io_bytes_watermark
&&
12 memcached_server_response_count(ptr
) < 2))
14 return MEMCACHED_SUCCESS
;
17 /* memcached_io_write and memcached_response may call memcached_purge
18 so we need to be able stop any recursion.. */
19 ptr
->root
->options
.is_purging
= true;
21 WATCHPOINT_ASSERT(ptr
->fd
!= -1);
22 /* Force a flush of the buffer to ensure that we don't have the n-1 pending
23 requests buffered up.. */
24 if (memcached_io_write(ptr
, NULL
, 0, 1) == -1)
26 ptr
->root
->options
.is_purging
= true;
27 return MEMCACHED_WRITE_FAILURE
;
29 WATCHPOINT_ASSERT(ptr
->fd
!= -1);
31 uint32_t no_msg
= memcached_server_response_count(ptr
) - 1;
34 memcached_result_st result
;
35 memcached_result_st
*result_ptr
;
36 char buffer
[SMALL_STRING_LEN
];
39 * We need to increase the timeout, because we might be waiting for
40 * data to be sent from the server (the commands was in the output buffer
43 int32_t timeo
= ptr
->root
->poll_timeout
;
44 ptr
->root
->poll_timeout
= 2000;
46 result_ptr
= memcached_result_create(ptr
->root
, &result
);
47 WATCHPOINT_ASSERT(result_ptr
);
49 for (x
= 0; x
< no_msg
; x
++)
51 memcached_result_reset(result_ptr
);
52 memcached_return_t rc
= memcached_read_one_response(ptr
, buffer
,
56 * Purge doesn't care for what kind of command results that is received.
57 * The only kind of errors I care about if is I'm out of sync with the
58 * protocol or have problems reading data from the network..
60 if (rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_UNKNOWN_READ_FAILURE
)
64 memcached_io_reset(ptr
);
68 memcached_result_free(result_ptr
);
69 ptr
->root
->poll_timeout
= timeo
;
71 ptr
->root
->options
.is_purging
= false;