X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fquit.cc;h=7ece03b9bbabad323c11a58480f01b21277989a9;hb=b30da3e793829246675966830c668c3f60496e07;hp=c12a1d82b32ca5b9385c49c6fc0562cd86b093a6;hpb=c856b49960f8f0f536edb996bf665a0ac40325a3;p=m6w6%2Flibmemcached diff --git a/libmemcached/quit.cc b/libmemcached/quit.cc index c12a1d82..7ece03b9 100644 --- a/libmemcached/quit.cc +++ b/libmemcached/quit.cc @@ -37,6 +37,65 @@ #include +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}}; + + 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; + + 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); + } + + return rc; + } + + 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; + } +} + /* This closes all connections (forces flush of input as well). @@ -46,108 +105,40 @@ will force data to be completed. */ -void memcached_quit_server(org::libmemcached::Instance* instance, bool io_death) +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) { - memcached_return_t rc; - if (instance->root->flags.binary_protocol) - { - protocol_binary_request_quit request= {}; // = {.bytes= {0}}; - - 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; - - 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); - } + send_quit_message(instance); instance->start_close_socket(); - - /* 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 (memcached_success(rc) and (instance->root->flags.buffer_requests or instance->root->number_of_replicas)) - { - if (0) - { - memcached_return_t rc_slurp; - while (memcached_continue(rc_slurp= memcached_io_slurp(instance))) {} ; - WATCHPOINT_ASSERT(rc_slurp == MEMCACHED_CONNECTION_FAILURE); - } - else - { - 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; + drain_instance(instance); } - } instance->close_socket(); - instance->state= MEMCACHED_SERVER_STATE_NEW; - instance->cursor_active_= 0; - instance->io_bytes_sent= 0; - instance->write_buffer_offset= size_t(instance->root and memcached_is_udp(instance->root) ? UDP_DATAGRAM_HEADER_LENGTH : 0); - instance->read_buffer_length= 0; - instance->read_ptr= instance->read_buffer; - instance->options.is_shutting_down= false; - memcached_server_response_reset(instance); - - // We reset the version so that if we end up talking to a different server - // we don't have stale server version information. - instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX; - if (io_death) { memcached_mark_server_for_timeout(instance); } } -void send_quit(memcached_st *memc) +void send_quit(Memcached *memc) { for (uint32_t x= 0; x < memcached_server_count(memc); x++) { - org::libmemcached::Instance* instance= memcached_instance_fetch(memc, x); + memcached_instance_st* instance= memcached_instance_fetch(memc, x); memcached_quit_server(instance, false); } } -void memcached_quit(memcached_st *memc) +void memcached_quit(memcached_st *shell) { + Memcached* memc= memcached2Memcached(shell); memcached_return_t rc; if (memcached_failed(rc= initialize_query(memc, true))) {