3 memcached_return_t
memcached_purge(memcached_server_instance_st
*ptr
)
6 memcached_return_t ret
= MEMCACHED_SUCCESS
;
7 memcached_st
*root
= (memcached_st
*)ptr
->root
;
9 if (memcached_is_purging(ptr
->root
) || /* already purging */
10 (memcached_server_response_count(ptr
) < ptr
->root
->io_msg_watermark
&&
11 ptr
->io_bytes_sent
< ptr
->root
->io_bytes_watermark
) ||
12 (ptr
->io_bytes_sent
>= ptr
->root
->io_bytes_watermark
&&
13 memcached_server_response_count(ptr
) < 2))
15 return MEMCACHED_SUCCESS
;
18 /* memcached_io_write and memcached_response may call memcached_purge
19 so we need to be able stop any recursion.. */
20 memcached_set_purging(root
, true);
22 WATCHPOINT_ASSERT(ptr
->fd
!= -1);
23 /* Force a flush of the buffer to ensure that we don't have the n-1 pending
24 requests buffered up.. */
25 if (memcached_io_write(ptr
, NULL
, 0, 1) == -1)
27 memcached_set_purging(root
, true);
29 return MEMCACHED_WRITE_FAILURE
;
31 WATCHPOINT_ASSERT(ptr
->fd
!= -1);
33 uint32_t no_msg
= memcached_server_response_count(ptr
) - 1;
36 memcached_result_st result
;
37 memcached_result_st
*result_ptr
;
38 char buffer
[SMALL_STRING_LEN
];
41 * We need to increase the timeout, because we might be waiting for
42 * data to be sent from the server (the commands was in the output buffer
45 const int32_t timeo
= ptr
->root
->poll_timeout
;
46 root
->poll_timeout
= 2000;
48 result_ptr
= memcached_result_create(root
, &result
);
49 WATCHPOINT_ASSERT(result_ptr
);
51 for (x
= 0; x
< no_msg
; x
++)
53 memcached_result_reset(result_ptr
);
54 memcached_return_t rc
= memcached_read_one_response(ptr
, buffer
,
58 * Purge doesn't care for what kind of command results that is received.
59 * The only kind of errors I care about if is I'm out of sync with the
60 * protocol or have problems reading data from the network..
62 if (rc
== MEMCACHED_PROTOCOL_ERROR
|| rc
== MEMCACHED_UNKNOWN_READ_FAILURE
)
66 memcached_io_reset(ptr
);
69 if (ptr
->root
->callbacks
!= NULL
)
71 memcached_callback_st cb
= *ptr
->root
->callbacks
;
72 if (rc
== MEMCACHED_SUCCESS
)
74 for (uint32_t y
= 0; y
< cb
.number_of_callback
; y
++)
76 rc
= (*cb
.callback
[y
])(ptr
->root
, result_ptr
, cb
.context
);
77 if (rc
!= MEMCACHED_SUCCESS
)
84 memcached_result_free(result_ptr
);
85 root
->poll_timeout
= timeo
;
87 memcached_set_purging(root
, false);