From: Brian Aker Date: Tue, 15 Feb 2011 18:37:39 +0000 (-0800) Subject: Merge in bug fix for 456080. X-Git-Tag: 0.51~38 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=2591754352720dd6d6aaf5980b06804e39016ed3;p=m6w6%2Flibmemcached Merge in bug fix for 456080. --- diff --git a/docs/memcached_behavior.pod b/docs/memcached_behavior.pod index b3cf33ad..02ab0de4 100644 --- a/docs/memcached_behavior.pod +++ b/docs/memcached_behavior.pod @@ -239,13 +239,13 @@ Specify time, in seconds, to mark a connection as idle. This is only available a Find the current size of SO_SNDBUF. A value of 0 means either an error occured or no hosts were available. It is safe to assume system default -if this occurs. +if this occurs. If an error occurs you can checked the last cached errno statement to find the specific error. =item MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE Find the current size of SO_RCVBUF. A value of 0 means either an error occured or no hosts were available. It is safe to assume system default -if this occurs. +if this occurs. If an error occurs you can checked the last cached errno statement to find the specific error. =item MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT diff --git a/libmemcached/behavior.c b/libmemcached/behavior.c index b84e770a..2b6ccdf9 100644 --- a/libmemcached/behavior.c +++ b/libmemcached/behavior.c @@ -313,11 +313,20 @@ uint64_t memcached_behavior_get(memcached_st *ptr, /* REFACTOR */ /* We just try the first host, and if it is down we return zero */ if ((memcached_connect(instance)) != MEMCACHED_SUCCESS) + { + return 0; + } + + if (memcached_io_wait_for_write(instance) != MEMCACHED_SUCCESS) + { return 0; + } - if (getsockopt(instance->fd, SOL_SOCKET, - SO_SNDBUF, &sock_size, &sock_length)) + if (getsockopt(instance->fd, SOL_SOCKET, SO_SNDBUF, &sock_size, &sock_length) < 0) + { + ptr->cached_errno= errno; return 0; /* Zero means error */ + } } return (uint64_t) sock_size; @@ -340,11 +349,20 @@ uint64_t memcached_behavior_get(memcached_st *ptr, { /* We just try the first host, and if it is down we return zero */ if ((memcached_connect(instance)) != MEMCACHED_SUCCESS) + { + return 0; + } + + if (memcached_io_wait_for_write(instance) != MEMCACHED_SUCCESS) + { return 0; + } - if (getsockopt(instance->fd, SOL_SOCKET, - SO_RCVBUF, &sock_size, &sock_length)) + if (getsockopt(instance->fd, SOL_SOCKET, SO_RCVBUF, &sock_size, &sock_length) < 0) + { + ptr->cached_errno= errno; return 0; /* Zero means error */ + } } diff --git a/libmemcached/io.c b/libmemcached/io.c index 9f38af5c..e94c136f 100644 --- a/libmemcached/io.c +++ b/libmemcached/io.c @@ -105,6 +105,11 @@ static memcached_return_t io_wait(memcached_server_write_instance_st ptr, return MEMCACHED_FAILURE; } +memcached_return_t memcached_io_wait_for_write(memcached_server_write_instance_st ptr) +{ + return io_wait(ptr, MEM_WRITE); +} + /** * Try to fill the input buffer for a server with as much * data as possible. diff --git a/libmemcached/io.h b/libmemcached/io.h index 9d5087e0..3662954d 100644 --- a/libmemcached/io.h +++ b/libmemcached/io.h @@ -46,6 +46,9 @@ struct libmemcached_io_vector_st const void *buffer; }; +LIBMEMCACHED_LOCAL +memcached_return_t memcached_io_wait_for_write(memcached_server_write_instance_st ptr); + LIBMEMCACHED_LOCAL ssize_t memcached_io_writev(memcached_server_write_instance_st ptr, const struct libmemcached_io_vector_st *vector,