From: Brian Aker Date: Sun, 23 Dec 2012 11:50:12 +0000 (-0500) Subject: Update errors to make sure we return the real error. X-Git-Tag: 1.0.16~24^2~1 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=0f8935c1217d98bb2d7054eeea797cfc73a5bd17;p=m6w6%2Flibmemcached Update errors to make sure we return the real error. --- diff --git a/libmemcached/auto.cc b/libmemcached/auto.cc index 4196b668..f9f84d7b 100644 --- a/libmemcached/auto.cc +++ b/libmemcached/auto.cc @@ -52,13 +52,15 @@ static void auto_response(org::libmemcached::Instance* instance, const bool repl rc= memcached_response(instance, &instance->root->result); } - if (memcached_success(rc)) + if (memcached_fatal(rc)) { - *value= instance->root->result.numeric_value; + fprintf(stderr, "%s\n", memcached_strerror(NULL, rc)); + assert(memcached_last_error(instance->root) != MEMCACHED_SUCCESS); + *value= UINT64_MAX; } else { - *value= UINT64_MAX; + *value= instance->root->result.numeric_value; } } diff --git a/libmemcached/connect.cc b/libmemcached/connect.cc index 6b7df7ae..02631b60 100644 --- a/libmemcached/connect.cc +++ b/libmemcached/connect.cc @@ -462,8 +462,7 @@ static memcached_return_t unix_socket_connect(org::libmemcached::Instance* serve if ((server->fd= socket(AF_UNIX, type, 0)) < 0) { - memcached_set_errno(*server, errno, NULL); - return MEMCACHED_CONNECTION_FAILURE; + return memcached_set_errno(*server, errno, NULL); } struct sockaddr_un servAddr; @@ -490,8 +489,7 @@ static memcached_return_t unix_socket_connect(org::libmemcached::Instance* serve default: WATCHPOINT_ERRNO(errno); - memcached_set_errno(*server, errno, MEMCACHED_AT); - return MEMCACHED_CONNECTION_FAILURE; + return memcached_set_errno(*server, errno, MEMCACHED_AT); } } } while (0); diff --git a/libmemcached/delete.cc b/libmemcached/delete.cc index a7526dfc..8b4ca76a 100644 --- a/libmemcached/delete.cc +++ b/libmemcached/delete.cc @@ -101,6 +101,7 @@ static inline memcached_return_t binary_delete(org::libmemcached::Instance* inst memcached_return_t rc; if (memcached_fatal(rc= memcached_vdo(instance, vector, 4, should_flush))) { + assert(memcached_last_error(instance->root) != MEMCACHED_SUCCESS); memcached_io_reset(instance); } @@ -121,6 +122,7 @@ static inline memcached_return_t binary_delete(org::libmemcached::Instance* inst if (memcached_fatal(memcached_vdo(replica, vector, 4, should_flush))) { + assert(memcached_last_error(instance->root) != MEMCACHED_SUCCESS); memcached_io_reset(replica); } else diff --git a/libmemcached/do.cc b/libmemcached/do.cc index ffb9a48b..ef63927b 100644 --- a/libmemcached/do.cc +++ b/libmemcached/do.cc @@ -11,6 +11,56 @@ #include +static memcached_return_t _vdo_udp(org::libmemcached::Instance* instance, + libmemcached_io_vector_st vector[], + const size_t count) +{ +#ifndef __MINGW32__ + if (vector[0].buffer or vector[0].length) + { + return memcached_set_error(*instance->root, MEMCACHED_NOT_SUPPORTED, MEMCACHED_AT, + memcached_literal_param("UDP messages was attempted, but vector was not setup for it")); + } + + struct msghdr msg; + memset(&msg, 0, sizeof(msg)); + + increment_udp_message_id(instance); + vector[0].buffer= instance->write_buffer; + vector[0].length= UDP_DATAGRAM_HEADER_LENGTH; + + msg.msg_iov= (struct iovec*)vector; +#if defined(TARGET_OS_OSX) && TARGET_OS_OSX + msg.msg_iovlen= int(count); +#else + msg.msg_iovlen= count; +#endif + + uint32_t retry= 5; + while (--retry) + { + ssize_t sendmsg_length= ::sendmsg(instance->fd, &msg, 0); + if (sendmsg_length > 0) + { + break; + } + else if (sendmsg_length < 0) + { + if (errno == EMSGSIZE) + { + return memcached_set_error(*instance, MEMCACHED_WRITE_FAILURE, MEMCACHED_AT); + } + + return memcached_set_errno(*instance, errno, MEMCACHED_AT); + } + } + + return MEMCACHED_SUCCESS; +#else + return MEMCACHED_FAILURE; +#endif +} + memcached_return_t memcached_vdo(org::libmemcached::Instance* instance, libmemcached_io_vector_st vector[], const size_t count, @@ -34,62 +84,21 @@ memcached_return_t memcached_vdo(org::libmemcached::Instance* instance, **/ if (memcached_is_udp(instance->root)) { -#ifndef __MINGW32__ - if (vector[0].buffer or vector[0].length) - { - return memcached_set_error(*instance->root, MEMCACHED_NOT_SUPPORTED, MEMCACHED_AT, - memcached_literal_param("UDP messages was attempted, but vector was not setup for it")); - } - - struct msghdr msg; - memset(&msg, 0, sizeof(msg)); - - increment_udp_message_id(instance); - vector[0].buffer= instance->write_buffer; - vector[0].length= UDP_DATAGRAM_HEADER_LENGTH; - - msg.msg_iov= (struct iovec*)vector; -#if defined(TARGET_OS_OSX) && TARGET_OS_OSX - msg.msg_iovlen= int(count); -#else - msg.msg_iovlen= count; -#endif - - uint32_t retry= 5; - while (--retry) - { - ssize_t sendmsg_length= ::sendmsg(instance->fd, &msg, 0); - if (sendmsg_length > 0) - { - break; - } - else if (sendmsg_length < 0) - { - if (errno == EMSGSIZE) - { - return memcached_set_error(*instance, MEMCACHED_WRITE_FAILURE, MEMCACHED_AT); - } - - return memcached_set_errno(*instance, errno, MEMCACHED_AT); - } - } - - return MEMCACHED_SUCCESS; -#else - return MEMCACHED_FAILURE; -#endif + return _vdo_udp(instance, vector, count); } bool sent_success= memcached_io_writev(instance, vector, count, with_flush); if (sent_success == false) { + assert(memcached_last_error(instance->root) == MEMCACHED_SUCCESS); if (memcached_last_error(instance->root) == MEMCACHED_SUCCESS) { + assert(memcached_last_error(instance->root) != MEMCACHED_SUCCESS); return memcached_set_error(*instance, MEMCACHED_WRITE_FAILURE, MEMCACHED_AT); } else { - rc= MEMCACHED_WRITE_FAILURE; + rc= memcached_last_error(instance->root); } } else if (memcached_is_replying(instance->root)) diff --git a/libmemcached/storage.cc b/libmemcached/storage.cc index cd29670d..e17b7609 100644 --- a/libmemcached/storage.cc +++ b/libmemcached/storage.cc @@ -201,7 +201,8 @@ static memcached_return_t memcached_send_binary(memcached_st *ptr, } #endif - return MEMCACHED_WRITE_FAILURE; + assert(memcached_last_error(server->root) != MEMCACHED_SUCCESS); + return memcached_last_error(server->root); } if (verb == SET_OP and ptr->number_of_replicas > 0)