+memcached_server_st *memcached_server_create(memcached_st *memc, memcached_server_st *ptr)
+{
+ if (ptr == NULL)
+ {
+ ptr= (memcached_server_st *)calloc(1, sizeof(memcached_server_st));
+
+ if (!ptr)
+ return NULL; /* MEMCACHED_MEMORY_ALLOCATION_FAILURE */
+
+ ptr->is_allocated= true;
+ }
+ else
+ memset(ptr, 0, sizeof(memcached_server_st));
+
+ ptr->root= memc;
+
+ return ptr;
+}
+
+memcached_server_st *memcached_server_create_with(memcached_st *memc, memcached_server_st *host,
+ const char *hostname, unsigned int port,
+ uint32_t weight, memcached_connection type)
+{
+ host= memcached_server_create(memc, host);
+
+ if (host == NULL)
+ return NULL;
+
+ strncpy(host->hostname, hostname, MEMCACHED_MAX_HOST_LENGTH - 1);
+ host->root= memc ? memc : NULL;
+ host->port= port;
+ host->weight= weight;
+ host->fd= -1;
+ host->type= type;
+ host->read_ptr= host->read_buffer;
+ if (memc)
+ host->next_retry= memc->retry_timeout;
+ if (type == MEMCACHED_CONNECTION_UDP)
+ {
+ host->write_buffer_offset= UDP_DATAGRAM_HEADER_LENGTH;
+ memcached_io_init_udp_header(host, 0);
+ }
+
+ return host;
+}
+
+void memcached_server_free(memcached_server_st *ptr)
+{
+ memcached_quit_server(ptr, 0);
+
+ if (ptr->cached_server_error)
+ {
+ free(ptr->cached_server_error);
+ ptr->cached_server_error= NULL;
+ }
+
+ if (ptr->address_info)
+ {
+ freeaddrinfo(ptr->address_info);
+ ptr->address_info= NULL;
+ }
+
+ if (ptr->is_allocated)
+ ptr->root->call_free(ptr->root, ptr);
+ else
+ memset(ptr, 0, sizeof(memcached_server_st));
+}
+
+/*
+ If we do not have a valid object to clone from, we toss an error.
+*/
+memcached_server_st *memcached_server_clone(memcached_server_st *clone, memcached_server_st *ptr)
+{
+ memcached_server_st *rv = NULL;
+
+ /* We just do a normal create if ptr is missing */
+ if (ptr == NULL)
+ return NULL;
+
+ rv = memcached_server_create_with(ptr->root, clone,
+ ptr->hostname, ptr->port, ptr->weight,
+ ptr->type);
+ if (rv != NULL)
+ {
+ rv->cached_errno= ptr->cached_errno;
+ if (ptr->cached_server_error)
+ rv->cached_server_error= strdup(ptr->cached_server_error);
+ }
+
+ return rv;
+
+}
+