From: Date: Wed, 21 May 2008 14:49:54 +0000 (+0900) Subject: Fix for death of file io to call shutdown() X-Git-Tag: 0.21~1 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=91e5a2590a918ee7718023d99cc23692d5b2da23;p=m6w6%2Flibmemcached Fix for death of file io to call shutdown() --- diff --git a/ChangeLog b/ChangeLog index 7c95c16c..e533985c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ * New MEMCACHED_CALLBACK_PREFIX_KEY added. You can now create domains for values. * Fixed bug introducd in last version on memcp + * Fix for death of file io to call shutdown() 0.20 Mon May 5 08:34:26 PDT 2008 * New consistent distribution tests. diff --git a/libmemcached/memcached_get.c b/libmemcached/memcached_get.c index f6c81338..34fcb4ea 100644 --- a/libmemcached/memcached_get.c +++ b/libmemcached/memcached_get.c @@ -51,22 +51,28 @@ char *memcached_get_by_key(memcached_st *ptr, /* On all failure drop to returning NULL */ if (rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED) { - uint8_t latch; /* We use latch to track the state of the original socket */ - if (rc == MEMCACHED_BUFFERED) { + uint8_t latch; /* We use latch to track the state of the original socket */ latch= memcached_behavior_get(ptr, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS); if (latch == 0) memcached_behavior_set(ptr, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 1); - } - rc= memcached_set(ptr, key, key_length, - memcached_result_value(&ptr->result), - memcached_result_length(&ptr->result), - 0, memcached_result_flags(&ptr->result)); + rc= memcached_set(ptr, key, key_length, + memcached_result_value(&ptr->result), + memcached_result_length(&ptr->result), + 0, memcached_result_flags(&ptr->result)); - if (rc == MEMCACHED_BUFFERED && latch == 0) - memcached_behavior_set(ptr, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 0); + if (rc == MEMCACHED_BUFFERED && latch == 0) + memcached_behavior_set(ptr, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 0); + } + else + { + rc= memcached_set(ptr, key, key_length, + memcached_result_value(&ptr->result), + memcached_result_length(&ptr->result), + 0, memcached_result_flags(&ptr->result)); + } if (rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED) { diff --git a/libmemcached/memcached_io.c b/libmemcached/memcached_io.c index 38544102..93ca4173 100644 --- a/libmemcached/memcached_io.c +++ b/libmemcached/memcached_io.c @@ -204,9 +204,14 @@ ssize_t memcached_io_write(memcached_server_st *ptr, return original_length; } -memcached_return memcached_io_close(memcached_server_st *ptr) +memcached_return memcached_io_close(memcached_server_st *ptr, uint8_t io_death) { - close(ptr->fd); + /* in case of death shutdown to avoid blocking at close() */ + + if (io_death) + shutdown(ptr->fd, SHUT_RDWR); + else + close(ptr->fd); return MEMCACHED_SUCCESS; } diff --git a/libmemcached/memcached_io.h b/libmemcached/memcached_io.h index 887f5200..f7a72574 100644 --- a/libmemcached/memcached_io.h +++ b/libmemcached/memcached_io.h @@ -6,4 +6,4 @@ ssize_t memcached_io_write(memcached_server_st *ptr, void memcached_io_reset(memcached_server_st *ptr); ssize_t memcached_io_read(memcached_server_st *ptr, char *buffer, size_t length); -memcached_return memcached_io_close(memcached_server_st *ptr); +memcached_return memcached_io_close(memcached_server_st *ptr, uint8_t io_death); diff --git a/libmemcached/memcached_quit.c b/libmemcached/memcached_quit.c index b764cd1b..9749b848 100644 --- a/libmemcached/memcached_quit.c +++ b/libmemcached/memcached_quit.c @@ -29,12 +29,9 @@ void memcached_quit_server(memcached_server_st *ptr, uint8_t io_death) */ while ((read_length= memcached_io_read(ptr, buffer, sizeof(buffer)/sizeof(*buffer))) - > 0) - { - ; - } + > 0); } - memcached_io_close(ptr); + memcached_io_close(ptr, io_death); ptr->fd= -1; ptr->write_buffer_offset= 0;