*
*/
-#include "libmemcached/common.h"
-#include <iostream>
+#include <libmemcached/common.h>
+#include <cassert>
/*
What happens if no servers exist?
{
unlikely (ptr->flags.use_udp)
{
- *error= MEMCACHED_NOT_SUPPORTED;
+ if (value_length)
+ *value_length= 0;
+
+ *error= memcached_set_error(*ptr, MEMCACHED_NOT_SUPPORTED, MEMCACHED_AT);
return NULL;
}
+ uint64_t query_id= ptr->query_id;
+ (void)query_id;
+
/* Request the key */
*error= memcached_mget_by_key_real(ptr, group_key, group_key_length,
(const char * const *)&key,
&key_length, 1, false);
+ assert(ptr->query_id == query_id +1);
+
+
+ if (memcached_failed(*error))
+ {
+ if (memcached_has_current_error(*ptr)) // Find the most accurate error
+ {
+ *error= memcached_last_error(ptr);
+ }
+
+ if (value_length)
+ *value_length= 0;
+
+ return NULL;
+ }
char *value= memcached_fetch(ptr, NULL, NULL,
value_length, flags, error);
+ assert(ptr->query_id == query_id +1);
+
/* This is for historical reasons */
if (*error == MEMCACHED_END)
*error= MEMCACHED_NOTFOUND;
}
}
}
+ assert(ptr->query_id == query_id +1);
return NULL;
}
&dummy_error);
WATCHPOINT_ASSERT(dummy_length == 0);
WATCHPOINT_ASSERT(dummy_value == 0);
+ assert(ptr->query_id == query_id +1);
return value;
}
const char *get_command= "get ";
uint8_t get_command_length= 4;
unsigned int master_server_key= (unsigned int)-1; /* 0 is a valid server id! */
- bool is_group_key_set= false;
memcached_return_t rc;
if (memcached_failed(rc= initialize_query(ptr)))
}
unlikely (ptr->flags.use_udp)
- return MEMCACHED_NOT_SUPPORTED;
+ {
+ return memcached_set_error(*ptr, MEMCACHED_NOT_SUPPORTED, MEMCACHED_AT);
+ }
LIBMEMCACHED_MEMCACHED_MGET_START();
if (number_of_keys == 0)
- return MEMCACHED_NOTFOUND;
+ {
+ return memcached_set_error(*ptr, MEMCACHED_NOTFOUND, MEMCACHED_AT, memcached_literal_param("number_of_keys was zero"));
+ }
if (ptr->flags.verify_key && (memcached_key_test(keys, key_length, number_of_keys) == MEMCACHED_BAD_KEY_PROVIDED))
{
- return MEMCACHED_BAD_KEY_PROVIDED;
+ return memcached_set_error(*ptr, MEMCACHED_BAD_KEY_PROVIDED, MEMCACHED_AT, memcached_literal_param("A bad key value was provided"));
}
+ bool is_group_key_set= false;
if (group_key && group_key_length)
{
if (ptr->flags.verify_key and (memcached_key_test((const char * const *)&group_key, &group_key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED))
- return MEMCACHED_BAD_KEY_PROVIDED;
+ {
+ return memcached_set_error(*ptr, MEMCACHED_BAD_KEY_PROVIDED, MEMCACHED_AT, memcached_literal_param("A bad group key was provided."));
+ }
master_server_key= memcached_generate_hash_with_redistribution(ptr, group_key, group_key_length);
is_group_key_set= true;
{
rc= memcached_connect(instance);
- if (rc != MEMCACHED_SUCCESS)
+ if (memcached_failed(rc))
{
+ memcached_set_error(*instance, rc, MEMCACHED_AT);
continue;
}
hosts_connected++;
{
LIBMEMCACHED_MEMCACHED_MGET_END();
- if (rc != MEMCACHED_SUCCESS)
+ if (memcached_failed(rc))
return rc;
- return MEMCACHED_NO_SERVERS;
+ return memcached_set_error(*ptr, MEMCACHED_NO_SERVERS, MEMCACHED_AT);
}
LIBMEMCACHED_MEMCACHED_MGET_END();
if (failures_occured_in_sending && success_happened)
+ {
return MEMCACHED_SOME_ERRORS;
+ }
if (success_happened)
return MEMCACHED_SUCCESS;
- return MEMCACHED_FAILURE;
+ return MEMCACHED_FAILURE; // Complete failure occurred
}
memcached_return_t memcached_mget_by_key(memcached_st *ptr,
for (uint32_t x= 0; x < number_of_keys; ++x)
{
uint32_t server_key;
- memcached_server_write_instance_st instance;
if (is_group_key_set)
{
server_key= memcached_generate_hash_with_redistribution(ptr, keys[x], key_length[x]);
}
- instance= memcached_server_instance_fetch(ptr, server_key);
+ memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, server_key);
if (memcached_server_response_count(instance) == 0)
{
rc= memcached_connect(instance);
- if (rc != MEMCACHED_SUCCESS)
+ if (memcached_failed(rc))
continue;
}
if (ptr->write_buffer_offset == buffer_end && ptr->type != MEMCACHED_CONNECTION_UDP)
{
- memcached_return_t rc;
- ssize_t sent_length;
-
WATCHPOINT_ASSERT(ptr->fd != INVALID_SOCKET);
- sent_length= io_flush(ptr, with_flush, &rc);
+
+ memcached_return_t rc;
+ ssize_t sent_length= io_flush(ptr, with_flush, &rc);
if (sent_length == -1)
{
return -1;
rc= io_wait(ptr, MEM_WRITE);
if (rc == MEMCACHED_SUCCESS || rc == MEMCACHED_TIMEOUT)
+ {
continue;
+ }
memcached_quit_server(ptr, true);
return -1;
case EPIPE:
default:
memcached_quit_server(ptr, true);
- *error= MEMCACHED_ERRNO;
+ *error= memcached_set_errno(*ptr, get_socket_errno(), MEMCACHED_AT);
WATCHPOINT_ASSERT(ptr->fd == -1);
return -1;
}
memcached_return_t rc= memcached_io_read(ptr, data + offset, size - offset,
&nread);
if (rc != MEMCACHED_SUCCESS)
+ {
return rc;
+ }
offset+= (size_t) nread;
}
ssize_t nread;
memcached_return_t rc= memcached_io_read(ptr, buffer_ptr, 1, &nread);
if (rc != MEMCACHED_SUCCESS)
+ {
return rc;
+ }
if (*buffer_ptr == '\n')
line_complete= true;
#define BUILDING_LIBMEMCACHED
// !NEVER use common.h, always use memcached.h in your own apps
#include <libmemcached/common.h>
+#include <libmemcached/util.h>
#include "tests/parser.h"
#include "tests/print.h"
test_return_t regression_bug_71231153(memcached_st *)
{
- if (1) return TEST_SKIPPED;
+ if (libmemcached_util_ping("10.0.2.252", 0, NULL)) // If for whatever reason someone has a host at this address, skip
+ return TEST_SKIPPED;
memcached_st *memc= memcached(memcached_literal_param("--SERVER=10.0.2.252 --CONNECT-TIMEOUT=1 --POLL-TIMEOUT=1"));
test_true(memc);
memcached_return_t rc;
size_t value_len;
- char *value= memcached_get(memc, "test", 4, &value_len, NULL, &rc);
+ char *value= memcached_get(memc, memcached_literal_param("test"), &value_len, NULL, &rc);
test_false(value);
- test_compare_got(MEMCACHED_TIMEOUT, rc, memcached_last_error_message(memc));
+ test_compare(0, value_len);
+ test_true_got(rc == MEMCACHED_TIMEOUT or rc == MEMCACHED_FAILURE or rc == MEMCACHED_ERRNO, memcached_strerror(memc, rc));
memcached_free(memc);