* Modified RPM to strict check install.
* Added documentation for memcached_server_cursor();
+ * Added memcached_servers_reset().
+
0.36 Wed Jan 6 18:23:50 PST 2010
* Merged in new memslap utility.
* All of constants.h has been updated to match style (all old identifiers
BUILT_SOURCES += ${CALLBACK_PAGES}
CREATE_PAGES= \
+ memcached_clone.pop \
memcached_create.pop \
memcached_free.pop \
- memcached_clone.pop
+ memcached_servers_reset.pop
BUILT_SOURCES += ${CREATE_PAGES}
DELETE_PAGES= \
=head1 NAME
-memcached_create, memcached_free - Create a memcached_st structure
+memcached_create, memcached_free, memcached_clone, memcached_servers_reset- Create a memcached_st structure
=head1 LIBRARY
memcached_st *memcached_clone (memcached_st *destination, memcached_st *source);
+ void memcached_servers_reset(memcached_st);
+
=head1 DESCRIPTION
memcached_create() is used to create a C<memcached_st> structure that will then
the argument for the source to clone, it is the same as a call to memcached_create().
If the destination argument is NULL a C<memcached_st> will be allocated for you.
+memcached_servers_reset() allows you to zero out the list of servers that
+the memcached_st has.
+
To clean up memory associated with a C<memcached_st> structure you should pass
it to memcached_free() when you are finished using it. memcached_free() is
the only way to make sure all memory is deallocated when you finish using
#include <memcached.h>
- unsigned int memcached_server_count (memcached_st *ptr);
+ uint32_t memcached_server_count (memcached_st *ptr);
memcached_server_st *
memcached_server_list (memcached_st *ptr);
*error= MEMCACHED_SUCCESS;
server_count= memcached_server_count(memc);
- result= (memcached_analysis_st*)calloc(memc->number_of_hosts,
+ result= (memcached_analysis_st*)calloc(memcached_server_count(memc),
sizeof(memcached_analysis_st));
if (!result)
unsigned int server_key;
bool no_reply= ptr->flags.no_reply;
- unlikely (ptr->hosts == NULL || ptr->number_of_hosts == 0)
+ unlikely (ptr->hosts == NULL || memcached_server_count(ptr) == 0)
return MEMCACHED_NO_SERVERS;
if (ptr->flags.verify_key && (memcached_key_test((const char **)&key, &key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED))
unsigned int server_key;
bool no_reply= ptr->flags.no_reply;
- unlikely (ptr->hosts == NULL || ptr->number_of_hosts == 0)
+ unlikely (ptr->hosts == NULL || memcached_server_count(ptr) == 0)
return MEMCACHED_NO_SERVERS;
server_key= memcached_generate_hash(ptr, master_key, master_key_length);
memcached_quit(ptr);
break;
case MEMCACHED_BEHAVIOR_USE_UDP:
- if (ptr->number_of_hosts)
+ if (memcached_server_count(ptr))
{
return MEMCACHED_FAILURE;
}
unlikely (rc != MEMCACHED_SUCCESS)
return rc;
- unlikely (ptr->hosts == NULL || ptr->number_of_hosts == 0)
+ unlikely (ptr->hosts == NULL || memcached_server_count(ptr) == 0)
return MEMCACHED_NO_SERVERS;
server_key= memcached_generate_hash(ptr, master_key, master_key_length);
for (uint32_t x= 0; x < ptr->number_of_replicas; ++x)
{
++server_key;
- if (server_key == ptr->number_of_hosts)
+ if (server_key == memcached_server_count(ptr))
server_key= 0;
memcached_server_st* server= &ptr->hosts[server_key];
uint32_t server_key;
uint32_t x;
- unlikely (ptr->number_of_hosts == 0)
+ unlikely (memcached_server_count(ptr) == 0)
return MEMCACHED_NO_SERVERS;
- for (server_key= 0; server_key < ptr->number_of_hosts; server_key++)
+ for (server_key= 0; server_key < memcached_server_count(ptr); server_key++)
{
/* 256 I BELIEVE is the upper limit of slabs */
for (x= 0; x < 256; x++)
memcached_return_t rc;
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
- unlikely (ptr->number_of_hosts == 0)
+ unlikely (memcached_server_count(ptr) == 0)
return MEMCACHED_NO_SERVERS;
- for (x= 0; x < ptr->number_of_hosts; x++)
+ for (x= 0; x < memcached_server_count(ptr); x++)
{
bool no_reply= ptr->flags.no_reply;
unsigned int x;
protocol_binary_request_flush request= {.bytes= {0}};
- unlikely (ptr->number_of_hosts == 0)
+ unlikely (memcached_server_count(ptr) == 0)
return MEMCACHED_NO_SERVERS;
request.message.header.request.magic= (uint8_t)PROTOCOL_BINARY_REQ;
request.message.header.request.bodylen= htonl(request.message.header.request.extlen);
request.message.body.expiration= htonl((uint32_t) expiration);
- for (x= 0; x < ptr->number_of_hosts; x++)
+ for (x= 0; x < memcached_server_count(ptr); x++)
{
if (ptr->flags.no_reply)
request.message.header.request.opcode= PROTOCOL_BINARY_CMD_FLUSHQ;
}
}
- for (x= 0; x < ptr->number_of_hosts; x++)
+ for (x= 0; x < memcached_server_count(ptr); x++)
{
if (memcached_server_response_count(&ptr->hosts[x]) > 0)
(void)memcached_response(&ptr->hosts[x], NULL, 0, NULL);
#include "common.h"
-memcached_return_t memcached_flush_buffers(memcached_st *mem)
+memcached_return_t memcached_flush_buffers(memcached_st *memc)
{
memcached_return_t ret= MEMCACHED_SUCCESS;
- for (uint32_t x= 0; x < mem->number_of_hosts; ++x)
- if (mem->hosts[x].write_buffer_offset != 0)
+ for (uint32_t x= 0; x < memcached_server_count(memc); ++x)
+ if (memc->hosts[x].write_buffer_offset != 0)
{
- if (mem->hosts[x].fd == -1 &&
- (ret= memcached_connect(&mem->hosts[x])) != MEMCACHED_SUCCESS)
+ if (memc->hosts[x].fd == -1 &&
+ (ret= memcached_connect(&memc->hosts[x])) != MEMCACHED_SUCCESS)
{
WATCHPOINT_ERROR(ret);
return ret;
}
- if (memcached_io_write(&mem->hosts[x], NULL, 0, 1) == -1)
+ if (memcached_io_write(&memc->hosts[x], NULL, 0, 1) == -1)
ret= MEMCACHED_SOME_ERRORS;
}
if (number_of_keys == 0)
return MEMCACHED_NOTFOUND;
- if (ptr->number_of_hosts == 0)
+ if (memcached_server_count(ptr) == 0)
return MEMCACHED_NO_SERVERS;
if (ptr->flags.verify_key && (memcached_key_test(keys, key_length, number_of_keys) == MEMCACHED_BAD_KEY_PROVIDED))
It might be optimum to bounce the connection if count > some number.
*/
- for (x= 0; x < ptr->number_of_hosts; x++)
+ for (x= 0; x < memcached_server_count(ptr); x++)
{
if (memcached_server_response_count(&ptr->hosts[x]))
{
/*
Should we muddle on if some servers are dead?
*/
- for (x= 0; x < ptr->number_of_hosts; x++)
+ for (x= 0; x < memcached_server_count(ptr); x++)
{
if (memcached_server_response_count(&ptr->hosts[x]))
{
request.message.header.request.opcode= PROTOCOL_BINARY_CMD_NOOP;
request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
- for (x= 0; x < ptr->number_of_hosts; x++)
+ for (x= 0; x < memcached_server_count(ptr); x++)
if (memcached_server_response_count(&ptr->hosts[x]))
{
if (memcached_io_write(&ptr->hosts[x], NULL, 0, 1) == -1)
for (x= 0; x < number_of_keys; ++x)
{
- if (hash[x] == ptr->number_of_hosts)
+ if (hash[x] == memcached_server_count(ptr))
continue; /* Already successfully sent */
uint32_t server= hash[x] + replica;
if (randomize_read && ((server + start) <= (hash[x] + ptr->number_of_replicas)))
server += start;
- while (server >= ptr->number_of_hosts)
- server -= ptr->number_of_hosts;
+ while (server >= memcached_server_count(ptr))
+ server -= memcached_server_count(ptr);
if (dead_servers[server])
continue;
}
memcached_server_response_increment(&ptr->hosts[server]);
- hash[x]= ptr->number_of_hosts;
+ hash[x]= memcached_server_count(ptr);
}
if (success)
bool* dead_servers;
hash= ptr->call_malloc(ptr, sizeof(uint32_t) * number_of_keys);
- dead_servers= ptr->call_calloc(ptr, ptr->number_of_hosts, sizeof(bool));
+ dead_servers= ptr->call_calloc(ptr, memcached_server_count(ptr), sizeof(bool));
if (hash == NULL || dead_servers == NULL)
{
uint32_t hash= 1; /* Just here to remove compile warning */
- WATCHPOINT_ASSERT(ptr->number_of_hosts);
+ WATCHPOINT_ASSERT(memcached_server_count(ptr));
- if (ptr->number_of_hosts == 1)
+ if (memcached_server_count(ptr) == 1)
return 0;
hash= memcached_generate_hash_value(key, key_length, ptr->hash);
return right->index;
}
case MEMCACHED_DISTRIBUTION_MODULA:
- return hash % ptr->number_of_hosts;
+ return hash % memcached_server_count(ptr);
case MEMCACHED_DISTRIBUTION_RANDOM:
- return (uint32_t) random() % ptr->number_of_hosts;
+ return (uint32_t) random() % memcached_server_count(ptr);
case MEMCACHED_DISTRIBUTION_CONSISTENT_MAX:
default:
WATCHPOINT_ASSERT(0); /* We have added a distribution without extending the logic */
- return hash % ptr->number_of_hosts;
+ return hash % memcached_server_count(ptr);
}
/* NOTREACHED */
}
{
uint32_t hash= 1; /* Just here to remove compile warning */
- WATCHPOINT_ASSERT(ptr->number_of_hosts);
+ WATCHPOINT_ASSERT(memcached_server_count(ptr));
- if (ptr->number_of_hosts == 1)
+ if (memcached_server_count(ptr) == 1)
return 0;
if (ptr->flags.hash_with_prefix_key)
static void sort_hosts(memcached_st *ptr)
{
- if (ptr->number_of_hosts)
+ if (memcached_server_count(ptr))
{
- qsort(ptr->hosts, ptr->number_of_hosts, sizeof(memcached_server_st), compare_servers);
- ptr->hosts[0].number_of_hosts= ptr->number_of_hosts;
+ qsort(ptr->hosts, memcached_server_count(ptr), sizeof(memcached_server_st), compare_servers);
+ ptr->hosts[0].number_of_hosts= memcached_server_count(ptr);
}
}
return MEMCACHED_SUCCESS;
}
-void server_list_free(memcached_st *ptr, memcached_server_st *servers)
-{
- uint32_t x;
-
- if (servers == NULL)
- return;
-
- for (x= 0; x < memcached_servers_count(servers); x++)
- if (servers[x].address_info)
- {
- freeaddrinfo(servers[x].address_info);
- servers[x].address_info= NULL;
- }
-
- if (ptr)
- ptr->call_free(ptr, servers);
- else
- free(servers);
-}
-
static uint32_t ketama_server_hash(const char *key, unsigned int key_length, int alignment)
{
unsigned char results[16];
{
live_servers= 0;
ptr->next_distribution_rebuild= 0;
- for (host_index= 0; host_index < ptr->number_of_hosts; ++host_index)
+ for (host_index= 0; host_index < memcached_server_count(ptr); ++host_index)
{
if (list[host_index].next_retry <= now.tv_sec)
live_servers++;
}
}
else
- live_servers= ptr->number_of_hosts;
+ live_servers= memcached_server_count(ptr);
is_ketama_weighted= memcached_behavior_get(ptr, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED);
points_per_server= (uint32_t) (is_ketama_weighted ? MEMCACHED_POINTS_PER_SERVER_KETAMA : MEMCACHED_POINTS_PER_SERVER);
if (is_ketama_weighted)
{
- for (host_index = 0; host_index < ptr->number_of_hosts; ++host_index)
+ for (host_index = 0; host_index < memcached_server_count(ptr); ++host_index)
{
if (list[host_index].weight == 0)
{
}
}
- for (host_index = 0; host_index < ptr->number_of_hosts; ++host_index)
+ for (host_index = 0; host_index < memcached_server_count(ptr); ++host_index)
{
if (is_auto_ejecting && list[host_index].next_retry > now.tv_sec)
continue;
WATCHPOINT_ASSERT(ptr);
WATCHPOINT_ASSERT(ptr->continuum);
- WATCHPOINT_ASSERT(ptr->number_of_hosts * MEMCACHED_POINTS_PER_SERVER <= MEMCACHED_CONTINUUM_SIZE);
+ WATCHPOINT_ASSERT(memcached_server_count(ptr) * MEMCACHED_POINTS_PER_SERVER <= MEMCACHED_CONTINUUM_SIZE);
ptr->continuum_points_counter= pointer_counter;
qsort(ptr->continuum, ptr->continuum_points_counter, sizeof(memcached_continuum_item_st), continuum_item_cmp);
#ifdef DEBUG
- for (pointer_index= 0; ptr->number_of_hosts && pointer_index < ((live_servers * MEMCACHED_POINTS_PER_SERVER) - 1); pointer_index++)
+ for (pointer_index= 0; memcached_server_count(ptr) && pointer_index < ((live_servers * MEMCACHED_POINTS_PER_SERVER) - 1); pointer_index++)
{
WATCHPOINT_ASSERT(ptr->continuum[pointer_index].value <= ptr->continuum[pointer_index + 1].value);
}
count= memcached_servers_count(list);
new_host_list= ptr->call_realloc(ptr, ptr->hosts,
- sizeof(memcached_server_st) * (count + ptr->number_of_hosts));
+ sizeof(memcached_server_st) * (count + memcached_server_count(ptr)));
if (! new_host_list)
return MEMCACHED_MEMORY_ALLOCATION_FAILURE;
return MEMCACHED_INVALID_HOST_PROTOCOL;
WATCHPOINT_ASSERT(list[x].hostname[0] != 0);
- memcached_server_create(ptr, &ptr->hosts[ptr->number_of_hosts]);
+ memcached_server_create(ptr, &ptr->hosts[memcached_server_count(ptr)]);
/* TODO check return type */
- (void)memcached_server_create_with(ptr, &ptr->hosts[ptr->number_of_hosts], list[x].hostname,
+ (void)memcached_server_create_with(ptr, &ptr->hosts[memcached_server_count(ptr)], list[x].hostname,
list[x].port, list[x].weight, list[x].type);
ptr->number_of_hosts++;
}
- ptr->hosts[0].number_of_hosts= (uint16_t) ptr->number_of_hosts;
+ ptr->hosts[0].number_of_hosts= memcached_server_count(ptr);
return run_distribution(ptr);
}
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_st) * (ptr->number_of_hosts + 1));
if (new_host_list == NULL)
return MEMCACHED_MEMORY_ALLOCATION_FAILURE;
ptr->hosts= new_host_list;
/* TODO: Check return type */
- (void)memcached_server_create_with(ptr, &ptr->hosts[ptr->number_of_hosts], hostname, port, weight, type);
+ (void)memcached_server_create_with(ptr, &ptr->hosts[memcached_server_count(ptr)], hostname, port, weight, type);
ptr->number_of_hosts++;
- memcached_servers_set_count(&ptr->hosts[0], ptr->number_of_hosts);
+ memcached_servers_set_count(&ptr->hosts[0], memcached_server_count(ptr));
return run_distribution(ptr);
}
memcached_st *ptr= st_ptr->root;
memcached_server_st *list= ptr->hosts;
- for (x= 0, host_index= 0; x < ptr->number_of_hosts; x++)
+ for (x= 0, host_index= 0; x < memcached_server_count(ptr); x++)
{
if (strncmp(list[x].hostname, st_ptr->hostname, MEMCACHED_MAX_HOST_LENGTH) != 0 || list[x].port != st_ptr->port)
{
return;
- for (x= 0; x < ptr->number_of_hosts; x++)
+ for (x= 0; x < memcached_server_count(ptr); x++)
{
if (memcached_server_response_count(ptr, x) &&
ptr->hosts[x].read_data_length < MEMCACHED_MAX_BUFFER )
unsigned int host_index= 0;
for (unsigned int x= 0;
- x< memc->number_of_hosts && host_index < MAX_SERVERS_TO_POLL;
+ x< memcached_server_count(memc) && host_index < MAX_SERVERS_TO_POLL;
++x)
{
if (memc->hosts[x].read_buffer_length > 0) /* I have data in the buffer */
if (host_index < 2)
{
/* We have 0 or 1 server with pending events.. */
- for (unsigned int x= 0; x< memc->number_of_hosts; ++x)
+ for (unsigned int x= 0; x< memcached_server_count(memc); ++x)
if (memcached_server_response_count(&memc->hosts[x]) > 0)
return &memc->hosts[x];
case 0:
break;
default:
- for (unsigned int x= 0; x < host_index; ++x)
+ for (size_t x= 0; x < host_index; ++x)
+ {
if (fds[x].revents & POLLIN)
- for (unsigned int y= 0; y < memc->number_of_hosts; ++y)
+ {
+ for (unsigned int y= 0; y < memcached_server_count(memc); ++y)
+ {
if (memc->hosts[y].fd == fds[x].fd)
return &memc->hosts[y];
+ }
+ }
+ }
}
return NULL;
return ptr;
}
+void server_list_free(memcached_st *ptr, memcached_server_st *servers)
+{
+ uint32_t x;
+
+ if (servers == NULL)
+ return;
+
+ for (x= 0; x < memcached_servers_count(servers); x++)
+ if (servers[x].address_info)
+ {
+ freeaddrinfo(servers[x].address_info);
+ servers[x].address_info= NULL;
+ }
+
+ if (ptr)
+ {
+ ptr->call_free(ptr, servers);
+ }
+ else
+ free(servers);
+}
+
+void memcached_servers_reset(memcached_st *ptr)
+{
+ server_list_free(ptr, ptr->hosts);
+
+ ptr->hosts= NULL;
+ ptr->number_of_hosts= 0;
+ ptr->cursor_server= 0;
+ ptr->last_disconnected_server= NULL;
+ ptr->server_failure_limit= 0;
+}
+
void memcached_free(memcached_st *ptr)
{
/* If we have anything open, lets close it now */
LIBMEMCACHED_API
memcached_return_t memcached_version(memcached_st *ptr);
+LIBMEMCACHED_API
+void memcached_servers_reset(memcached_st *ptr);
+
/* Public API */
LIBMEMCACHED_API
unsigned int x;
if (ptr->hosts == NULL ||
- ptr->number_of_hosts == 0)
+ memcached_server_count(ptr) == 0)
return;
- if (ptr->hosts && ptr->number_of_hosts)
+ if (ptr->hosts && memcached_server_count(ptr))
{
- for (x= 0; x < ptr->number_of_hosts; x++)
+ for (x= 0; x < memcached_server_count(ptr); x++)
memcached_quit_server(&ptr->hosts[x], 0);
}
}
{
uint32_t y;
- for (y= 0; y < ptr->number_of_hosts; y++)
+ for (y= 0; y < memcached_server_count(ptr); y++)
{
uint32_t x;
unlikely (*error != MEMCACHED_SUCCESS)
return NULL;
- unlikely (ptr->number_of_hosts == 0)
+ unlikely (memcached_server_count(ptr) == 0)
{
*error= MEMCACHED_NO_SERVERS;
return NULL;
const char *memcached_server_error(memcached_server_st *ptr)
{
- if (ptr)
- return ptr->cached_server_error;
- else
- return NULL;
+ return ptr
+ ? ptr->cached_server_error
+ : NULL;
}
void memcached_server_error_reset(memcached_server_st *ptr)
uint32_t memcached_server_list_count(memcached_server_st *ptr)
{
- if (ptr == NULL)
- return 0;
-
- return memcached_servers_count(ptr);
+ return (ptr == NULL)
+ ? 0
+ : memcached_servers_count(ptr);
}
void memcached_server_list_free(memcached_server_st *ptr)
return NULL;
}
- stats= ptr->call_calloc(ptr, ptr->number_of_hosts, sizeof(memcached_stat_st));
+ stats= ptr->call_calloc(ptr, memcached_server_count(ptr), sizeof(memcached_stat_st));
stats->root= ptr;
}
rc= MEMCACHED_SUCCESS;
- for (x= 0; x < ptr->number_of_hosts; x++)
+ for (x= 0; x < memcached_server_count(ptr); x++)
{
memcached_return_t temp_return;
unlikely (rc != MEMCACHED_SUCCESS)
return rc;
- unlikely (ptr->number_of_hosts == 0)
+ unlikely (memcached_server_count(ptr) == 0)
return MEMCACHED_NO_SERVERS;
if (ptr->flags.verify_key && (memcached_key_test((const char **)&key, &key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED))
for (uint32_t x= 0; x < ptr->number_of_replicas; x++)
{
++server_key;
- if (server_key == ptr->number_of_hosts)
+ if (server_key == memcached_server_count(ptr))
server_key= 0;
memcached_server_st *srv= &ptr->hosts[server_key];
return MEMCACHED_WRITE_FAILURE;
rc= MEMCACHED_SUCCESS;
- for (x= 0; x < ptr->number_of_hosts; x++)
+ for (x= 0; x < memcached_server_count(ptr); x++)
{
memcached_return_t rrc;
send_length= strlen(command);
rc= MEMCACHED_SUCCESS;
- for (x= 0; x < ptr->number_of_hosts; x++)
+ for (x= 0; x < memcached_server_count(ptr); x++)
{
memcached_return_t rrc;
request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
rc= MEMCACHED_SUCCESS;
- for (x= 0; x < ptr->number_of_hosts; x++)
+ for (x= 0; x < memcached_server_count(ptr); x++)
{
memcached_return_t rrc;
}
}
- for (x= 0; x < ptr->number_of_hosts; x++)
+ for (x= 0; x < memcached_server_count(ptr); x++)
+ {
if (memcached_server_response_count(&ptr->hosts[x]) > 0)
{
memcached_return_t rrc;
ptr->hosts[x].minor_version= (uint8_t)strtol(p + 1, &p, 10);
ptr->hosts[x].micro_version= (uint8_t)strtol(p + 1, NULL, 10);
}
+ }
return rc;
}
{
test_ports[x]= (uint32_t)random() % 64000;
rc= memcached_server_add_with_weight(local_memc, "localhost", test_ports[x], 0);
- test_truth(local_memc->number_of_hosts == x + 1);
+ test_truth(memcached_server_count(local_memc) == x + 1);
test_truth(memcached_servers_count(local_memc->hosts) == x+1);
test_truth(rc == MEMCACHED_SUCCESS);
}
{
test_ports[x]= (uint32_t)(random() % 64000);
rc= memcached_server_add_with_weight(local_memc, "localhost", test_ports[x], 0);
- test_truth(local_memc->number_of_hosts == x+1);
+ test_truth(memcached_server_count(local_memc) == x+1);
test_truth(memcached_servers_count(local_memc->hosts) == x+1);
test_truth(rc == MEMCACHED_SUCCESS);
}
size_t return_value_length;
/* Here we free everything before running a bunch of mget tests */
- {
- memcached_server_list_free(memc->hosts);
- memc->hosts= NULL;
- memc->number_of_hosts= 0;
- }
+ memcached_servers_reset(memc);
/* We need to empty the server before continueing test */
memcached_server_push(memc, server_pool);
/* verify that the server list was parsed okay. */
- test_truth(memc->number_of_hosts == 8);
+ test_truth(memcached_server_count(memc) == 8);
test_truth(strcmp(server_pool[0].hostname, "10.0.1.1") == 0);
test_truth(server_pool[0].port == 11211);
test_truth(server_pool[0].weight == 600);
memcached_server_push(memc, server_pool);
/* verify that the server list was parsed okay. */
- test_truth(memc->number_of_hosts == 8);
+ test_truth(memcached_server_count(memc) == 8);
test_truth(strcmp(server_pool[0].hostname, "10.0.1.1") == 0);
test_truth(server_pool[0].port == 11211);
test_truth(server_pool[0].weight == 600);
*/
memcached_return_t rc;
rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS,
- memc->number_of_hosts - 1);
+ memcached_server_count(memc) - 1);
test_truth(rc == MEMCACHED_SUCCESS);
- test_truth(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS) == memc->number_of_hosts - 1);
+ test_truth(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS) == memcached_server_count(memc) - 1);
return rc == MEMCACHED_SUCCESS ? TEST_SUCCESS : TEST_SKIPPED;
}
memcached_return_t rc;
struct stat buf;
- memcached_server_list_free(memc->hosts);
- memc->hosts= NULL;
- memc->number_of_hosts= 0;
+ memcached_servers_reset(memc);
if (stat("/tmp/memcached.socket", &buf))
return TEST_SKIPPED;
** way it is supposed to do!!!!
*/
int no_msg=0;
- for (uint32_t x=0; x < memc->number_of_hosts; ++x)
+ for (uint32_t x=0; x < memcached_server_count(memc); ++x)
no_msg+=(int)(memc->hosts[x].cursor_active);
test_truth(no_msg == 0);
* within the library, and this is not a supported interface.
* This is to verify correct behavior in the library
*/
- for (uint32_t host= 0; host < memc->number_of_hosts; ++host)
+ for (uint32_t host= 0; host < memcached_server_count(memc); ++host)
{
memcached_st *memc_clone= memcached_clone(NULL, memc);
memc_clone->hosts[host].port= 0;
static uint16_t *get_udp_request_ids(memcached_st *memc)
{
- uint16_t *ids= malloc(sizeof(uint16_t) * memc->number_of_hosts);
+ uint16_t *ids= malloc(sizeof(uint16_t) * memcached_server_count(memc));
assert(ids != NULL);
unsigned int x;
- for (x= 0; x < memc->number_of_hosts; x++)
+ for (x= 0; x < memcached_server_count(memc); x++)
ids[x]= get_udp_datagram_request_id((struct udp_datagram_header_st *) memc->hosts[x].write_buffer);
return ids;
memcached_server_st *cur_server = memc->hosts;
uint16_t *cur_req_ids = get_udp_request_ids(memc);
- for (x= 0; x < memc->number_of_hosts; x++)
+ for (x= 0; x < memcached_server_count(memc); x++)
{
test_truth(cur_server[x].cursor_active == 0);
test_truth(cur_req_ids[x] == expected_req_ids[x]);
|| memc->hosts[0].micro_version < 6)
return TEST_SKIPPED;
- uint32_t num_hosts= memc->number_of_hosts;
+ uint32_t num_hosts= memcached_server_count(memc);
unsigned int x= 0;
memcached_server_st servers[num_hosts];
memcpy(servers, memc->hosts, sizeof(memcached_server_st) * num_hosts);
test_truth(memc->flags.use_udp);
test_truth(memc->flags.no_reply);
- test_truth(memc->number_of_hosts == 0);
+ test_truth(memcached_server_count(memc) == 0);
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_USE_UDP,0);
test_truth(! (memc->flags.use_udp));
memcached_return_t rc;
uint16_t *expected_ids= get_udp_request_ids(memc);
unsigned int x;
- for (x= 0; x < memc->number_of_hosts;x++)
+ for (x= 0; x < memcached_server_count(memc); x++)
increment_request_id(&expected_ids[x]);
rc= memcached_verbosity(memc,3);
memcached_return_t rc;
uint16_t *expected_ids= get_udp_request_ids(memc);
unsigned int x;
- for (x= 0; x < memc->number_of_hosts;x++)
+ for (x= 0; x < memcached_server_count(memc);x++)
increment_request_id(&expected_ids[x]);
rc= memcached_flush(memc,0);
memcached_server_push(memc, server_pool);
/* verify that the server list was parsed okay. */
- test_truth(memc->number_of_hosts == 8);
+ test_truth(memcached_server_count(memc) == 8);
test_strcmp(server_pool[0].hostname, "10.0.1.1");
test_truth(server_pool[0].port == 11211);
test_truth(server_pool[0].weight == 600);
memcached_server_push(memc, server_pool);
/* verify that the server list was parsed okay. */
- test_truth(memc->number_of_hosts == 8);
+ test_truth(memcached_server_count(memc) == 8);
test_strcmp(server_pool[0].hostname, "10.0.1.1");
test_truth(server_pool[0].port == 11211);
test_truth(server_pool[0].weight == 600);
* 1024 (that should satisfy most users don't you think?). Future versions
* will include a mget_execute function call if you need a higher number.
*/
- uint32_t number_of_hosts= memc->number_of_hosts;
+ uint32_t number_of_hosts= memcached_server_count(memc);
memc->number_of_hosts= 1;
const size_t max_keys= 1024;
char **keys= calloc(max_keys, sizeof(char*));
free(key_length);
memc->number_of_hosts= number_of_hosts;
+
return TEST_SUCCESS;
}
test_truth(rc == MEMCACHED_SUCCESS);
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, 1);
- uint32_t number_of_hosts= memc->number_of_hosts;
+ uint32_t number_of_hosts= memcached_server_count(memc);
memc->number_of_hosts= 1;
char k[250];
static test_return_t regression_bug_447342(memcached_st *memc)
{
- if (memc->number_of_hosts < 3 || pre_replication(memc) != MEMCACHED_SUCCESS)
+ if (memcached_server_count(memc) < 3 || pre_replication(memc) != MEMCACHED_SUCCESS)
return TEST_SKIPPED;
memcached_return_t rc;
* in a non-portable way and you shouldn't be doing this. I'm only
* doing this in order to verify that the library works the way it should
*/
- uint32_t number_of_hosts= memc->number_of_hosts;
+ uint32_t number_of_hosts= memcached_server_count(memc);
memc->number_of_hosts= 1;
/* Ensure that we are connected to the server by setting a value */