diff options
author | Brian Aker <brian@tangent.org> | 2011-06-28 13:42:14 -0700 |
---|---|---|
committer | Brian Aker <brian@tangent.org> | 2011-06-28 13:42:14 -0700 |
commit | d8dedbd561c7cb57daf4192fe57ce5e205bcadd7 (patch) | |
tree | 86e9705e25c712d9446bbb66e048e96d333274c8 /libmemcached/response.cc | |
parent | 7be0a24db49a94fbadb7bc211b9f581689d80b07 (diff) | |
download | libmemcached-d8dedbd561c7cb57daf4192fe57ce5e205bcadd7.tar.gz |
Merge in namespace fixes for binary protocol.
Diffstat (limited to 'libmemcached/response.cc')
-rw-r--r-- | libmemcached/response.cc | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/libmemcached/response.cc b/libmemcached/response.cc index ff1d77b1..44ce840a 100644 --- a/libmemcached/response.cc +++ b/libmemcached/response.cc @@ -58,9 +58,13 @@ memcached_return_t memcached_read_one_response(memcached_server_write_instance_s memcached_return_t rc; if (ptr->root->flags.binary_protocol) + { rc= binary_read_one_response(ptr, buffer, buffer_length, result); + } else + { rc= textual_read_one_response(ptr, buffer, buffer_length, result); + } unlikely(rc == MEMCACHED_UNKNOWN_READ_FAILURE or rc == MEMCACHED_PROTOCOL_ERROR or @@ -283,7 +287,6 @@ static memcached_return_t textual_read_one_response(memcached_server_write_insta } else if (buffer[1] == 'E') /* SERVER_ERROR */ { - char *rel_ptr; char *startptr= buffer + 13, *endptr= startptr; while (*endptr != '\r' && *endptr != '\n') endptr++; @@ -294,9 +297,9 @@ static memcached_return_t textual_read_one_response(memcached_server_write_insta memory in the struct, which is important, for something that rarely should happen? */ - rel_ptr= (char *)libmemcached_realloc(ptr->root, - ptr->cached_server_error, - (size_t) (endptr - startptr + 1)); + char *rel_ptr= (char *)libmemcached_realloc(ptr->root, + ptr->cached_server_error, + (size_t) (endptr - startptr + 1)); if (rel_ptr == NULL) { @@ -312,7 +315,9 @@ static memcached_return_t textual_read_one_response(memcached_server_write_insta return MEMCACHED_SERVER_ERROR; } else if (buffer[1] == 'T') + { return MEMCACHED_STORED; + } else { WATCHPOINT_STRING(buffer); @@ -321,6 +326,7 @@ static memcached_return_t textual_read_one_response(memcached_server_write_insta } case 'D': /* DELETED */ return MEMCACHED_DELETED; + case 'N': /* NOT_FOUND */ { if (buffer[4] == 'F') @@ -424,19 +430,35 @@ static memcached_return_t binary_read_one_response(memcached_server_write_instan bodylen -= header.response.extlen; result->key_length= keylen; - if ((rc= memcached_safe_read(ptr, result->item_key, keylen)) != MEMCACHED_SUCCESS) + if (memcached_failed(rc= memcached_safe_read(ptr, result->item_key, keylen))) { WATCHPOINT_ERROR(rc); return MEMCACHED_UNKNOWN_READ_FAILURE; } + // Only bother with doing this if key_length > 0 + if (result->key_length) + { + if (memcached_array_size(ptr->root->prefix_key) and memcached_array_size(ptr->root->prefix_key) >= result->key_length) + { + return memcached_set_error(*ptr, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT); + } + + if (memcached_array_size(ptr->root->prefix_key)) + { + result->key_length-= memcached_array_size(ptr->root->prefix_key); + memmove(result->item_key, result->item_key +memcached_array_size(ptr->root->prefix_key), result->key_length); + } + } + bodylen -= keylen; - if (memcached_string_check(&result->value, - bodylen) != MEMCACHED_SUCCESS) + if (memcached_failed(memcached_string_check(&result->value, bodylen))) + { return MEMCACHED_MEMORY_ALLOCATION_FAILURE; + } char *vptr= memcached_string_value_mutable(&result->value); - if ((rc= memcached_safe_read(ptr, vptr, bodylen)) != MEMCACHED_SUCCESS) + if (memcached_failed(rc= memcached_safe_read(ptr, vptr, bodylen))) { WATCHPOINT_ERROR(rc); return MEMCACHED_UNKNOWN_READ_FAILURE; @@ -445,11 +467,14 @@ static memcached_return_t binary_read_one_response(memcached_server_write_instan memcached_string_set_length(&result->value, bodylen); } break; + case PROTOCOL_BINARY_CMD_INCREMENT: case PROTOCOL_BINARY_CMD_DECREMENT: { if (bodylen != sizeof(uint64_t) || buffer_length != sizeof(uint64_t)) + { return MEMCACHED_PROTOCOL_ERROR; + } WATCHPOINT_ASSERT(bodylen == buffer_length); uint64_t val; @@ -463,6 +488,7 @@ static memcached_return_t binary_read_one_response(memcached_server_write_instan memcpy(buffer, &val, sizeof(val)); } break; + case PROTOCOL_BINARY_CMD_SASL_LIST_MECHS: case PROTOCOL_BINARY_CMD_VERSION: { |