X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=src%2Flibmemcached%2Fquit.cc;h=2f1ed81526edeed84e240313b1d9f21c809494c3;hb=c8c52cf24f50f55454ba36250fd54b848d6d9ce2;hp=ad16d2c1aa334b5a0c0efd5c5c129385e8aa9650;hpb=5bb6f975322d3da0caf082b8d890132194d0a4ea;p=awesomized%2Flibmemcached diff --git a/src/libmemcached/quit.cc b/src/libmemcached/quit.cc index ad16d2c1..2f1ed815 100644 --- a/src/libmemcached/quit.cc +++ b/src/libmemcached/quit.cc @@ -1,101 +1,67 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Libmemcached library - * - * Copyright (C) 2011 Data Differential, http://datadifferential.com/ - * Copyright (C) 2010 Brian Aker All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ +/* + +--------------------------------------------------------------------+ + | libmemcached-awesome - C/C++ Client Library for memcached | + +--------------------------------------------------------------------+ + | Redistribution and use in source and binary forms, with or without | + | modification, are permitted under the terms of the BSD license. | + | You should have received a copy of the license in a bundled file | + | named LICENSE; in case you did not receive a copy you can review | + | the terms online at: https://opensource.org/licenses/BSD-3-Clause | + +--------------------------------------------------------------------+ + | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ | + | Copyright (c) 2020-2021 Michael Wallner https://awesome.co/ | + +--------------------------------------------------------------------+ +*/ #include "libmemcached/common.h" namespace { - memcached_return_t send_quit_message(memcached_instance_st* instance) - { - memcached_return_t rc; - if (instance->root->flags.binary_protocol) - { - protocol_binary_request_quit request= {}; // = {.bytes= {0}}; +memcached_return_t send_quit_message(memcached_instance_st *instance) { + memcached_return_t rc; + if (instance->root->flags.binary_protocol) { + protocol_binary_request_quit request = {}; // = {.bytes= {0}}; - initialize_binary_request(instance, request.message.header); + initialize_binary_request(instance, request.message.header); - request.message.header.request.opcode = PROTOCOL_BINARY_CMD_QUIT; - request.message.header.request.datatype = PROTOCOL_BINARY_RAW_BYTES; + request.message.header.request.opcode = PROTOCOL_BINARY_CMD_QUIT; + request.message.header.request.datatype = PROTOCOL_BINARY_RAW_BYTES; - libmemcached_io_vector_st vector[]= - { - { request.bytes, sizeof(request.bytes) } - }; + libmemcached_io_vector_st vector[] = {{request.bytes, sizeof(request.bytes)}}; - rc= memcached_vdo(instance, vector, 1, true); - } - else - { - libmemcached_io_vector_st vector[]= - { - { memcached_literal_param("quit\r\n") } - }; + rc = memcached_vdo(instance, vector, 1, true); + } else { + libmemcached_io_vector_st vector[] = {{memcached_literal_param("quit\r\n")}}; - rc= memcached_vdo(instance, vector, 1, true); - } - - return rc; + rc = memcached_vdo(instance, vector, 1, true); } - void drain_instance(memcached_instance_st* instance) - { - /* read until socket is closed, or there is an error - * closing the socket before all data is read - * results in server throwing away all data which is - * not read - * - * In .40 we began to only do this if we had been doing buffered - * requests of had replication enabled. - */ - if (instance->root->flags.buffer_requests or instance->root->number_of_replicas) - { - memcached_io_slurp(instance); - } + return rc; +} - /* - * memcached_io_read may call memcached_quit_server with io_death if - * it encounters problems, but we don't care about those occurences. - * The intention of that loop is to drain the data sent from the - * server to ensure that the server processed all of the data we - * sent to the server. - */ - instance->server_failure_counter= 0; - instance->server_timeout_counter= 0; +void drain_instance(memcached_instance_st *instance) { + /* read until socket is closed, or there is an error + * closing the socket before all data is read + * results in server throwing away all data which is + * not read + * + * In .40 we began to only do this if we had been doing buffered + * requests of had replication enabled. + */ + if (instance->root->flags.buffer_requests or instance->root->number_of_replicas) { + memcached_io_slurp(instance); } + + /* + * memcached_io_read may call memcached_quit_server with io_death if + * it encounters problems, but we don't care about those occurences. + * The intention of that loop is to drain the data sent from the + * server to ensure that the server processed all of the data we + * sent to the server. + */ + instance->server_failure_counter = 0; + instance->server_timeout_counter = 0; } +} // namespace /* This closes all connections (forces flush of input as well). @@ -106,11 +72,10 @@ namespace { will force data to be completed. */ -void memcached_quit_server(memcached_instance_st* instance, bool io_death) -{ - if (instance->valid()) - { - if (io_death == false and memcached_is_udp(instance->root) == false and instance->is_shutting_down() == false) +void memcached_quit_server(memcached_instance_st *instance, bool io_death) { + if (instance->valid()) { + if (io_death == false and memcached_is_udp(instance->root) == false + and instance->is_shutting_down() == false) { send_quit_message(instance); @@ -121,8 +86,7 @@ void memcached_quit_server(memcached_instance_st* instance, bool io_death) instance->close_socket(); - if (io_death and memcached_is_udp(instance->root)) - { + if (io_death and memcached_is_udp(instance->root)) { /* If using UDP, we should stop using the server briefly on every IO failure. If using TCP, it may be that the connection went down a @@ -134,22 +98,18 @@ void memcached_quit_server(memcached_instance_st* instance, bool io_death) } } -void send_quit(Memcached *memc) -{ - for (uint32_t x= 0; x < memcached_server_count(memc); x++) - { - memcached_instance_st* instance= memcached_instance_fetch(memc, x); +void send_quit(Memcached *memc) { + for (uint32_t x = 0; x < memcached_server_count(memc); x++) { + memcached_instance_st *instance = memcached_instance_fetch(memc, x); memcached_quit_server(instance, false); } } -void memcached_quit(memcached_st *shell) -{ - Memcached* memc= memcached2Memcached(shell); +void memcached_quit(memcached_st *shell) { + Memcached *memc = memcached2Memcached(shell); memcached_return_t rc; - if (memcached_failed(rc= initialize_query(memc, true))) - { + if (memcached_failed(rc = initialize_query(memc, true))) { return; }