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);
27 ~Purge() { memcached_set_purging(_memc
, false); }
35 PollTimeout(Memcached
*arg
, int32_t ms
= 50)
36 : _timeout(arg
->poll_timeout
)
37 , _origin(arg
->poll_timeout
) {
41 ~PollTimeout() { _origin
= _timeout
; }
48 bool memcached_purge(memcached_instance_st
*ptr
) {
49 Memcached
*root
= (Memcached
*) ptr
->root
;
51 if (memcached_is_purging(ptr
->root
) || /* already purging */
52 (memcached_server_response_count(ptr
) < ptr
->root
->io_msg_watermark
53 && ptr
->io_bytes_sent
< ptr
->root
->io_bytes_watermark
)
54 || (ptr
->io_bytes_sent
>= ptr
->root
->io_bytes_watermark
55 && memcached_server_response_count(ptr
) < 2))
61 memcached_io_write and memcached_response may call memcached_purge
62 so we need to be able stop any recursion..
64 Purge
set_purge(root
);
66 WATCHPOINT_ASSERT(ptr
->fd
!= INVALID_SOCKET
);
68 Force a flush of the buffer to ensure that we don't have the n-1 pending
69 requests buffered up..
71 if (memcached_io_write(ptr
) == false) {
72 memcached_io_reset(ptr
);
73 memcached_set_error(*ptr
, MEMCACHED_WRITE_FAILURE
, MEMCACHED_AT
);
76 WATCHPOINT_ASSERT(ptr
->fd
!= INVALID_SOCKET
);
78 bool is_successful
= true;
79 uint32_t no_msg
= memcached_server_response_count(ptr
);
81 memcached_result_st result
;
84 * We need to increase the timeout, because we might be waiting for
85 * data to be sent from the server (the commands was in the output buffer
88 PollTimeout
poll_timeout(ptr
->root
);
90 memcached_result_st
*result_ptr
= memcached_result_create(root
, &result
);
93 for (uint32_t x
= 0; x
< no_msg
- 1; x
++) {
94 memcached_result_reset(result_ptr
);
95 memcached_return_t rc
= memcached_read_one_response(ptr
, result_ptr
);
97 * Purge doesn't care for what kind of command results that is received.
98 * The only kind of errors I care about if is I'm out of sync with the
99 * protocol or have problems reading data from the network..
101 if (rc
== MEMCACHED_PROTOCOL_ERROR
or rc
== MEMCACHED_UNKNOWN_READ_FAILURE
102 or rc
== MEMCACHED_READ_FAILURE
)
104 WATCHPOINT_ERROR(rc
);
105 is_successful
= false;
107 if (rc
== MEMCACHED_TIMEOUT
) {
111 if (ptr
->root
->callbacks
!= NULL
) {
112 memcached_callback_st cb
= *ptr
->root
->callbacks
;
113 if (memcached_success(rc
)) {
114 for (uint32_t y
= 0; y
< cb
.number_of_callback
; y
++) {
115 if (memcached_fatal((*cb
.callback
[y
])(ptr
->root
, result_ptr
, cb
.context
))) {
123 memcached_result_free(result_ptr
);
126 return is_successful
;