Update docs.
[m6w6/libmemcached] / libmemcached / server_list.c
index c8f18368b44a9479fa96b3e72e172adf6622f3e1..ca37f7f9a4b3f159e5f8747d50be33c4918a3698 100644 (file)
 
 #include "common.h"
 
-memcached_server_st *memcached_server_list_append_with_weight(memcached_server_st *ptr,
-                                                              const char *hostname, in_port_t port,
-                                                              uint32_t weight,
-                                                              memcached_return_t *error)
+memcached_server_list_st 
+memcached_server_list_append_with_weight(memcached_server_list_st ptr,
+                                         const char *hostname, in_port_t port,
+                                         uint32_t weight,
+                                         memcached_return_t *error)
 {
-  unsigned int count;
-  memcached_server_st *new_host_list;
+  uint32_t count;
+  memcached_server_list_st new_host_list;
 
   if (hostname == NULL || error == NULL)
     return NULL;
 
-  if (! port)
+  if (hostname[0] == '/')
+    port = 0;
+  else if (! port)
     port= MEMCACHED_DEFAULT_PORT;
 
   /* Increment count for hosts */
@@ -36,12 +39,16 @@ memcached_server_st *memcached_server_list_append_with_weight(memcached_server_s
   new_host_list= (memcached_server_write_instance_st)realloc(ptr, sizeof(memcached_server_st) * count);
   if (!new_host_list)
   {
+    ptr->cached_errno= errno;
     *error= MEMCACHED_MEMORY_ALLOCATION_FAILURE;
     return NULL;
   }
 
-  /* TODO: Check return type */
-  memcached_server_create_with(NULL, &new_host_list[count-1], hostname, port, weight, MEMCACHED_CONNECTION_TCP);
+  /* @todo Check return type */
+  memcached_server_create_with(NULL, &new_host_list[count-1], hostname, port, weight, port ? MEMCACHED_CONNECTION_TCP : MEMCACHED_CONNECTION_UNIX_SOCKET);
+
+  // Handset allocated since 
+  new_host_list->options.is_allocated= true;
 
   /* Backwards compatibility hack */
   memcached_servers_set_count(new_host_list, count);
@@ -50,9 +57,27 @@ memcached_server_st *memcached_server_list_append_with_weight(memcached_server_s
   return new_host_list;
 }
 
-memcached_server_st *memcached_server_list_append(memcached_server_st *ptr,
-                                                  const char *hostname, in_port_t port,
-                                                  memcached_return_t *error)
+memcached_server_list_st
+memcached_server_list_append(memcached_server_list_st ptr,
+                             const char *hostname, in_port_t port,
+                             memcached_return_t *error)
 {
   return memcached_server_list_append_with_weight(ptr, hostname, port, 0, error);
 }
+
+uint32_t memcached_server_list_count(const memcached_server_list_st self)
+{
+  return (self == NULL)
+    ? 0
+    : self->number_of_hosts;
+}
+
+memcached_server_st *memcached_server_list(const memcached_st *self)
+{
+  return self->servers;
+}
+
+void memcached_server_list_set(memcached_st *self, memcached_server_st *list)
+{
+  self->servers= list;
+}