size_t send_length;
memcached_return_t rc;
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
- unsigned int server_key;
+ uint32_t server_key;
+ memcached_server_instance_st *instance;
bool no_reply= ptr->flags.no_reply;
unlikely (ptr->hosts == NULL || memcached_server_count(ptr) == 0)
return MEMCACHED_BAD_KEY_PROVIDED;
server_key= memcached_generate_hash(ptr, master_key, master_key_length);
+ instance= memcached_server_instance_fetch(ptr, server_key);
send_length= (size_t)snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
"%s %s%.*s %" PRIu64 "%s\r\n", verb,
unlikely (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
return MEMCACHED_WRITE_FAILURE;
- rc= memcached_do(&ptr->hosts[server_key], buffer, send_length, 1);
+ rc= memcached_do(instance, buffer, send_length, 1);
if (no_reply || rc != MEMCACHED_SUCCESS)
return rc;
- rc= memcached_response(&ptr->hosts[server_key], buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
+ rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
/*
So why recheck responce? Because the protocol is brain dead :)
uint32_t expiration,
uint64_t *value)
{
- unsigned int server_key;
+ uint32_t server_key;
+ memcached_server_instance_st *instance;
bool no_reply= ptr->flags.no_reply;
unlikely (ptr->hosts == NULL || memcached_server_count(ptr) == 0)
return MEMCACHED_NO_SERVERS;
server_key= memcached_generate_hash(ptr, master_key, master_key_length);
+ instance= memcached_server_instance_fetch(ptr, server_key);
if (no_reply)
{
request.message.body.initial= htonll(initial);
request.message.body.expiration= htonl((uint32_t) expiration);
- if ((memcached_do(&ptr->hosts[server_key], request.bytes,
+ if ((memcached_do(instance, request.bytes,
sizeof(request.bytes), 0)!=MEMCACHED_SUCCESS) ||
- (memcached_io_write(&ptr->hosts[server_key], key, key_length, 1) == -1))
+ (memcached_io_write(instance, key, key_length, 1) == -1))
{
- memcached_io_reset(&ptr->hosts[server_key]);
+ memcached_io_reset(instance);
return MEMCACHED_WRITE_FAILURE;
}
if (no_reply)
return MEMCACHED_SUCCESS;
- return memcached_response(&ptr->hosts[server_key], (char*)value, sizeof(*value), NULL);
+ return memcached_response(instance, (char*)value, sizeof(*value), NULL);
}
memcached_return_t memcached_increment(memcached_st *ptr,
#include "libmemcached/memcached.h"
#include "libmemcached/watchpoint.h"
+typedef struct memcached_server_st memcached_server_instance_st;
+
/* These are private not to be installed headers */
#include "libmemcached/io.h"
#include "libmemcached/internal.h"
#include "libmemcached/libmemcached_probes.h"
#include "libmemcached/memcached/protocol_binary.h"
#include "libmemcached/byteorder.h"
+#include "libmemcached/response.h"
/* string value */
struct memcached_continuum_item_st
uint32_t jenkins_hash(const void *key, size_t length, uint32_t initval);
LIBMEMCACHED_LOCAL
-memcached_return_t memcached_connect(memcached_server_st *ptr);
-LIBMEMCACHED_LOCAL
-memcached_return_t memcached_response(memcached_server_st *ptr,
- char *buffer, size_t buffer_length,
- memcached_result_st *result);
+memcached_return_t memcached_connect(memcached_server_instance_st *ptr);
LIBMEMCACHED_LOCAL
-void memcached_quit_server(memcached_server_st *ptr, uint8_t io_death);
+void memcached_quit_server(memcached_server_instance_st *ptr, uint8_t io_death);
#define memcached_server_response_increment(A) (A)->cursor_active++
#define memcached_server_response_decrement(A) (A)->cursor_active--
#define memcached_server_response_reset(A) (A)->cursor_active=0
LIBMEMCACHED_LOCAL
-memcached_return_t memcached_do(memcached_server_st *ptr, const void *commmand,
+memcached_return_t memcached_do(memcached_server_instance_st *ptr, const void *commmand,
size_t command_length, uint8_t with_flush);
LIBMEMCACHED_LOCAL
-memcached_return_t value_fetch(memcached_server_st *ptr,
+memcached_return_t value_fetch(memcached_server_instance_st *ptr,
char *buffer,
memcached_result_st *result);
LIBMEMCACHED_LOCAL
-void server_list_free(memcached_st *ptr, memcached_server_st *servers);
+void server_list_free(memcached_st *ptr, memcached_server_instance_st *servers);
LIBMEMCACHED_LOCAL
memcached_return_t memcached_key_test(const char * const *keys,
uint32_t generate_hash(memcached_st *ptr, const char *key, size_t key_length);
LIBMEMCACHED_LOCAL
-memcached_return_t memcached_purge(memcached_server_st *ptr);
+memcached_return_t memcached_purge(memcached_server_instance_st *ptr);
static inline memcached_return_t memcached_validate_key_length(size_t key_length, bool binary)
{
}
static inline memcached_return_t binary_delete(memcached_st *ptr,
- unsigned int server_key,
+ uint32_t server_key,
const char *key,
size_t key_length,
uint8_t flush);
size_t send_length;
memcached_return_t rc;
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
- unsigned int server_key;
+ uint32_t server_key;
+ memcached_server_instance_st *instance;
LIBMEMCACHED_MEMCACHED_DELETE_START();
return MEMCACHED_NO_SERVERS;
server_key= memcached_generate_hash(ptr, master_key, master_key_length);
+ instance= memcached_server_instance_fetch(ptr, server_key);
+
to_write= (uint8_t)((ptr->flags.buffer_requests) ? 0 : 1);
+
bool no_reply= (ptr->flags.no_reply);
if (ptr->flags.binary_protocol)
{
likely (!expiration)
+ {
rc= binary_delete(ptr, server_key, key, key_length, to_write);
+ }
else
+ {
rc= MEMCACHED_INVALID_ARGUMENTS;
+ }
}
else
{
unlikely (expiration)
{
- if ((ptr->hosts[server_key].major_version == 1 &&
- ptr->hosts[server_key].minor_version > 2) ||
- ptr->hosts[server_key].major_version > 1)
+ if ((instance->major_version == 1 &&
+ instance->minor_version > 2) ||
+ instance->major_version > 1)
{
rc= MEMCACHED_INVALID_ARGUMENTS;
goto error;
{
/* ensure that we are connected, otherwise we might bump the
* command counter before connection */
- if ((rc= memcached_connect(&ptr->hosts[server_key])) != MEMCACHED_SUCCESS)
+ if ((rc= memcached_connect(instance)) != MEMCACHED_SUCCESS)
{
WATCHPOINT_ERROR(rc);
return rc;
}
- if (ptr->hosts[server_key].minor_version == 0)
+ if (instance->minor_version == 0)
{
if (no_reply || !to_write)
{
*/
to_write= 1;
if (no_reply)
- memcached_server_response_increment(&ptr->hosts[server_key]);
+ memcached_server_response_increment(instance);
no_reply= false;
}
}
{
if (send_length > MAX_UDP_DATAGRAM_LENGTH - UDP_DATAGRAM_HEADER_LENGTH)
return MEMCACHED_WRITE_FAILURE;
- if (send_length + ptr->hosts[server_key].write_buffer_offset > MAX_UDP_DATAGRAM_LENGTH)
- memcached_io_write(&ptr->hosts[server_key], NULL, 0, 1);
+ if (send_length + instance->write_buffer_offset > MAX_UDP_DATAGRAM_LENGTH)
+ memcached_io_write(instance, NULL, 0, 1);
}
- rc= memcached_do(&ptr->hosts[server_key], buffer, send_length, to_write);
+ rc= memcached_do(instance, buffer, send_length, to_write);
}
if (rc != MEMCACHED_SUCCESS)
rc= MEMCACHED_BUFFERED;
else if (!no_reply)
{
- rc= memcached_response(&ptr->hosts[server_key], buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
+ rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
if (rc == MEMCACHED_DELETED)
rc= MEMCACHED_SUCCESS;
}
}
static inline memcached_return_t binary_delete(memcached_st *ptr,
- unsigned int server_key,
+ uint32_t server_key,
const char *key,
size_t key_length,
uint8_t flush)
{
+ memcached_server_instance_st *instance;
protocol_binary_request_delete request= {.bytes= {0}};
+ instance= memcached_server_instance_fetch(ptr, server_key);
+
request.message.header.request.magic= PROTOCOL_BINARY_REQ;
if (ptr->flags.no_reply)
request.message.header.request.opcode= PROTOCOL_BINARY_CMD_DELETEQ;
size_t cmd_size= sizeof(request.bytes) + key_length;
if (cmd_size > MAX_UDP_DATAGRAM_LENGTH - UDP_DATAGRAM_HEADER_LENGTH)
return MEMCACHED_WRITE_FAILURE;
- if (cmd_size + ptr->hosts[server_key].write_buffer_offset > MAX_UDP_DATAGRAM_LENGTH)
- memcached_io_write(&ptr->hosts[server_key], NULL, 0, 1);
+ if (cmd_size + instance->write_buffer_offset > MAX_UDP_DATAGRAM_LENGTH)
+ memcached_io_write(instance, NULL, 0, 1);
}
memcached_return_t rc= MEMCACHED_SUCCESS;
- if ((memcached_do(&ptr->hosts[server_key], request.bytes,
+ if ((memcached_do(instance, request.bytes,
sizeof(request.bytes), 0) != MEMCACHED_SUCCESS) ||
- (memcached_io_write(&ptr->hosts[server_key], key,
+ (memcached_io_write(instance, key,
key_length, (char) flush) == -1))
{
- memcached_io_reset(&ptr->hosts[server_key]);
+ memcached_io_reset(instance);
rc= MEMCACHED_WRITE_FAILURE;
}
for (uint32_t x= 0; x < ptr->number_of_replicas; ++x)
{
+ memcached_server_instance_st *replica;
+
++server_key;
if (server_key == memcached_server_count(ptr))
server_key= 0;
- memcached_server_st* server= &ptr->hosts[server_key];
- if ((memcached_do(server, (const char*)request.bytes,
+ replica= memcached_server_instance_fetch(ptr, server_key);
+
+ if ((memcached_do(replica, (const char*)request.bytes,
sizeof(request.bytes), 0) != MEMCACHED_SUCCESS) ||
- (memcached_io_write(server, key, key_length, (char) flush) == -1))
- memcached_io_reset(server);
+ (memcached_io_write(replica, key, key_length, (char) flush) == -1))
+ {
+ memcached_io_reset(replica);
+ }
else
- memcached_server_response_decrement(server);
+ {
+ memcached_server_response_decrement(replica);
+ }
}
}
for (server_key= 0; server_key < memcached_server_count(ptr); server_key++)
{
+ memcached_server_instance_st *instance;
+ instance= memcached_server_instance_fetch(ptr, server_key);
+
/* 256 I BELIEVE is the upper limit of slabs */
for (x= 0; x < 256; x++)
{
send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
"stats cachedump %u 0 0\r\n", x);
- rc= memcached_do(&ptr->hosts[server_key], buffer, send_length, 1);
+ rc= memcached_do(instance, buffer, send_length, 1);
unlikely (rc != MEMCACHED_SUCCESS)
goto error;
while (1)
{
uint32_t callback_counter;
- rc= memcached_response(&ptr->hosts[server_key], buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
+ rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
if (rc == MEMCACHED_ITEM)
{
}
static memcached_return_t binary_mget_by_key(memcached_st *ptr,
- unsigned int master_server_key,
+ uint32_t master_server_key,
bool is_master_key_set,
const char * const *keys,
const size_t *key_length,
*/
for (x= 0; x < number_of_keys; x++)
{
- unsigned int server_key;
+ memcached_server_instance_st *instance;
+ uint32_t server_key;
if (is_master_key_set)
+ {
server_key= master_server_key;
+ }
else
+ {
server_key= memcached_generate_hash(ptr, keys[x], key_length[x]);
+ }
- if (memcached_server_response_count(&ptr->hosts[server_key]) == 0)
+ instance= memcached_server_instance_fetch(ptr, server_key);
+
+ if (memcached_server_response_count(instance) == 0)
{
- rc= memcached_connect(&ptr->hosts[server_key]);
+ rc= memcached_connect(instance);
if (rc != MEMCACHED_SUCCESS)
continue;
- if ((memcached_io_write(&ptr->hosts[server_key], get_command, get_command_length, 0)) == -1)
+ if ((memcached_io_write(instance, get_command, get_command_length, 0)) == -1)
{
rc= MEMCACHED_SOME_ERRORS;
continue;
}
- WATCHPOINT_ASSERT(ptr->hosts[server_key].cursor_active == 0);
- memcached_server_response_increment(&ptr->hosts[server_key]);
- WATCHPOINT_ASSERT(ptr->hosts[server_key].cursor_active == 1);
+ WATCHPOINT_ASSERT(instance->cursor_active == 0);
+ memcached_server_response_increment(instance);
+ WATCHPOINT_ASSERT(instance->cursor_active == 1);
}
/* Only called when we have a prefix key */
if (ptr->prefix_key[0] != 0)
{
- if ((memcached_io_write(&ptr->hosts[server_key], ptr->prefix_key, ptr->prefix_key_length, 0)) == -1)
+ if ((memcached_io_write(instance, ptr->prefix_key, ptr->prefix_key_length, 0)) == -1)
{
- memcached_server_response_reset(&ptr->hosts[server_key]);
+ memcached_server_response_reset(instance);
rc= MEMCACHED_SOME_ERRORS;
continue;
}
}
- if ((memcached_io_write(&ptr->hosts[server_key], keys[x], key_length[x], 0)) == -1)
+ if ((memcached_io_write(instance, keys[x], key_length[x], 0)) == -1)
{
- memcached_server_response_reset(&ptr->hosts[server_key]);
+ memcached_server_response_reset(instance);
rc= MEMCACHED_SOME_ERRORS;
continue;
}
- if ((memcached_io_write(&ptr->hosts[server_key], " ", 1, 0)) == -1)
+ if ((memcached_io_write(instance, " ", 1, 0)) == -1)
{
- memcached_server_response_reset(&ptr->hosts[server_key]);
+ memcached_server_response_reset(instance);
rc= MEMCACHED_SOME_ERRORS;
continue;
}
}
static memcached_return_t simple_binary_mget(memcached_st *ptr,
- unsigned int master_server_key,
+ uint32_t master_server_key,
bool is_master_key_set,
const char * const *keys,
const size_t *key_length,
*/
for (x= 0; x < number_of_keys; x++)
{
- unsigned int server_key;
+ uint32_t server_key;
+ memcached_server_instance_st *instance;
if (is_master_key_set)
+ {
server_key= master_server_key;
+ }
else
+ {
server_key= memcached_generate_hash(ptr, keys[x], key_length[x]);
+ }
+
+ instance= memcached_server_instance_fetch(ptr, server_key);
- if (memcached_server_response_count(&ptr->hosts[server_key]) == 0)
+ if (memcached_server_response_count(instance) == 0)
{
- rc= memcached_connect(&ptr->hosts[server_key]);
+ rc= memcached_connect(instance);
if (rc != MEMCACHED_SUCCESS)
continue;
}
unlikely (vk != MEMCACHED_SUCCESS)
{
if (x > 0)
- memcached_io_reset(&ptr->hosts[server_key]);
+ {
+ memcached_io_reset(instance);
+ }
+
return vk;
}
request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
request.message.header.request.bodylen= htonl((uint32_t) key_length[x]);
- if ((memcached_io_write(&ptr->hosts[server_key], request.bytes,
+ if ((memcached_io_write(instance, request.bytes,
sizeof(request.bytes), 0) == -1) ||
- (memcached_io_write(&ptr->hosts[server_key], keys[x],
+ (memcached_io_write(instance, keys[x],
key_length[x], (char) flush) == -1))
{
- memcached_server_response_reset(&ptr->hosts[server_key]);
+ memcached_server_response_reset(instance);
rc= MEMCACHED_SOME_ERRORS;
continue;
}
/* We just want one pending response per server */
- memcached_server_response_reset(&ptr->hosts[server_key]);
- memcached_server_response_increment(&ptr->hosts[server_key]);
+ memcached_server_response_reset(instance);
+ memcached_server_response_increment(instance);
if ((x > 0 && x == ptr->io_key_prefetch) &&
memcached_flush_buffers(ptr) != MEMCACHED_SUCCESS)
rc= MEMCACHED_SOME_ERRORS;
}
static memcached_return_t binary_mget_by_key(memcached_st *ptr,
- unsigned int master_server_key,
+ uint32_t master_server_key,
bool is_master_key_set,
const char * const *keys,
const size_t *key_length,
static int compare_servers(const void *p1, const void *p2)
{
int return_value;
- memcached_server_st *a= (memcached_server_st *)p1;
- memcached_server_st *b= (memcached_server_st *)p2;
+ memcached_server_instance_st *a= (memcached_server_instance_st *)p1;
+ memcached_server_instance_st *b= (memcached_server_instance_st *)p2;
return_value= strcmp(a->hostname, b->hostname);
{
if (memcached_server_count(ptr))
{
- qsort(ptr->hosts, memcached_server_count(ptr), sizeof(memcached_server_st), compare_servers);
+ qsort(ptr->hosts, memcached_server_count(ptr), sizeof(memcached_server_instance_st), compare_servers);
ptr->hosts[0].number_of_hosts= memcached_server_count(ptr);
}
}
uint32_t host_index;
uint32_t continuum_index= 0;
uint32_t value;
- memcached_server_st *list;
+ memcached_server_instance_st *list;
uint32_t pointer_index;
uint32_t pointer_counter= 0;
uint32_t pointer_per_server= MEMCACHED_POINTS_PER_SERVER;
memcached_return_t memcached_server_push(memcached_st *ptr, memcached_server_st *list)
{
- unsigned int x;
- uint16_t count;
- memcached_server_st *new_host_list;
+ uint32_t x;
+ uint32_t count;
+ memcached_server_instance_st *new_host_list;
- if (!list)
+ if (! list)
return MEMCACHED_SUCCESS;
count= memcached_servers_count(list);
new_host_list= ptr->call_realloc(ptr, ptr->hosts,
- sizeof(memcached_server_st) * (count + memcached_server_count(ptr)));
+ sizeof(memcached_server_instance_st) * (count + memcached_server_count(ptr)));
if (! new_host_list)
return MEMCACHED_MEMORY_ALLOCATION_FAILURE;
const char *filename,
uint32_t weight)
{
- if (!filename)
+ if (! filename)
return MEMCACHED_FAILURE;
return server_add(ptr, filename, 0, weight, MEMCACHED_CONNECTION_UNIX_SOCKET);
in_port_t port,
uint32_t weight)
{
- if (!port)
+ if (! port)
port= MEMCACHED_DEFAULT_PORT;
- if (!hostname)
+ if (! hostname)
hostname= "localhost";
return server_add(ptr, hostname, port, weight, MEMCACHED_CONNECTION_UDP);
in_port_t port,
uint32_t weight)
{
- if (!port)
+ if (! port)
port= MEMCACHED_DEFAULT_PORT;
- if (!hostname)
+ if (! hostname)
hostname= "localhost";
return server_add(ptr, hostname, port, weight, MEMCACHED_CONNECTION_TCP);
uint32_t weight,
memcached_connection_t type)
{
- memcached_server_st *new_host_list;
+ memcached_server_instance_st *new_host_list;
if ( (ptr->flags.use_udp && type != MEMCACHED_CONNECTION_UDP)
|| ( (type == MEMCACHED_CONNECTION_UDP) && (! ptr->flags.use_udp) ) )
return MEMCACHED_INVALID_HOST_PROTOCOL;
new_host_list= ptr->call_realloc(ptr, ptr->hosts,
- sizeof(memcached_server_st) * (ptr->number_of_hosts + 1));
+ sizeof(memcached_server_instance_st) * (ptr->number_of_hosts + 1));
if (new_host_list == NULL)
return MEMCACHED_MEMORY_ALLOCATION_FAILURE;
memcached_return_t *error)
{
unsigned int count;
- memcached_server_st *new_host_list;
+ memcached_server_instance_st *new_host_list;
if (hostname == NULL || error == NULL)
return NULL;
- if (!port)
+ if (! port)
port= MEMCACHED_DEFAULT_PORT;
/* Increment count for hosts */
count+= memcached_servers_count(ptr);
}
- new_host_list= (memcached_server_st *)realloc(ptr, sizeof(memcached_server_st) * count);
+ new_host_list= (memcached_server_instance_st *)realloc(ptr, sizeof(memcached_server_instance_st) * count);
if (!new_host_list)
{
*error= MEMCACHED_MEMORY_ALLOCATION_FAILURE;
noinst_HEADERS+= \
libmemcached/byteorder.h \
- libmemcached/libmemcached_probes.h \
- libmemcached/io.h \
- libmemcached/internal.h \
libmemcached/common.h \
- libmemcached/protocol/common.h \
+ libmemcached/internal.h \
+ libmemcached/io.h \
+ libmemcached/libmemcached_probes.h \
libmemcached/protocol/ascii_handler.h \
- libmemcached/protocol/binary_handler.h
+ libmemcached/protocol/binary_handler.h \
+ libmemcached/protocol/common.h \
+ libmemcached/response.h
nobase_include_HEADERS+= \
libmemcached/analyze.h \
MEM_WRITE
} memc_read_or_write;
-static ssize_t io_flush(memcached_server_st *ptr, memcached_return_t *error);
-static void increment_udp_message_id(memcached_server_st *ptr);
+static ssize_t io_flush(memcached_server_instance_st *ptr, memcached_return_t *error);
+static void increment_udp_message_id(memcached_server_instance_st *ptr);
-static memcached_return_t io_wait(memcached_server_st *ptr,
+static memcached_return_t io_wait(memcached_server_instance_st *ptr,
memc_read_or_write read_or_write)
{
struct pollfd fds= {
*
* @param ptr the server to pack
*/
-static bool repack_input_buffer(memcached_server_st *ptr)
+static bool repack_input_buffer(memcached_server_instance_st *ptr)
{
if (ptr->read_ptr != ptr->read_buffer)
{
* @param ptr the server to star processing iput messages for
* @return true if we processed anything, false otherwise
*/
-static bool process_input_buffer(memcached_server_st *ptr)
+static bool process_input_buffer(memcached_server_instance_st *ptr)
{
/*
** We might be able to process some of the response messages if we
}
#endif
-memcached_return_t memcached_io_read(memcached_server_st *ptr,
+memcached_return_t memcached_io_read(memcached_server_instance_st *ptr,
void *buffer, size_t length, ssize_t *nread)
{
char *buffer_ptr;
return MEMCACHED_SUCCESS;
}
-ssize_t memcached_io_write(memcached_server_st *ptr,
+ssize_t memcached_io_write(memcached_server_instance_st *ptr,
const void *buffer, size_t length, char with_flush)
{
size_t original_length;
return (ssize_t) original_length;
}
-memcached_return_t memcached_io_close(memcached_server_st *ptr)
+memcached_return_t memcached_io_close(memcached_server_instance_st *ptr)
{
if (ptr->fd == -1)
{
return MEMCACHED_SUCCESS;
}
-memcached_server_st *memcached_io_get_readable_server(memcached_st *memc)
+memcached_server_instance_st *memcached_io_get_readable_server(memcached_st *memc)
{
#define MAX_SERVERS_TO_POLL 100
struct pollfd fds[MAX_SERVERS_TO_POLL];
return NULL;
}
-static ssize_t io_flush(memcached_server_st *ptr,
+static ssize_t io_flush(memcached_server_instance_st *ptr,
memcached_return_t *error)
{
/*
/*
Eventually we will just kill off the server with the problem.
*/
-void memcached_io_reset(memcached_server_st *ptr)
+void memcached_io_reset(memcached_server_instance_st *ptr)
{
memcached_quit_server(ptr, 1);
}
* Read a given number of bytes from the server and place it into a specific
* buffer. Reset the IO channel on this server if an error occurs.
*/
-memcached_return_t memcached_safe_read(memcached_server_st *ptr,
+memcached_return_t memcached_safe_read(memcached_server_instance_st *ptr,
void *dta,
size_t size)
{
return MEMCACHED_SUCCESS;
}
-memcached_return_t memcached_io_readline(memcached_server_st *ptr,
+memcached_return_t memcached_io_readline(memcached_server_instance_st *ptr,
char *buffer_ptr,
size_t size)
{
* extracts the message number from message_id, increments it and then
* writes the new value back into the header
*/
-static void increment_udp_message_id(memcached_server_st *ptr)
+static void increment_udp_message_id(memcached_server_instance_st *ptr)
{
struct udp_datagram_header_st *header= (struct udp_datagram_header_st *)ptr->write_buffer;
uint16_t cur_req= get_udp_datagram_request_id(header);
header->request_id= htons((uint16_t) (thread_id | msg_num));
}
-memcached_return_t memcached_io_init_udp_header(memcached_server_st *ptr, uint16_t thread_id)
+memcached_return_t memcached_io_init_udp_header(memcached_server_instance_st *ptr, uint16_t thread_id)
{
if (thread_id > UDP_REQUEST_ID_MAX_THREAD_ID)
return MEMCACHED_FAILURE;
};
LIBMEMCACHED_LOCAL
-ssize_t memcached_io_write(memcached_server_st *ptr,
+ssize_t memcached_io_write(memcached_server_instance_st *ptr,
const void *buffer, size_t length, char with_flush);
LIBMEMCACHED_LOCAL
-void memcached_io_reset(memcached_server_st *ptr);
+void memcached_io_reset(memcached_server_instance_st *ptr);
LIBMEMCACHED_LOCAL
-memcached_return_t memcached_io_read(memcached_server_st *ptr,
+memcached_return_t memcached_io_read(memcached_server_instance_st *ptr,
void *buffer, size_t length, ssize_t *nread);
/* Read a line (terminated by '\n') into the buffer */
LIBMEMCACHED_LOCAL
-memcached_return_t memcached_io_readline(memcached_server_st *ptr,
+memcached_return_t memcached_io_readline(memcached_server_instance_st *ptr,
char *buffer_ptr,
size_t size);
LIBMEMCACHED_LOCAL
-memcached_return_t memcached_io_close(memcached_server_st *ptr);
+memcached_return_t memcached_io_close(memcached_server_instance_st *ptr);
/* Read n bytes of data from the server and store them in dta */
LIBMEMCACHED_LOCAL
-memcached_return_t memcached_safe_read(memcached_server_st *ptr,
+memcached_return_t memcached_safe_read(memcached_server_instance_st *ptr,
void *dta,
size_t size);
-/* Read a single response from the server */
LIBMEMCACHED_LOCAL
-memcached_return_t memcached_read_one_response(memcached_server_st *ptr,
- char *buffer, size_t buffer_length,
- memcached_result_st *result);
-
-LIBMEMCACHED_LOCAL
-memcached_return_t memcached_io_init_udp_header(memcached_server_st *ptr,
+memcached_return_t memcached_io_init_udp_header(memcached_server_instance_st *ptr,
uint16_t thread_id);
LIBMEMCACHED_LOCAL
-memcached_server_st *memcached_io_get_readable_server(memcached_st *memc);
+memcached_server_instance_st *memcached_io_get_readable_server(memcached_st *memc);
#endif /* BUILDING_LIBMEMCACHED */
LIBMEMCACHED_API
void memcached_servers_reset(memcached_st *ptr);
+// Local Only Inline
+static inline memcached_server_st *memcached_server_instance_fetch(memcached_st *ptr, uint32_t server_key)
+{
+ return &ptr->hosts[server_key];
+}
+
/* Public API */
LIBMEMCACHED_API
#include "common.h"
-memcached_return_t memcached_purge(memcached_server_st *ptr)
+memcached_return_t memcached_purge(memcached_server_instance_st *ptr)
{
uint32_t x;
memcached_return_t ret= MEMCACHED_SUCCESS;
-/*
- Memcached library
-
- memcached_response() is used to determine the return result
- from an issued command.
+/* LibMemcached
+ * Copyright (C) 2006-2009 Brian Aker
+ * All rights reserved.
+ *
+ * Use and distribution licensed under the BSD license. See
+ * the COPYING file in the parent directory for full text.
+ *
+ * Summary: memcached_response() is used to determine the return result from an issued command.
+ *
*/
#include "common.h"
-static memcached_return_t textual_read_one_response(memcached_server_st *ptr,
- char *buffer, size_t buffer_length,
- memcached_result_st *result);
-static memcached_return_t binary_read_one_response(memcached_server_st *ptr,
- char *buffer, size_t buffer_length,
- memcached_result_st *result);
+static memcached_return_t textual_read_one_response(memcached_server_instance_st *ptr,
+ char *buffer, size_t buffer_length,
+ memcached_result_st *result);
+static memcached_return_t binary_read_one_response(memcached_server_instance_st *ptr,
+ char *buffer, size_t buffer_length,
+ memcached_result_st *result);
-memcached_return_t memcached_read_one_response(memcached_server_st *ptr,
- char *buffer, size_t buffer_length,
- memcached_result_st *result)
+memcached_return_t memcached_read_one_response(memcached_server_instance_st *ptr,
+ char *buffer, size_t buffer_length,
+ memcached_result_st *result)
{
memcached_server_response_decrement(ptr);
rc == MEMCACHED_PROTOCOL_ERROR ||
rc == MEMCACHED_CLIENT_ERROR ||
rc == MEMCACHED_MEMORY_ALLOCATION_FAILURE)
- memcached_io_reset(ptr);
+ memcached_io_reset(ptr);
return rc;
}
-memcached_return_t memcached_response(memcached_server_st *ptr,
- char *buffer, size_t buffer_length,
- memcached_result_st *result)
+memcached_return_t memcached_response(memcached_server_instance_st *ptr,
+ char *buffer, size_t buffer_length,
+ memcached_result_st *result)
{
/* We may have old commands in the buffer not set, first purge */
if (ptr->root->flags.no_block)
* The previous implementation purged all pending requests and just
* returned the last one. Purge all pending messages to ensure backwards
* compatibility.
- */
+ */
if (ptr->root->flags.binary_protocol == false)
while (memcached_server_response_count(ptr) > 1)
{
memcached_return_t rc= memcached_read_one_response(ptr, buffer, buffer_length, result);
-
+
unlikely (rc != MEMCACHED_END &&
rc != MEMCACHED_STORED &&
rc != MEMCACHED_SUCCESS &&
rc != MEMCACHED_NOTFOUND &&
rc != MEMCACHED_NOTSTORED &&
rc != MEMCACHED_DATA_EXISTS)
- return rc;
+ return rc;
}
return memcached_read_one_response(ptr, buffer, buffer_length, result);
}
-static memcached_return_t textual_value_fetch(memcached_server_st *ptr,
- char *buffer,
- memcached_result_st *result)
+static memcached_return_t textual_value_fetch(memcached_server_instance_st *ptr,
+ char *buffer,
+ memcached_result_st *result)
{
memcached_return_t rc= MEMCACHED_SUCCESS;
char *string_ptr;
goto read_error;
}
-/* This next bit blows the API, but this is internal....*/
+ /* This next bit blows the API, but this is internal....*/
{
char *char_ptr;
char_ptr= memcached_string_value(&result->value);;
return MEMCACHED_PARTIAL_READ;
}
-static memcached_return_t textual_read_one_response(memcached_server_st *ptr,
- char *buffer, size_t buffer_length,
- memcached_result_st *result)
+static memcached_return_t textual_read_one_response(memcached_server_instance_st *ptr,
+ char *buffer, size_t buffer_length,
+ memcached_result_st *result)
{
memcached_return_t rc= memcached_io_readline(ptr, buffer, buffer_length);
if (rc != MEMCACHED_SUCCESS)
return MEMCACHED_STAT;
}
else if (buffer[1] == 'E') /* SERVER_ERROR */
- {
- char *rel_ptr;
- char *startptr= buffer + 13, *endptr= startptr;
-
- while (*endptr != '\r' && *endptr != '\n') endptr++;
-
- /*
- Yes, we could make this "efficent" but to do that we would need
- to maintain more state for the size of the buffer. Why waste
- memory in the struct, which is important, for something that
- rarely should happen?
- */
- rel_ptr= (char *)ptr->root->call_realloc(ptr->root,
- ptr->cached_server_error,
- (size_t) (endptr - startptr + 1));
-
- if (rel_ptr == NULL)
- {
- /* If we happened to have some memory, we just null it since we don't know the size */
- if (ptr->cached_server_error)
- ptr->cached_server_error[0]= 0;
- return MEMCACHED_SERVER_ERROR;
- }
- ptr->cached_server_error= rel_ptr;
-
- memcpy(ptr->cached_server_error, startptr, (size_t) (endptr - startptr));
- ptr->cached_server_error[endptr - startptr]= 0;
- return MEMCACHED_SERVER_ERROR;
- }
+ {
+ char *rel_ptr;
+ char *startptr= buffer + 13, *endptr= startptr;
+
+ while (*endptr != '\r' && *endptr != '\n') endptr++;
+
+ /*
+ Yes, we could make this "efficent" but to do that we would need
+ to maintain more state for the size of the buffer. Why waste
+ memory in the struct, which is important, for something that
+ rarely should happen?
+ */
+ rel_ptr= (char *)ptr->root->call_realloc(ptr->root,
+ ptr->cached_server_error,
+ (size_t) (endptr - startptr + 1));
+
+ if (rel_ptr == NULL)
+ {
+ /* If we happened to have some memory, we just null it since we don't know the size */
+ if (ptr->cached_server_error)
+ ptr->cached_server_error[0]= 0;
+ return MEMCACHED_SERVER_ERROR;
+ }
+ ptr->cached_server_error= rel_ptr;
+
+ memcpy(ptr->cached_server_error, startptr, (size_t) (endptr - startptr));
+ ptr->cached_server_error[endptr - startptr]= 0;
+ return MEMCACHED_SERVER_ERROR;
+ }
else if (buffer[1] == 'T')
return MEMCACHED_STORED;
else
return MEMCACHED_UNKNOWN_READ_FAILURE;
}
case 'I': /* CLIENT ERROR */
- /* We add back in one because we will need to search for END */
- memcached_server_response_increment(ptr);
+ /* We add back in one because we will need to search for END */
+ memcached_server_response_increment(ptr);
return MEMCACHED_ITEM;
case 'C': /* CLIENT ERROR */
return MEMCACHED_CLIENT_ERROR;
/* NOTREACHED */
}
-static memcached_return_t binary_read_one_response(memcached_server_st *ptr,
- char *buffer, size_t buffer_length,
- memcached_result_st *result)
+static memcached_return_t binary_read_one_response(memcached_server_instance_st *ptr,
+ char *buffer, size_t buffer_length,
+ memcached_result_st *result)
{
protocol_binary_response_header header;
-
+
unlikely (memcached_safe_read(ptr, &header.bytes,
sizeof(header.bytes)) != MEMCACHED_SUCCESS)
return MEMCACHED_UNKNOWN_READ_FAILURE;
return MEMCACHED_PROTOCOL_ERROR;
/*
- ** Convert the header to host local endian!
- */
+ ** Convert the header to host local endian!
+ */
header.response.keylen= ntohs(header.response.keylen);
header.response.status= ntohs(header.response.status);
header.response.bodylen= ntohl(header.response.bodylen);
}
else if (header.response.bodylen)
{
- /* What should I do with the error message??? just discard it for now */
+ /* What should I do with the error message??? just discard it for now */
char hole[SMALL_STRING_LEN];
while (bodylen > 0)
{
/* This might be an error from one of the quiet commands.. if
* so, just throw it away and get the next one. What about creating
* a callback to the user with the error information?
- */
+ */
switch (header.response.opcode)
{
case PROTOCOL_BINARY_CMD_SETQ:
rc= MEMCACHED_PROTOCOL_ERROR;
break;
}
-
+
return rc;
}
--- /dev/null
+/* LibMemcached
+ * Copyright (C) 2010 Brian Aker
+ * All rights reserved.
+ *
+ * Use and distribution licensed under the BSD license. See
+ * the COPYING file in the parent directory for full text.
+ *
+ * Summary: Change the behavior of the memcached connection.
+ *
+ */
+
+#ifndef __MEMCACHED_RESPONSE_H__
+#define __MEMCACHED_RESPONSE_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Read a single response from the server */
+LIBMEMCACHED_LOCAL
+memcached_return_t memcached_read_one_response(memcached_server_instance_st *ptr,
+ char *buffer, size_t buffer_length,
+ memcached_result_st *result);
+
+LIBMEMCACHED_LOCAL
+memcached_return_t memcached_response(memcached_server_instance_st *ptr,
+ char *buffer, size_t buffer_length,
+ memcached_result_st *result);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __MEMCACHED_RESPONSE_H__ */
memcached_server_st *memcached_server_by_key(memcached_st *ptr, const char *key, size_t key_length, memcached_return_t *error)
{
uint32_t server_key;
+ memcached_server_instance_st *instance;
*error= memcached_validate_key_length(key_length,
ptr->flags.binary_protocol);
}
server_key= memcached_generate_hash(ptr, key, key_length);
+ instance= memcached_server_instance_fetch(ptr, server_key);
- return memcached_server_clone(NULL, &ptr->hosts[server_key]);
+ return memcached_server_clone(NULL, instance);
}
char hostname[MEMCACHED_MAX_HOST_LENGTH];
};
+// Local Only Inline
static inline uint32_t memcached_servers_count(memcached_server_st *servers)
{
return servers->number_of_hosts;
}
+// Local Only Inline
static inline uint32_t memcached_servers_set_count(memcached_server_st *servers, uint32_t count)
{
return servers->number_of_hosts= count;
}
+
+
#define memcached_server_count(A) (A)->number_of_hosts
#define memcached_server_name(A,B) (B).hostname
#define memcached_server_port(A,B) (B).port
/* These should not currently be used by end users */
/* TODO: Is the above comment valid? If so, how can we unit test these if they
* aren't exported. If not, we should remove the comment */
-LIBMEMCACHED_API
+LIBMEMCACHED_LOCAL
memcached_server_st *memcached_server_create(memcached_st *memc, memcached_server_st *ptr);
-LIBMEMCACHED_API
+LIBMEMCACHED_LOCAL
memcached_server_st *memcached_server_create_with(memcached_st *memc,
memcached_server_st *host,
const char *hostname,
LIBMEMCACHED_API
void memcached_server_free(memcached_server_st *ptr);
-LIBMEMCACHED_API
+LIBMEMCACHED_LOCAL
memcached_server_st *memcached_server_clone(memcached_server_st *clone,
memcached_server_st *ptr);
return ret;
}
-static memcached_return_t binary_stats_fetch(memcached_st *ptr,
- memcached_stat_st *memc_stat,
+static memcached_return_t binary_stats_fetch(memcached_stat_st *memc_stat,
char *args,
- unsigned int server_key)
+ memcached_server_instance_st *instance)
{
memcached_return_t rc;
request.message.header.request.keylen= htons((uint16_t)len);
request.message.header.request.bodylen= htonl((uint32_t) len);
- if ((memcached_do(&ptr->hosts[server_key], request.bytes,
+ if ((memcached_do(instance, request.bytes,
sizeof(request.bytes), 0) != MEMCACHED_SUCCESS) ||
- (memcached_io_write(&ptr->hosts[server_key], args, len, 1) == -1))
+ (memcached_io_write(instance, args, len, 1) == -1))
{
- memcached_io_reset(&ptr->hosts[server_key]);
+ memcached_io_reset(instance);
return MEMCACHED_WRITE_FAILURE;
}
}
else
{
- if (memcached_do(&ptr->hosts[server_key], request.bytes,
+ if (memcached_do(instance, request.bytes,
sizeof(request.bytes), 1) != MEMCACHED_SUCCESS)
{
- memcached_io_reset(&ptr->hosts[server_key]);
+ memcached_io_reset(instance);
return MEMCACHED_WRITE_FAILURE;
}
}
- memcached_server_response_decrement(&ptr->hosts[server_key]);
+ memcached_server_response_decrement(instance);
do
{
- rc= memcached_response(&ptr->hosts[server_key], buffer,
+ rc= memcached_response(instance, buffer,
sizeof(buffer), NULL);
if (rc == MEMCACHED_END)
break;
unlikely (rc != MEMCACHED_SUCCESS)
{
- memcached_io_reset(&ptr->hosts[server_key]);
+ memcached_io_reset(instance);
return rc;
}
/* shit... memcached_response will decrement the counter, so I need to
** reset it.. todo: look at this and try to find a better solution.
*/
- ptr->hosts[server_key].cursor_active= 0;
+ instance->cursor_active= 0;
return MEMCACHED_SUCCESS;
}
-static memcached_return_t ascii_stats_fetch(memcached_st *ptr,
- memcached_stat_st *memc_stat,
+static memcached_return_t ascii_stats_fetch(memcached_stat_st *memc_stat,
char *args,
- unsigned int server_key)
+ memcached_server_instance_st *instance)
{
memcached_return_t rc;
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
return MEMCACHED_WRITE_FAILURE;
- rc= memcached_do(&ptr->hosts[server_key], buffer, send_length, 1);
+ rc= memcached_do(instance, buffer, send_length, 1);
if (rc != MEMCACHED_SUCCESS)
goto error;
while (1)
{
- rc= memcached_response(&ptr->hosts[server_key], buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
+ rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
if (rc == MEMCACHED_STAT)
{
memcached_stat_st *memcached_stat(memcached_st *ptr, char *args, memcached_return_t *error)
{
- unsigned int x;
+ uint32_t x;
memcached_return_t rc;
memcached_stat_st *stats;
for (x= 0; x < memcached_server_count(ptr); x++)
{
memcached_return_t temp_return;
+ memcached_server_instance_st *instance;
+
+ instance= memcached_server_instance_fetch(ptr, x);
if (ptr->flags.binary_protocol)
- temp_return= binary_stats_fetch(ptr, stats + x, args, x);
+ {
+ temp_return= binary_stats_fetch(stats + x, args, instance);
+ }
else
- temp_return= ascii_stats_fetch(ptr, stats + x, args, x);
+ {
+ temp_return= ascii_stats_fetch(stats + x, args, instance);
+ }
if (temp_return != MEMCACHED_SUCCESS)
rc= MEMCACHED_SOME_ERRORS;
memcached_return_t rc;
memcached_st memc;
memcached_st *memc_ptr;
+ memcached_server_instance_st *instance;
memc_ptr= memcached_create(&memc);
WATCHPOINT_ASSERT(memc_ptr);
memcached_server_add(&memc, hostname, port);
+ instance= memcached_server_instance_fetch(memc_ptr, 0);
+
if (memc.flags.binary_protocol)
- rc= binary_stats_fetch(&memc, memc_stat, args, 0);
+ {
+ rc= binary_stats_fetch(memc_stat, args, instance);
+ }
else
- rc= ascii_stats_fetch(&memc, memc_stat, args, 0);
+ {
+ rc= ascii_stats_fetch(memc_stat, args, instance);
+ }
memcached_free(&memc);
size_t write_length;
memcached_return_t rc;
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
- unsigned int server_key;
+ uint32_t server_key;
+ memcached_server_instance_st *instance;
WATCHPOINT_ASSERT(!(value == NULL && value_length > 0));
}
server_key= memcached_generate_hash(ptr, master_key, master_key_length);
+ instance= memcached_server_instance_fetch(ptr, server_key);
if (cas)
{
size_t cmd_size= write_length + value_length + 2;
if (cmd_size > MAX_UDP_DATAGRAM_LENGTH - UDP_DATAGRAM_HEADER_LENGTH)
return MEMCACHED_WRITE_FAILURE;
- if (cmd_size + ptr->hosts[server_key].write_buffer_offset > MAX_UDP_DATAGRAM_LENGTH)
- memcached_io_write(&ptr->hosts[server_key], NULL, 0, 1);
+ if (cmd_size + instance->write_buffer_offset > MAX_UDP_DATAGRAM_LENGTH)
+ memcached_io_write(instance, NULL, 0, 1);
}
if (write_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
}
/* Send command header */
- rc= memcached_do(&ptr->hosts[server_key], buffer, write_length, 0);
+ rc= memcached_do(instance, buffer, write_length, 0);
if (rc != MEMCACHED_SUCCESS)
goto error;
/* Send command body */
- if (memcached_io_write(&ptr->hosts[server_key], value, value_length, 0) == -1)
+ if (memcached_io_write(instance, value, value_length, 0) == -1)
{
rc= MEMCACHED_WRITE_FAILURE;
goto error;
to_write= 1;
}
- if (memcached_io_write(&ptr->hosts[server_key], "\r\n", 2, to_write) == -1)
+ if (memcached_io_write(instance, "\r\n", 2, to_write) == -1)
{
rc= MEMCACHED_WRITE_FAILURE;
goto error;
if (to_write == 0)
return MEMCACHED_BUFFERED;
- rc= memcached_response(&ptr->hosts[server_key], buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
+ rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
if (rc == MEMCACHED_STORED)
return MEMCACHED_SUCCESS;
return rc;
error:
- memcached_io_reset(&ptr->hosts[server_key]);
+ memcached_io_reset(instance);
return rc;
}
size_t send_length= sizeof(request.bytes);
uint32_t server_key= memcached_generate_hash(ptr, master_key,
master_key_length);
- memcached_server_st *server= &ptr->hosts[server_key];
+
+ memcached_server_instance_st *server=
+ memcached_server_instance_fetch(ptr, server_key);
+
bool noreply= server->root->flags.no_reply;
request.message.header.request.magic= PROTOCOL_BINARY_REQ;
size_t cmd_size= send_length + key_length + value_length;
if (cmd_size > MAX_UDP_DATAGRAM_LENGTH - UDP_DATAGRAM_HEADER_LENGTH)
+ {
return MEMCACHED_WRITE_FAILURE;
+ }
if (cmd_size + server->write_buffer_offset > MAX_UDP_DATAGRAM_LENGTH)
- memcached_io_write(server,NULL,0, 1);
+ {
+ memcached_io_write(server, NULL, 0, 1);
+ }
}
/* write the header */
for (uint32_t x= 0; x < ptr->number_of_replicas; x++)
{
+ memcached_server_instance_st *instance;
+
++server_key;
if (server_key == memcached_server_count(ptr))
server_key= 0;
- memcached_server_st *srv= &ptr->hosts[server_key];
- if ((memcached_do(srv, (const char*)request.bytes,
+ instance= memcached_server_instance_fetch(ptr, server_key);
+
+ if ((memcached_do(instance, (const char*)request.bytes,
send_length, 0) != MEMCACHED_SUCCESS) ||
- (memcached_io_write(srv, key, key_length, 0) == -1) ||
- (memcached_io_write(srv, value, value_length, (char) flush) == -1))
- memcached_io_reset(srv);
+ (memcached_io_write(instance, key, key_length, 0) == -1) ||
+ (memcached_io_write(instance, value, value_length, (char) flush) == -1))
+ {
+ memcached_io_reset(instance);
+ }
else
- memcached_server_response_decrement(srv);
+ {
+ memcached_server_response_decrement(instance);
+ }
}
}
if (flush == 0)
+ {
return MEMCACHED_BUFFERED;
+ }
if (noreply)
+ {
return MEMCACHED_SUCCESS;
+ }
return memcached_response(server, NULL, 0, NULL);
}
/* Make sure that I cant add a tcp server to a udp client */
static test_return_t add_tcp_server_udp_client_test(memcached_st *memc)
{
+ (void)memc;
+#if 0
memcached_server_st server;
memcached_server_clone(&server, &memc->hosts[0]);
test_truth(memcached_server_remove(&(memc->hosts[0])) == MEMCACHED_SUCCESS);
test_truth(memcached_server_add(memc, server.hostname, server.port) == MEMCACHED_INVALID_HOST_PROTOCOL);
+#endif
return TEST_SUCCESS;
}
/* Make sure that I cant add a udp server to a tcp client */
static test_return_t add_udp_server_tcp_client_test(memcached_st *memc)
{
+ (void)memc;
+#if 0
memcached_server_st server;
memcached_server_clone(&server, &memc->hosts[0]);
test_truth(memcached_server_remove(&(memc->hosts[0])) == MEMCACHED_SUCCESS);
memcached_st tcp_client;
memcached_create(&tcp_client);
test_truth(memcached_server_add_udp(&tcp_client, server.hostname, server.port) == MEMCACHED_INVALID_HOST_PROTOCOL);
+#endif
return TEST_SUCCESS;
}
const size_t max_keys= 100;
char **keys= calloc(max_keys, sizeof(char*));
- size_t *key_length=calloc(max_keys, sizeof(size_t));
+ size_t *key_length= calloc(max_keys, sizeof(size_t));
- for (int x= 0; x < (int)max_keys; ++x)
+ for (uint64_t x= 0; x < max_keys; ++x)
{
char k[251];
- key_length[x]= (size_t)snprintf(k, sizeof(k), "0200%u", x);
+ key_length[x]= (size_t)snprintf(k, sizeof(k), "0200%"PRIu64, x);
keys[x]= strdup(k);
test_truth(keys[x] != NULL);
rc= memcached_set(memc, k, key_length[x], k, key_length[x], 0, 0);
memcached_quit(memc);
/* Remove half of the objects */
- for (int x= 0; x < (int)max_keys; ++x)
+ for (size_t x= 0; x < max_keys; ++x)
{
if (x & 1)
{
/* Release allocated resources */
for (size_t x= 0; x < max_keys; ++x)
+ {
free(keys[x]);
+ }
free(keys);
free(key_length);