X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fquit.c;h=18a9a316956f6aa3ce676289353eec3221620c9e;hb=f283b947353ca50d35adad5326700df66a86c1a5;hp=dc11e97fcea5e65356c5775ca5147d2a01b733ad;hpb=04e768d414826cdea61b7b5f7e7e51b3c791feb5;p=awesomized%2Flibmemcached diff --git a/libmemcached/quit.c b/libmemcached/quit.c index dc11e97f..18a9a316 100644 --- a/libmemcached/quit.c +++ b/libmemcached/quit.c @@ -9,26 +9,28 @@ will force data to be completed. */ -void memcached_quit_server(memcached_server_st *ptr, uint8_t io_death) +void memcached_quit_server(memcached_server_st *ptr, bool io_death) { if (ptr->fd != -1) { - if (io_death == 0 && ptr->type != MEMCACHED_CONNECTION_UDP) + if (io_death == false && ptr->type != MEMCACHED_CONNECTION_UDP && ptr->options.is_shutting_down == false) { memcached_return_t rc; char buffer[MEMCACHED_MAX_BUFFER]; + ptr->options.is_shutting_down= true; + if (ptr->root->flags.binary_protocol) { protocol_binary_request_quit request = {.bytes= {0}}; request.message.header.request.magic = PROTOCOL_BINARY_REQ; request.message.header.request.opcode = PROTOCOL_BINARY_CMD_QUIT; request.message.header.request.datatype = PROTOCOL_BINARY_RAW_BYTES; - rc= memcached_do(ptr, request.bytes, sizeof(request.bytes), 1); + rc= memcached_do(ptr, request.bytes, sizeof(request.bytes), true); } else { - rc= memcached_do(ptr, "quit\r\n", 6, 1); + rc= memcached_do(ptr, "quit\r\n", strlen("quit\r\n"), true); } WATCHPOINT_ASSERT(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_FETCH_NOTFINISHED); @@ -38,10 +40,17 @@ void memcached_quit_server(memcached_server_st *ptr, uint8_t io_death) * 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. */ - ssize_t nread; - while (memcached_io_read(ptr, buffer, sizeof(buffer)/sizeof(*buffer), - &nread) == MEMCACHED_SUCCESS); + if (ptr->root->flags.buffer_requests || ptr->root->number_of_replicas) + { + ssize_t nread; + while (memcached_io_read(ptr, buffer, sizeof(buffer)/sizeof(*buffer), + &nread) == MEMCACHED_SUCCESS); + } + /* * memcached_io_read may call memcached_quit_server with io_death if @@ -59,25 +68,31 @@ void memcached_quit_server(memcached_server_st *ptr, uint8_t io_death) ptr->write_buffer_offset= (size_t) ((ptr->type == MEMCACHED_CONNECTION_UDP) ? UDP_DATAGRAM_HEADER_LENGTH : 0); ptr->read_buffer_length= 0; ptr->read_ptr= ptr->read_buffer; + ptr->options.is_shutting_down= false; memcached_server_response_reset(ptr); - if(io_death) + if (io_death) { ptr->server_failure_counter++; + set_last_disconnected_host(ptr); } } void memcached_quit(memcached_st *ptr) { - unsigned int x; + uint32_t x; - if (ptr->hosts == NULL || - ptr->number_of_hosts == 0) + if (memcached_server_count(ptr) == 0) return; - if (ptr->hosts && ptr->number_of_hosts) + if (memcached_server_count(ptr)) { - for (x= 0; x < ptr->number_of_hosts; x++) - memcached_quit_server(&ptr->hosts[x], 0); + for (x= 0; x < memcached_server_count(ptr); x++) + { + memcached_server_write_instance_st instance= + memcached_server_instance_fetch(ptr, x); + + memcached_quit_server(instance, false); + } } }