2 +--------------------------------------------------------------------+
3 | libmemcached - C/C++ Client Library for memcached |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted under the terms of the BSD license. |
7 | You should have received a copy of the license in a bundled file |
8 | named LICENSE; in case you did not receive a copy you can review |
9 | the terms online at: https://opensource.org/licenses/BSD-3-Clause |
10 +--------------------------------------------------------------------+
11 | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ |
12 | Copyright (c) 2020 Michael Wallner <mike@php.net> |
13 +--------------------------------------------------------------------+
16 #include "libmemcached/common.h"
18 #define memcached_set_purging(__object, __value) ((__object)->state.is_purging = (__value))
24 memcached_set_purging(_memc
, true);
28 memcached_set_purging(_memc
, false);
37 PollTimeout(Memcached
*arg
, int32_t ms
= 50)
38 : _timeout(arg
->poll_timeout
)
39 , _origin(arg
->poll_timeout
) {
52 bool memcached_purge(memcached_instance_st
*ptr
) {
53 Memcached
*root
= (Memcached
*) ptr
->root
;
55 if (memcached_is_purging(ptr
->root
) || /* already purging */
56 (memcached_server_response_count(ptr
) < ptr
->root
->io_msg_watermark
57 && ptr
->io_bytes_sent
< ptr
->root
->io_bytes_watermark
)
58 || (ptr
->io_bytes_sent
>= ptr
->root
->io_bytes_watermark
59 && memcached_server_response_count(ptr
) < 2))
65 memcached_io_write and memcached_response may call memcached_purge
66 so we need to be able stop any recursion..
68 Purge
set_purge(root
);
70 WATCHPOINT_ASSERT(ptr
->fd
!= INVALID_SOCKET
);
72 Force a flush of the buffer to ensure that we don't have the n-1 pending
73 requests buffered up..
75 if (memcached_io_write(ptr
) == false) {
76 memcached_io_reset(ptr
);
77 memcached_set_error(*ptr
, MEMCACHED_WRITE_FAILURE
, MEMCACHED_AT
);
80 WATCHPOINT_ASSERT(ptr
->fd
!= INVALID_SOCKET
);
82 bool is_successful
= true;
83 uint32_t no_msg
= memcached_server_response_count(ptr
);
85 memcached_result_st result
;
88 * We need to increase the timeout, because we might be waiting for
89 * data to be sent from the server (the commands was in the output buffer
92 PollTimeout
poll_timeout(ptr
->root
);
94 memcached_result_st
*result_ptr
= memcached_result_create(root
, &result
);
97 for (uint32_t x
= 0; x
< no_msg
- 1; x
++) {
98 memcached_result_reset(result_ptr
);
99 memcached_return_t rc
= memcached_read_one_response(ptr
, result_ptr
);
101 * Purge doesn't care for what kind of command results that is received.
102 * The only kind of errors I care about if is I'm out of sync with the
103 * protocol or have problems reading data from the network..
105 if (rc
== MEMCACHED_PROTOCOL_ERROR
or rc
== MEMCACHED_UNKNOWN_READ_FAILURE
106 or rc
== MEMCACHED_READ_FAILURE
)
108 WATCHPOINT_ERROR(rc
);
109 is_successful
= false;
111 if (rc
== MEMCACHED_TIMEOUT
) {
115 if (ptr
->root
->callbacks
!= NULL
) {
116 memcached_callback_st cb
= *ptr
->root
->callbacks
;
117 if (memcached_success(rc
)) {
118 for (uint32_t y
= 0; y
< cb
.number_of_callback
; y
++) {
119 if (memcached_fatal((*cb
.callback
[y
])(ptr
->root
, result_ptr
, cb
.context
))) {
127 memcached_result_free(result_ptr
);
130 return is_successful
;