From: Brian Aker Date: Wed, 4 Jan 2012 05:39:35 +0000 (-0800) Subject: Update to error messages. X-Git-Tag: 1.0.3~3^2~1^2 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=2959e927ae7c1da490db7a88f0cd589e8bc6b45f;p=awesomized%2Flibmemcached Update to error messages. --- diff --git a/libmemcached/auto.cc b/libmemcached/auto.cc index 88b921c4..28550a18 100644 --- a/libmemcached/auto.cc +++ b/libmemcached/auto.cc @@ -315,7 +315,8 @@ memcached_return_t memcached_increment_with_initial_by_key(memcached_st *ptr, } else { - rc= MEMCACHED_PROTOCOL_ERROR; + rc= memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, + memcached_literal_param("memcached_increment_with_initial_by_key() is not supported via the ASCII protocol")); } LIBMEMCACHED_MEMCACHED_INCREMENT_WITH_INITIAL_END(); @@ -380,7 +381,8 @@ memcached_return_t memcached_decrement_with_initial_by_key(memcached_st *ptr, } else { - rc= MEMCACHED_PROTOCOL_ERROR; + rc= memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, + memcached_literal_param("memcached_decrement_with_initial_by_key() is not supported via the ASCII protocol")); } LIBMEMCACHED_MEMCACHED_INCREMENT_WITH_INITIAL_END(); diff --git a/libmemcached/behavior.cc b/libmemcached/behavior.cc index abf69996..9769759b 100644 --- a/libmemcached/behavior.cc +++ b/libmemcached/behavior.cc @@ -114,7 +114,7 @@ memcached_return_t memcached_behavior_set(memcached_st *ptr, break; case MEMCACHED_BEHAVIOR_BUFFER_REQUESTS: - if (ptr->flags.use_udp) + if (memcached_is_udp(ptr)) { return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("MEMCACHED_BEHAVIOR_BUFFER_REQUESTS cannot be set while MEMCACHED_BEHAVIOR_USE_UDP is enabled.")); @@ -235,7 +235,7 @@ memcached_return_t memcached_behavior_set(memcached_st *ptr, break; case MEMCACHED_BEHAVIOR_NOREPLY: - if (ptr->flags.use_udp and bool(data) == false) + if (memcached_is_udp(ptr) and bool(data) == false) { return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("MEMCACHED_BEHAVIOR_NOREPLY cannot be disabled while MEMCACHED_BEHAVIOR_USE_UDP is enabled.")); @@ -316,7 +316,7 @@ uint64_t memcached_behavior_get(memcached_st *ptr, return ptr->flags.buffer_requests; case MEMCACHED_BEHAVIOR_USE_UDP: - return ptr->flags.use_udp; + return memcached_is_udp(ptr); case MEMCACHED_BEHAVIOR_TCP_NODELAY: return ptr->flags.tcp_nodelay; diff --git a/libmemcached/fetch.cc b/libmemcached/fetch.cc index 8867d53d..2b5b8006 100644 --- a/libmemcached/fetch.cc +++ b/libmemcached/fetch.cc @@ -44,23 +44,32 @@ char *memcached_fetch(memcached_st *ptr, char *key, size_t *key_length, { memcached_result_st *result_buffer= &ptr->result; memcached_return_t unused; - if (not error) + if (error == NULL) + { error= &unused; + } - - unlikely (ptr->flags.use_udp) + if (memcached_is_udp(ptr)) { if (value_length) + { *value_length= 0; + } if (key_length) + { *key_length= 0; + } if (flags) + { *flags= 0; + } if (key) + { *key= 0; + } *error= MEMCACHED_NOT_SUPPORTED; return NULL; @@ -71,16 +80,24 @@ char *memcached_fetch(memcached_st *ptr, char *key, size_t *key_length, { WATCHPOINT_ASSERT(result_buffer == NULL); if (value_length) + { *value_length= 0; + } if (key_length) + { *key_length= 0; + } if (flags) + { *flags= 0; + } if (key) + { *key= 0; + } return NULL; } @@ -96,26 +113,39 @@ char *memcached_fetch(memcached_st *ptr, char *key, size_t *key_length, { *error= MEMCACHED_KEY_TOO_BIG; if (value_length) + { *value_length= 0; + } - if (key_length) - *key_length= 0; + if (key_length) + { + *key_length= 0; + } - if (flags) - *flags= 0; + if (flags) + { + *flags= 0; + } - if (key) - *key= 0; + if (key) + { + *key= 0; + } return NULL; } + strncpy(key, result_buffer->item_key, result_buffer->key_length); // For the binary protocol we will cut off the key :( if (key_length) + { *key_length= result_buffer->key_length; + } } if (flags) + { *flags= result_buffer->item_flags; + } return memcached_string_take_value(&result_buffer->value); } @@ -134,13 +164,13 @@ memcached_result_st *memcached_fetch_result(memcached_st *ptr, return NULL; } - if (ptr->flags.use_udp) + if (memcached_is_udp(ptr)) { *error= MEMCACHED_NOT_SUPPORTED; return NULL; } - if (not result) + if (result == NULL) { // If we have already initialized (ie it is in use) our internal, we // create one. diff --git a/libmemcached/io.cc b/libmemcached/io.cc index 02f1cc0f..7a321ade 100644 --- a/libmemcached/io.cc +++ b/libmemcached/io.cc @@ -419,7 +419,7 @@ memcached_return_t memcached_io_wait_for_write(memcached_server_write_instance_s } memcached_return_t memcached_io_read(memcached_server_write_instance_st ptr, - void *buffer, size_t length, ssize_t *nread) + void *buffer, size_t length, ssize_t& nread) { assert_msg(ptr, "Programmer error, memcached_io_read() recieved an invalid memcached_server_write_instance_st"); // Programmer error char *buffer_ptr= static_cast(buffer); @@ -475,7 +475,7 @@ memcached_return_t memcached_io_read(memcached_server_write_instance_st ptr, default: { memcached_quit_server(ptr, true); - *nread= -1; + nread= -1; return memcached_set_errno(*ptr, get_socket_errno(), MEMCACHED_AT); } } @@ -493,8 +493,8 @@ memcached_return_t memcached_io_read(memcached_server_write_instance_st ptr, */ WATCHPOINT_STRING("We had a zero length recv()"); memcached_quit_server(ptr, true); - *nread= -1; - return memcached_set_error(*ptr, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT, + nread= -1; + return memcached_set_error(*ptr, MEMCACHED_CONNECTION_FAILURE, MEMCACHED_AT, memcached_literal_param("::rec() returned zero, server has disconnected")); } } while (data_read <= 0); @@ -527,7 +527,7 @@ memcached_return_t memcached_io_read(memcached_server_write_instance_st ptr, } } - *nread = (ssize_t)(buffer_ptr - (char*)buffer); + nread= ssize_t(buffer_ptr - (char*)buffer); return MEMCACHED_SUCCESS; } @@ -810,14 +810,14 @@ memcached_return_t memcached_safe_read(memcached_server_write_instance_st ptr, ssize_t nread; memcached_return_t rc; - while (memcached_continue(rc= memcached_io_read(ptr, data + offset, size - offset, &nread))) { }; + while (memcached_continue(rc= memcached_io_read(ptr, data + offset, size - offset, nread))) { }; if (memcached_failed(rc)) { return rc; } - offset+= (size_t) nread; + offset+= size_t(nread); } return MEMCACHED_SUCCESS; @@ -841,7 +841,7 @@ memcached_return_t memcached_io_readline(memcached_server_write_instance_st ptr, * the logic. */ ssize_t nread; - memcached_return_t rc= memcached_io_read(ptr, buffer_ptr, 1, &nread); + memcached_return_t rc= memcached_io_read(ptr, buffer_ptr, 1, nread); if (memcached_failed(rc) and rc == MEMCACHED_IN_PROGRESS) { memcached_quit_server(ptr, true); diff --git a/libmemcached/io.hpp b/libmemcached/io.hpp index efce2233..549f86a0 100644 --- a/libmemcached/io.hpp +++ b/libmemcached/io.hpp @@ -52,7 +52,7 @@ memcached_return_t memcached_io_wait_for_write(memcached_server_write_instance_s void memcached_io_reset(memcached_server_write_instance_st ptr); memcached_return_t memcached_io_read(memcached_server_write_instance_st ptr, - void *buffer, size_t length, ssize_t *nread); + void *buffer, size_t length, ssize_t& nread); /* Read a line (terminated by '\n') into the buffer */ memcached_return_t memcached_io_readline(memcached_server_write_instance_st ptr, diff --git a/libmemcached/purge.cc b/libmemcached/purge.cc index d80785ff..4dd65419 100644 --- a/libmemcached/purge.cc +++ b/libmemcached/purge.cc @@ -78,7 +78,6 @@ memcached_return_t memcached_purge(memcached_server_write_instance_st ptr) { memcached_result_st result; memcached_result_st *result_ptr; - char buffer[SMALL_STRING_LEN]; /* * We need to increase the timeout, because we might be waiting for @@ -94,9 +93,7 @@ memcached_return_t memcached_purge(memcached_server_write_instance_st ptr) for (uint32_t x= 0; x < no_msg; x++) { memcached_result_reset(result_ptr); - memcached_return_t rc= memcached_read_one_response(ptr, buffer, - sizeof (buffer), - result_ptr); + memcached_return_t rc= memcached_read_one_response(ptr, result_ptr); /* * Purge doesn't care for what kind of command results that is received. * The only kind of errors I care about if is I'm out of sync with the @@ -115,7 +112,7 @@ memcached_return_t memcached_purge(memcached_server_write_instance_st ptr) if (ptr->root->callbacks != NULL) { memcached_callback_st cb = *ptr->root->callbacks; - if (rc == MEMCACHED_SUCCESS) + if (memcached_success(rc)) { for (uint32_t y= 0; y < cb.number_of_callback; y++) { diff --git a/libmemcached/response.cc b/libmemcached/response.cc index 435cafe7..e876123d 100644 --- a/libmemcached/response.cc +++ b/libmemcached/response.cc @@ -146,7 +146,7 @@ static memcached_return_t textual_value_fetch(memcached_server_write_instance_st some people lazy about using the return length. */ size_t to_read= (value_length) + 2; - memcached_return_t rrc= memcached_io_read(ptr, value_ptr, to_read, &read_length); + memcached_return_t rrc= memcached_io_read(ptr, value_ptr, to_read, read_length); if (memcached_failed(rrc) and rrc == MEMCACHED_IN_PROGRESS) { memcached_quit_server(ptr, true); @@ -181,7 +181,7 @@ read_error: } static memcached_return_t textual_read_one_response(memcached_server_write_instance_st ptr, - char *buffer, size_t buffer_length, + char *buffer, const size_t buffer_length, memcached_result_st *result, uint64_t& numeric_value) { @@ -193,39 +193,49 @@ static memcached_return_t textual_read_one_response(memcached_server_write_insta { return rc; } + assert(total_read); switch(buffer[0]) { - case 'V': /* VALUE || VERSION */ - if (buffer[1] == 'A' and buffer[2] == 'L' and buffer[3] == 'U' and buffer[4] == 'E') /* VALUE */ + case 'V': { - /* We add back in one because we will need to search for END */ - memcached_server_response_increment(ptr); - return textual_value_fetch(ptr, buffer, result); - } - else if (buffer[1] == 'E' and buffer[2] == 'R' and buffer[3] == 'S' and buffer[4] == 'I' and buffer[5] == 'O' and buffer[6] == 'N') /* VERSION */ - { - return MEMCACHED_SUCCESS; + // VALUE + if (buffer[1] == 'A' and buffer[2] == 'L' and buffer[3] == 'U' and buffer[4] == 'E') /* VALUE */ + { + /* We add back in one because we will need to search for END */ + memcached_server_response_increment(ptr); + return textual_value_fetch(ptr, buffer, result); + } + // VERSION + else if (buffer[1] == 'E' and buffer[2] == 'R' and buffer[3] == 'S' and buffer[4] == 'I' and buffer[5] == 'O' and buffer[6] == 'N') /* VERSION */ + { + return MEMCACHED_SUCCESS; + } } break; - case 'O': /* OK */ - if (buffer[1] == 'K') + case 'O': { - return MEMCACHED_SUCCESS; + // OK + if (buffer[1] == 'K') + { + return MEMCACHED_SUCCESS; + } } break; - case 'S': /* STORED STATS SERVER_ERROR */ + case 'S': { + // STAT if (buffer[1] == 'T' and buffer[2] == 'A' and buffer[3] == 'T') /* STORED STATS */ { memcached_server_response_increment(ptr); return MEMCACHED_STAT; } + // SERVER_ERROR else if (buffer[1] == 'E' and buffer[2] == 'R' and buffer[3] == 'V' and buffer[4] == 'E' and buffer[5] == 'R' and buffer[6] == '_' - and buffer[7] == 'E' and buffer[8] == 'R' and buffer[9] == 'R' and buffer[10] == 'O' and buffer[11] == 'R' ) /* SERVER_ERROR */ + and buffer[7] == 'E' and buffer[8] == 'R' and buffer[9] == 'R' and buffer[10] == 'O' and buffer[11] == 'R' ) { if (total_read == memcached_literal_param_size("SERVER_ERROR")) { @@ -250,28 +260,34 @@ static memcached_return_t textual_read_one_response(memcached_server_write_insta return memcached_set_error(*ptr, MEMCACHED_SERVER_ERROR, MEMCACHED_AT, startptr, size_t(endptr - startptr)); } - else if (buffer[1] == 'T' and buffer[2] == 'O' and buffer[3] == 'R' and buffer[4] == 'E' and buffer[5] == 'D') + // STORED + else if (buffer[1] == 'T' and buffer[2] == 'O' and buffer[3] == 'R') // and buffer[4] == 'E' and buffer[5] == 'D') { return MEMCACHED_STORED; } } break; - case 'D': /* DELETED */ + case 'D': + { + // DELETED if (buffer[1] == 'E' and buffer[2] == 'L' and buffer[3] == 'E' and buffer[4] == 'T' and buffer[5] == 'E' and buffer[6] == 'D') { return MEMCACHED_DELETED; } - break; + } + break; - case 'N': /* NOT_FOUND */ + case 'N': { + // NOT_FOUND if (buffer[1] == 'O' and buffer[2] == 'T' and buffer[3] == '_' and buffer[4] == 'F' and buffer[5] == 'O' and buffer[6] == 'U' and buffer[7] == 'N' and buffer[8] == 'D') { return MEMCACHED_NOTFOUND; } + // NOT_STORED else if (buffer[1] == 'O' and buffer[2] == 'T' and buffer[3] == '_' and buffer[4] == 'S' and buffer[5] == 'T' and buffer[6] == 'O' and buffer[7] == 'R' and buffer[8] == 'E' and buffer[9] == 'D') @@ -283,16 +299,21 @@ static memcached_return_t textual_read_one_response(memcached_server_write_insta case 'E': /* PROTOCOL ERROR or END */ { + // END if (buffer[1] == 'N' and buffer[2] == 'D') { return MEMCACHED_END; } +#if 0 + // PROTOCOL_ERROR else if (buffer[1] == 'R' and buffer[2] == 'O' and buffer[3] == 'T' and buffer[4] == 'O' and buffer[5] == 'C' and buffer[6] == 'O' and buffer[7] == 'L' and buffer[8] == '_' and buffer[9] == 'E' and buffer[10] == 'R' and buffer[11] == 'R' and buffer[12] == 'O' and buffer[13] == 'R') { return MEMCACHED_PROTOCOL_ERROR; } +#endif + // EXISTS else if (buffer[1] == 'X' and buffer[2] == 'I' and buffer[3] == 'S' and buffer[4] == 'T' and buffer[5] == 'S') { return MEMCACHED_DATA_EXISTS; @@ -302,6 +323,7 @@ static memcached_return_t textual_read_one_response(memcached_server_write_insta case 'T': /* TOUCHED */ { + // TOUCHED if (buffer[1] == 'O' and buffer[2] == 'U' and buffer[3] == 'C' and buffer[4] == 'H' and buffer[5] == 'E' and buffer[6] == 'D') { return MEMCACHED_SUCCESS; @@ -310,18 +332,26 @@ static memcached_return_t textual_read_one_response(memcached_server_write_insta break; case 'I': /* ITEM */ - if (buffer[1] == 'T' and buffer[2] == 'E' and buffer[3] == 'M') { - /* We add back in one because we will need to search for END */ - memcached_server_response_increment(ptr); - return MEMCACHED_ITEM; + // ITEM + if (buffer[1] == 'T' and buffer[2] == 'E' and buffer[3] == 'M') + { + /* We add back in one because we will need to search for END */ + memcached_server_response_increment(ptr); + return MEMCACHED_ITEM; + } } break; case 'C': /* CLIENT ERROR */ - if (buffer[1] == 'L' and buffer[2] == 'I' and buffer[3] == 'E' and buffer[4] == 'N' and buffer[5] == 'T') { - return MEMCACHED_CLIENT_ERROR; + // CLIENT_ERROR + if (buffer[1] == 'L' and buffer[2] == 'I' and buffer[3] == 'E' and buffer[4] == 'N' and buffer[5] == 'T' + and buffer[6] == '_' + and buffer[7] == 'E' and buffer[8] == 'R' and buffer[9] == 'R' and buffer[10] == 'O' and buffer[11] == 'R') + { + return MEMCACHED_CLIENT_ERROR; + } } break; @@ -360,12 +390,20 @@ static memcached_return_t textual_read_one_response(memcached_server_write_insta } buffer[total_read]= 0; +#if 0 + if (total_read >= sizeof("STORSTORED") -1) + { + fprintf(stderr, "%s:%d '%s', %.*s\n", __FILE__, __LINE__, + buffer, MEMCACHED_MAX_BUFFER, ptr->read_buffer); + assert(memcmp(buffer,"STORSTORED", sizeof("STORSTORED") -1)); + } +#endif return memcached_set_error(*ptr, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT, buffer, total_read); } static memcached_return_t binary_read_one_response(memcached_server_write_instance_st ptr, - char *buffer, size_t buffer_length, + char *buffer, const size_t buffer_length, memcached_result_st *result) { memcached_return_t rc; @@ -379,7 +417,7 @@ static memcached_return_t binary_read_one_response(memcached_server_write_instan if (header.response.magic != PROTOCOL_BINARY_RES) { - return MEMCACHED_PROTOCOL_ERROR; + return memcached_set_error(*ptr, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT); } /* @@ -462,7 +500,7 @@ static memcached_return_t binary_read_one_response(memcached_server_write_instan { if (bodylen != sizeof(uint64_t) or buffer_length != sizeof(uint64_t)) { - return MEMCACHED_PROTOCOL_ERROR; + return memcached_set_error(*ptr, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT); } WATCHPOINT_ASSERT(bodylen == buffer_length); @@ -562,8 +600,7 @@ static memcached_return_t binary_read_one_response(memcached_server_write_instan default: { /* Command not implemented yet! */ - WATCHPOINT_ASSERT(0); - return MEMCACHED_PROTOCOL_ERROR; + return memcached_set_error(*ptr, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT); } } } @@ -636,8 +673,7 @@ static memcached_return_t binary_read_one_response(memcached_server_write_instan case PROTOCOL_BINARY_RESPONSE_EINVAL: case PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND: default: - /* @todo fix the error mappings */ - rc= MEMCACHED_PROTOCOL_ERROR; + return memcached_set_error(*ptr, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT); break; } } @@ -645,25 +681,11 @@ static memcached_return_t binary_read_one_response(memcached_server_write_instan return rc; } -memcached_return_t memcached_read_one_response(memcached_server_write_instance_st ptr, - char *buffer, size_t buffer_length, - memcached_result_st *result) -{ - uint64_t numeric_value; - - return memcached_read_one_response(ptr, buffer, buffer_length, result, numeric_value); -} - -memcached_return_t memcached_read_one_response(memcached_server_write_instance_st ptr, - char *buffer, size_t buffer_length, - memcached_result_st *result, - uint64_t& numeric_value) +static memcached_return_t _read_one_response(memcached_server_write_instance_st ptr, + char *buffer, const size_t buffer_length, + memcached_result_st *result, + uint64_t& numeric_value) { - if (memcached_is_udp(ptr->root)) - { - return memcached_set_error(*ptr, MEMCACHED_NOT_SUPPORTED, MEMCACHED_AT); - } - memcached_server_response_decrement(ptr); if (result == NULL) @@ -673,13 +695,14 @@ memcached_return_t memcached_read_one_response(memcached_server_write_instance_s } memcached_return_t rc; - if (ptr->root->flags.binary_protocol) + if (memcached_is_binary(ptr->root)) { rc= binary_read_one_response(ptr, buffer, buffer_length, result); } else { rc= textual_read_one_response(ptr, buffer, buffer_length, result, numeric_value); + assert(rc != MEMCACHED_PROTOCOL_ERROR); } if (rc == MEMCACHED_UNKNOWN_READ_FAILURE or @@ -694,6 +717,21 @@ memcached_return_t memcached_read_one_response(memcached_server_write_instance_s return rc; } +memcached_return_t memcached_read_one_response(memcached_server_write_instance_st ptr, + memcached_result_st *result) +{ + uint64_t numeric_value; + char buffer[SMALL_STRING_LEN]; + + if (memcached_is_udp(ptr->root)) + { + return memcached_set_error(*ptr, MEMCACHED_NOT_SUPPORTED, MEMCACHED_AT); + } + + + return _read_one_response(ptr, buffer, sizeof(buffer), result, numeric_value); +} + memcached_return_t memcached_response(memcached_server_write_instance_st ptr, char *buffer, size_t buffer_length, memcached_result_st *result) @@ -724,25 +762,33 @@ memcached_return_t memcached_response(memcached_server_write_instance_st ptr, * returned the last one. Purge all pending messages to ensure backwards * compatibility. */ - if (memcached_is_binary(ptr->root) == false) + if (memcached_is_binary(ptr->root) == false and memcached_server_response_count(ptr) > 1) { + memcached_result_st junked_result; + memcached_result_st *junked_result_ptr= memcached_result_create(ptr->root, &junked_result); + + assert(junked_result_ptr); + while (memcached_server_response_count(ptr) > 1) { - memcached_return_t rc= memcached_read_one_response(ptr, buffer, buffer_length, result, numeric_value); - - if (rc != MEMCACHED_END && - rc != MEMCACHED_STORED && - rc != MEMCACHED_SUCCESS && - rc != MEMCACHED_STAT && - rc != MEMCACHED_DELETED && - rc != MEMCACHED_NOTFOUND && - rc != MEMCACHED_NOTSTORED && + memcached_return_t rc= _read_one_response(ptr, buffer, buffer_length, junked_result_ptr, numeric_value); + + // @TODO should we return an error on another but a bad read case? + if (rc != MEMCACHED_END and + rc != MEMCACHED_STORED and + rc != MEMCACHED_SUCCESS and + rc != MEMCACHED_STAT and + rc != MEMCACHED_DELETED and + rc != MEMCACHED_NOTFOUND and + rc != MEMCACHED_NOTSTORED and rc != MEMCACHED_DATA_EXISTS) { + memcached_result_free(junked_result_ptr); return rc; } } + memcached_result_free(junked_result_ptr); } - return memcached_read_one_response(ptr, buffer, buffer_length, result, numeric_value); + return _read_one_response(ptr, buffer, buffer_length, result, numeric_value); } diff --git a/libmemcached/response.h b/libmemcached/response.h index 527bf062..d9abdb8a 100644 --- a/libmemcached/response.h +++ b/libmemcached/response.h @@ -39,14 +39,8 @@ /* Read a single response from the server */ memcached_return_t memcached_read_one_response(memcached_server_write_instance_st ptr, - char *buffer, size_t buffer_length, memcached_result_st *result); -memcached_return_t memcached_read_one_response(memcached_server_write_instance_st ptr, - char *buffer, size_t buffer_length, - memcached_result_st *result, - uint64_t& numeric_value); - memcached_return_t memcached_response(memcached_server_write_instance_st ptr, char *buffer, size_t buffer_length, memcached_result_st *result); diff --git a/libmemcached/sasl.cc b/libmemcached/sasl.cc index 77c5fdf7..902ccd87 100644 --- a/libmemcached/sasl.cc +++ b/libmemcached/sasl.cc @@ -133,9 +133,10 @@ memcached_return_t memcached_sasl_authenticate_connection(memcached_server_st *s } /* SANITY CHECK: SASL can only be used with the binary protocol */ - if (server->root->flags.binary_protocol == false) + if (memcached_is_binary(server->root) == false) { - return MEMCACHED_PROTOCOL_ERROR; + return memcached_set_error(*server, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, + memcached_literal_param("memcached_sasl_authenticate_connection() is not supported via the ASCII protocol")); } /* Try to get the supported mech from the server. Servers without SASL diff --git a/libmemcached/stats.cc b/libmemcached/stats.cc index a0a965f1..d5d1c234 100644 --- a/libmemcached/stats.cc +++ b/libmemcached/stats.cc @@ -543,7 +543,7 @@ memcached_stat_st *memcached_stat(memcached_st *self, char *args, memcached_retu memcached_server_write_instance_st instance= memcached_server_instance_fetch(self, x); memcached_return_t temp_return; - if (self->flags.binary_protocol) + if (memcached_is_binary(self)) { temp_return= binary_stats_fetch(stat_instance, args, args_length, instance, NULL); } diff --git a/libmemcached/storage.cc b/libmemcached/storage.cc index 0ce4ea61..2d0ae8fc 100644 --- a/libmemcached/storage.cc +++ b/libmemcached/storage.cc @@ -290,20 +290,22 @@ static memcached_return_t memcached_send_ascii(memcached_st *ptr, /* Send command header */ memcached_return_t rc= memcached_vdo(instance, vector, 12, flush); - if (rc == MEMCACHED_SUCCESS) + + // If we should not reply, return with MEMCACHED_SUCCESS, unless error + if (reply == false) { - if (flush == false) - { - return MEMCACHED_BUFFERED; - } + return memcached_success(rc) ? MEMCACHED_SUCCESS : rc; + } - if (reply == false) - { - return MEMCACHED_SUCCESS; - } + if (flush == false) + { + return memcached_success(rc) ? MEMCACHED_BUFFERED : rc; + } + if (rc == MEMCACHED_SUCCESS) + { char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; - rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); + rc= memcached_response(instance, buffer, sizeof(buffer), NULL); if (rc == MEMCACHED_STORED) { diff --git a/libmemcachedutil/pid.cc b/libmemcachedutil/pid.cc index 7ff665b6..99f378d1 100644 --- a/libmemcachedutil/pid.cc +++ b/libmemcachedutil/pid.cc @@ -48,11 +48,13 @@ pid_t libmemcached_util_getpid(const char *hostname, in_port_t port, memcached_r pid_t pid= -1; memcached_return_t unused; - if (not ret) + if (ret == NULL) + { ret= &unused; + } memcached_st *memc_ptr= memcached_create(NULL); - if (not memc_ptr) + if (memc_ptr == NULL) { *ret= MEMCACHED_MEMORY_ALLOCATION_FAILURE; return -1; @@ -72,8 +74,7 @@ pid_t libmemcached_util_getpid(const char *hostname, in_port_t port, memcached_r } else if (rc == MEMCACHED_SOME_ERRORS) // Generic answer, we will now find the specific reason (if one exists) { - memcached_server_instance_st instance= - memcached_server_instance_by_position(memc_ptr, 0); + memcached_server_instance_st instance= memcached_server_instance_by_position(memc_ptr, 0); assert_msg(instance and instance->error_messages, " "); if (instance and instance->error_messages) diff --git a/libtest/run.gdb b/libtest/run.gdb index a520ae87..320407a2 100644 --- a/libtest/run.gdb +++ b/libtest/run.gdb @@ -1,3 +1,2 @@ set environment LIBTEST_IN_GDB=1 run -quit diff --git a/tests/include.am b/tests/include.am index 5afdf5bf..23f0f899 100644 --- a/tests/include.am +++ b/tests/include.am @@ -229,8 +229,8 @@ test-memcapable: tests/var tests/memcapable pahole-mem: tests/testapp @$(PAHOLE_COMMAND) tests/testapp -gdb-mem: tests/testapp - @$(DEBUG_COMMAND) tests/testapp +gdb-mem: tests/var tests/libmemcached-1.0/testapp + @$(DEBUG_COMMAND) tests/libmemcached-1.0/testapp gdb-sasl: tests/sasl @$(DEBUG_COMMAND) tests/sasl