+/* Protoypes (static) */
+static memcached_return server_add(memcached_st *ptr, char *hostname,
+ 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;
+ unsigned int range;
+
+ range= (MEMCACHED_WHEEL_SIZE / ptr->number_of_hosts);
+
+ /* 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));
+ host->port= port;
+ host->fd= -1;
+ host->type= type;
+ host->read_ptr= host->read_buffer;
+ host->write_ptr= host->write_buffer;
+ host->sockaddr_inited= MEMCACHED_NOT_ALLOCATED;
+}
+