+static memcached_return_t server_add(memcached_st *ptr,
+ const memcached_string_t& hostname,
+ in_port_t port,
+ uint32_t weight,
+ memcached_connection_t type)
+{
+ assert_msg(ptr, "Programmer mistake, somehow server_add() was passed a NULL memcached_st");
+
+ org::libmemcached::Instance* new_host_list= libmemcached_xrealloc(ptr, memcached_instance_list(ptr), (ptr->number_of_hosts + 1), org::libmemcached::Instance);
+
+ if (new_host_list == NULL)
+ {
+ return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT);
+ }
+
+ memcached_instance_set(ptr, new_host_list);
+
+ /* TODO: Check return type */
+ org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, memcached_server_count(ptr));
+
+ if (__instance_create_with(ptr, instance, hostname, port, weight, type) == NULL)
+ {
+ return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT);
+ }
+
+ if (weight > 1)
+ {
+ ptr->ketama.weighted= true;
+ }
+
+ ptr->number_of_hosts++;
+
+ return run_distribution(ptr);
+}
+