/*
This is a partial implementation for fetching/creating memcached_server_st objects.
*/
-#include "common.h"
+#include <libmemcached/common.h>
static inline void _server_init(memcached_server_st *self, const memcached_st *root,
const char *hostname, in_port_t port,
uint32_t weight, memcached_connection_t type)
{
- self->options.sockaddr_inited= false;
self->options.is_shutting_down= false;
+ self->options.is_dead= false;
self->number_of_hosts= 0;
self->cursor_active= 0;
self->port= port;
self->fd= -1;
self->io_bytes_sent= 0;
self->server_failure_counter= 0;
- self->weight= weight;
- self->state.is_corked= false;
- self->state.is_dead= false;
+ self->weight= weight ? weight : 1; // 1 is the default weight value
WATCHPOINT_SET(self->io_wait_count.read= 0);
WATCHPOINT_SET(self->io_wait_count.write= 0);
self->major_version= UINT8_MAX;
self->read_data_length= 0;
self->write_buffer_offset= 0;
self->address_info= NULL;
+ self->address_info_next= NULL;
if (root)
{
self->next_retry= 0;
}
+ if (self->weight > 1 && root)
+ {
+ ((memcached_st *)root)->ketama.weighted= true;
+ }
+
self->root= root;
self->limit_maxbytes= 0;
if (hostname == NULL)
+ {
self->hostname[0]= 0;
+ }
else
+ {
strncpy(self->hostname, hostname, NI_MAXHOST - 1);
+ }
}
static memcached_server_st *_server_create(memcached_server_st *self, const memcached_st *memc)
if (memcached_is_allocated(self))
{
- libmemcached_free(self->root, self);
+ if (self->root)
+ {
+ libmemcached_free(self->root, self);
+ }
+ else
+ {
+ free(self);
+ }
}
else
{
if (self == NULL)
return;
- const memcached_st *root= self->root;
-
for (uint32_t x= 0; x < memcached_server_list_count(self); x++)
{
if (self[x].address_info)
}
}
+ const memcached_st *root= self->root;
if (root)
{
libmemcached_free(root, self);