Skip to content

Commit

Permalink
INTERNAL: Refactor a memcached_fetch function
Browse files Browse the repository at this point in the history
  • Loading branch information
ing-eoking committed Jan 15, 2025
1 parent 3499c5e commit 3d7b14a
Showing 1 changed file with 9 additions and 53 deletions.
62 changes: 9 additions & 53 deletions libmemcached/fetch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,73 +63,29 @@ char *memcached_fetch(memcached_st *ptr, char *key, size_t *key_length,
if (not error)
error= &unused;


unlikely (ptr->flags.use_udp)
{
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;
}

result_buffer= memcached_fetch_result(ptr, result_buffer, error);
if (result_buffer == NULL or memcached_failed(*error))
if (result_buffer == NULL || result_buffer->key_length > MEMCACHED_MAX_KEY)
{
WATCHPOINT_ASSERT(result_buffer == NULL);
if (value_length)
*value_length= 0;

if (key_length)
*key_length= 0;

if (flags)
*flags= 0;
*error= (result_buffer != NULL) ? MEMCACHED_KEY_TOO_BIG : *error;

if (key)
*key= 0;
if (key) *key= 0;
if (key_length) *key_length= 0;
if (value_length) *value_length= 0;
if (flags) *flags= 0;

return NULL;
}

if (value_length)
{
*value_length= memcached_string_length(&result_buffer->value);
}

if (key)
{
if (result_buffer->key_length > MEMCACHED_MAX_KEY)
{
*error= MEMCACHED_KEY_TOO_BIG;
if (value_length)
*value_length= 0;

if (key_length)
*key_length= 0;

if (flags)
*flags= 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 (value_length)
*value_length= memcached_string_length(&result_buffer->value);

if (flags)
*flags= result_buffer->item_flags;

Expand Down

0 comments on commit 3d7b14a

Please sign in to comment.