unsigned int port,
memcached_connection type);
+#define MEMCACHED_WHEEL_SIZE 1024
+#define MEMCACHED_STRIDE 4
+static void rebalance_wheel(memcached_st *ptr)
+{
+ unsigned int x;
+ unsigned int y;
+ unsigned int latch;
+
+ /* Seed the Wheel */
+ memset(ptr->wheel, 0, sizeof(unsigned int) * MEMCACHED_WHEEL_SIZE);
+
+ for (latch= y= x= 0; x < MEMCACHED_WHEEL_SIZE; x++, latch++)
+ {
+ if (latch == MEMCACHED_STRIDE)
+ {
+ y++;
+ if (y == ptr->number_of_hosts)
+ y= 0;
+ latch= 0;
+ }
+
+ ptr->wheel[x]= y;
+ }
+}
+
static void host_reset(memcached_server_st *host, char *hostname, unsigned int port,
memcached_connection type)
{
memset(host, 0, sizeof(memcached_server_st));
- memcpy(host->hostname, hostname, strlen(hostname));
+ strncpy(host->hostname, hostname, MEMCACHED_MAX_HOST_LENGTH - 1);
host->port= port;
host->fd= -1;
host->type= type;
}
ptr->hosts[0].count= ptr->number_of_hosts;
+ rebalance_wheel(ptr);
+
return MEMCACHED_SUCCESS;
}
ptr->number_of_hosts++;
ptr->hosts[0].count++;
+ rebalance_wheel(ptr);
+
LIBMEMCACHED_MEMCACHED_SERVER_ADD_END();
return MEMCACHED_SUCCESS;
unsigned int count;
memcached_server_st *new_host_list;
- if (!hostname)
- return ptr;
+ if (hostname == NULL || error == NULL)
+ return NULL;
if (!port)
port= MEMCACHED_DEFAULT_PORT;
void memcached_server_list_free(memcached_server_st *ptr)
{
+ unsigned int x;
+
if (ptr == NULL)
return;
+ for (x= 0; x < ptr->count; x++)
+ if (ptr[x].address_info)
+ freeaddrinfo(ptr[x].address_info);
+
free(ptr);
}