}
static memcached_return_t server_print_callback(const memcached_st *,
- const memcached_server_st *instance,
+ memcached_server_instance_st instance,
void *)
{
std::cerr << memcached_server_name(instance) << ":" << memcached_server_port(instance) <<
- " " << int(instance->major_version) <<
- "." << int(instance->minor_version) <<
- "." << int(instance->micro_version) << std::endl;
+ " " << int(memcached_server_major_version(instance)) <<
+ "." << int(memcached_server_minor_version(instance)) <<
+ "." << int(memcached_server_micro_version(instance)) << std::endl;
return MEMCACHED_SUCCESS;
}
LIBMEMCACHED_API
const char *memcached_server_type(const memcached_server_instance_st ptr);
+LIBMEMCACHED_API
+uint8_t memcached_server_major_version(const memcached_server_instance_st ptr);
+
+LIBMEMCACHED_API
+uint8_t memcached_server_minor_version(const memcached_server_instance_st ptr);
+
+LIBMEMCACHED_API
+uint8_t memcached_server_micro_version(const memcached_server_instance_st ptr);
+
#ifdef __cplusplus
} // extern "C"
#endif
unsigned int version;
} server_info;
uint32_t number_of_hosts;
- memcached_server_st *servers;
- memcached_server_st *last_disconnected_server;
+ struct memcached_instance_st *servers;
+ struct memcached_instance_st *last_disconnected_server;
int32_t snd_timeout;
int32_t rcv_timeout;
uint32_t server_failure_limit;
// All of the flavors of memcache_server_st
struct memcached_server_st;
-typedef const struct memcached_server_st *memcached_server_instance_st;
+struct memcached_instance_st;
+typedef const struct memcached_instance_st *memcached_server_instance_st;
typedef struct memcached_server_st *memcached_server_list_st;
struct memcached_callback_st;
#include <libmemcached/watchpoint.h>
#include <libmemcached/is.h>
+#include <libmemcached/instance.h>
#include <libmemcached/server_instance.h>
#ifdef HAVE_POLL_H
#include <libmemcached/allocators.hpp>
#include <libmemcached/hash.hpp>
#include <libmemcached/quit.hpp>
+#include <libmemcached/instance.hpp>
#include <libmemcached/server.hpp>
#include <libmemcached/behavior.hpp>
#include <libmemcached/sasl.hpp>
#define memcached_server_response_decrement(A) (A)->cursor_active--
#define memcached_server_response_reset(A) (A)->cursor_active=0
+#define memcached_instance_response_increment(A) (A)->cursor_active++
+#define memcached_instance_response_decrement(A) (A)->cursor_active--
+#define memcached_instance_response_reset(A) (A)->cursor_active=0
+
bool memcached_purge(memcached_server_write_instance_st ptr);
+struct memcached_instance_st* memcached_instance_by_position(const memcached_st *ptr, uint32_t server_key);
+
#ifdef __cplusplus
}
#endif
#define SOCK_CLOEXEC 0
#endif
-static memcached_return_t connect_poll(memcached_server_st *server)
+static memcached_return_t connect_poll(memcached_instance_st *server)
{
struct pollfd fds[1];
fds[0].fd= server->fd;
return memcached_set_errno(*server, get_socket_errno(), MEMCACHED_AT);
}
-static memcached_return_t set_hostinfo(memcached_server_st *server)
+static memcached_return_t set_hostinfo(memcached_instance_st *server)
{
assert(server->type != MEMCACHED_CONNECTION_UNIX_SOCKET);
if (server->address_info)
return MEMCACHED_SUCCESS;
}
-static inline void set_socket_nonblocking(memcached_server_st *server)
+static inline void set_socket_nonblocking(memcached_instance_st *server)
{
#ifdef WIN32
u_long arg= 1;
#endif
}
-static void set_socket_options(memcached_server_st *server)
+static void set_socket_options(memcached_instance_st *server)
{
assert_msg(server->fd != INVALID_SOCKET, "invalid socket was passed to set_socket_options()");
set_socket_nonblocking(server);
}
-static memcached_return_t unix_socket_connect(memcached_server_st *server)
+static memcached_return_t unix_socket_connect(memcached_instance_st *server)
{
#ifndef WIN32
WATCHPOINT_ASSERT(server->fd == INVALID_SOCKET);
#endif
}
-static memcached_return_t network_connect(memcached_server_st *server)
+static memcached_return_t network_connect(memcached_instance_st *server)
{
bool timeout_error_occured= false;
if (memcached_has_current_error(*server))
{
- return memcached_server_error_return(server);
+ return memcached_instance_error_return(server);
}
if (timeout_error_occured and server->state < MEMCACHED_SERVER_STATE_IN_PROGRESS)
if (memcached_has_current_error(*server))
{
memcached_mark_server_for_timeout(server);
- assert(memcached_failed(memcached_server_error_return(server)));
+ assert(memcached_failed(memcached_instance_error_return(server)));
}
else
{
char message[MAX_ERROR_LENGTH];
};
-static void _set(memcached_server_st& server, memcached_st& memc)
+static void _set(memcached_instance_st& server, memcached_st& memc)
{
if (server.error_messages and server.error_messages->query_id != server.root->query_id)
{
return memcached_set_error(memc, rc, at, tmp);
}
-memcached_return_t memcached_set_error(memcached_server_st& self, memcached_return_t rc, const char *at, const char *str, size_t length)
+memcached_return_t memcached_set_error(memcached_instance_st& self, memcached_return_t rc, const char *at, const char *str, size_t length)
{
assert_msg(rc != MEMCACHED_ERRNO, "Programmer error, MEMCACHED_ERRNO was set to be returned to client");
- assert_msg(rc != MEMCACHED_SOME_ERRORS, "Programmer error, MEMCACHED_SOME_ERRORS was about to be set on a memcached_server_st");
+ assert_msg(rc != MEMCACHED_SOME_ERRORS, "Programmer error, MEMCACHED_SOME_ERRORS was about to be set on a memcached_instance_st");
memcached_string_t tmp= { str, length };
return memcached_set_error(self, rc, at, tmp);
return memcached_set_error(memc, MEMCACHED_PARSE_ERROR, at, buffer, length);
}
-static inline size_t append_host_to_string(memcached_server_st& self, char* buffer, const size_t buffer_length)
+static inline size_t append_host_to_string(memcached_instance_st& self, char* buffer, const size_t buffer_length)
{
size_t size= 0;
switch (self.type)
return size;
}
-memcached_return_t memcached_set_error(memcached_server_st& self, memcached_return_t rc, const char *at, memcached_string_t& str)
+memcached_return_t memcached_set_error(memcached_instance_st& self, memcached_return_t rc, const char *at, memcached_string_t& str)
{
assert_msg(rc != MEMCACHED_ERRNO, "Programmer error, MEMCACHED_ERRNO was set to be returned to client");
- assert_msg(rc != MEMCACHED_SOME_ERRORS, "Programmer error, MEMCACHED_SOME_ERRORS was about to be set on a memcached_server_st");
+ assert_msg(rc != MEMCACHED_SOME_ERRORS, "Programmer error, MEMCACHED_SOME_ERRORS was about to be set on a memcached_instance_st");
if (memcached_fatal(rc) == false)
{
return rc;
return rc;
}
-memcached_return_t memcached_set_error(memcached_server_st& self, memcached_return_t rc, const char *at)
+memcached_return_t memcached_set_error(memcached_instance_st& self, memcached_return_t rc, const char *at)
{
- assert_msg(rc != MEMCACHED_SOME_ERRORS, "Programmer error, MEMCACHED_SOME_ERRORS was about to be set on a memcached_server_st");
+ assert_msg(rc != MEMCACHED_SOME_ERRORS, "Programmer error, MEMCACHED_SOME_ERRORS was about to be set on a memcached_instance_st");
if (memcached_fatal(rc) == false)
{
return rc;
return memcached_set_errno(self, local_errno, at, tmp);
}
-memcached_return_t memcached_set_errno(memcached_server_st& self, int local_errno, const char *at, const char *str, size_t length)
+memcached_return_t memcached_set_errno(memcached_instance_st& self, int local_errno, const char *at, const char *str, size_t length)
{
memcached_string_t tmp= { str, length };
return memcached_set_errno(self, local_errno, at, tmp);
return rc;
}
-memcached_return_t memcached_set_errno(memcached_server_st& self, int local_errno, const char *at, memcached_string_t& str)
+memcached_return_t memcached_set_errno(memcached_instance_st& self, int local_errno, const char *at, memcached_string_t& str)
{
if (local_errno == 0)
{
return rc;
}
-memcached_return_t memcached_set_errno(memcached_server_st& self, int local_errno, const char *at)
+memcached_return_t memcached_set_errno(memcached_instance_st& self, int local_errno, const char *at)
{
if (local_errno == 0)
{
self.error_messages= NULL;
}
+void memcached_error_free(memcached_instance_st& self)
+{
+ _error_free(self.error_messages);
+ self.error_messages= NULL;
+}
+
void memcached_error_free(memcached_server_st& self)
{
_error_free(self.error_messages);
return false;
}
-bool memcached_has_current_error(memcached_server_st& server)
+bool memcached_has_current_error(memcached_instance_st& server)
{
return memcached_has_current_error(*(server.root));
}
}
-memcached_error_t *memcached_error_copy(const memcached_server_st& server)
+memcached_error_t *memcached_error_copy(const memcached_instance_st& server)
{
if (server.error_messages == NULL)
{
return MEMCACHED_SUCCESS;
}
+
+memcached_return_t memcached_instance_error_return(memcached_instance_st* instance)
+{
+ if (instance == NULL)
+ {
+ return MEMCACHED_INVALID_ARGUMENTS;
+ }
+
+ if (instance and instance->error_messages)
+ {
+ return instance->error_messages->rc;
+ }
+
+ return MEMCACHED_SUCCESS;
+}
memcached_return_t memcached_set_error(memcached_st&, memcached_return_t rc, const char *at);
LIBMEMCACHED_LOCAL
- memcached_return_t memcached_set_error(memcached_server_st&, memcached_return_t rc, const char *at);
+ memcached_return_t memcached_set_error(memcached_instance_st&, memcached_return_t rc, const char *at);
LIBMEMCACHED_LOCAL
memcached_return_t memcached_set_error(memcached_st&, memcached_return_t rc, const char *at, const char *str, size_t length);
LIBMEMCACHED_LOCAL
- memcached_return_t memcached_set_error(memcached_server_st&, memcached_return_t rc, const char *at, const char *str, size_t length);
+ memcached_return_t memcached_set_error(memcached_instance_st&, memcached_return_t rc, const char *at, const char *str, size_t length);
LIBMEMCACHED_LOCAL
memcached_return_t memcached_set_error(memcached_st& memc, memcached_return_t rc, const char *at, memcached_string_t& str);
LIBMEMCACHED_LOCAL
- memcached_return_t memcached_set_error(memcached_server_st&, memcached_return_t rc, const char *at, memcached_string_t& str);
+ memcached_return_t memcached_set_error(memcached_instance_st&, memcached_return_t rc, const char *at, memcached_string_t& str);
LIBMEMCACHED_LOCAL
memcached_return_t memcached_set_errno(memcached_st& memc, int local_errno, const char *at, memcached_string_t& str);
LIBMEMCACHED_LOCAL
- memcached_return_t memcached_set_errno(memcached_server_st&, int local_errno, const char *at, memcached_string_t& str);
+ memcached_return_t memcached_set_errno(memcached_instance_st&, int local_errno, const char *at, memcached_string_t& str);
LIBMEMCACHED_LOCAL
memcached_return_t memcached_set_errno(memcached_st& memc, int local_errno, const char *at, const char *str, size_t length);
LIBMEMCACHED_LOCAL
- memcached_return_t memcached_set_errno(memcached_server_st&, int local_errno, const char *at, const char *str, size_t length);
+ memcached_return_t memcached_set_errno(memcached_instance_st&, int local_errno, const char *at, const char *str, size_t length);
LIBMEMCACHED_LOCAL
memcached_return_t memcached_set_errno(memcached_st& memc, int local_errno, const char *at);
LIBMEMCACHED_LOCAL
- memcached_return_t memcached_set_errno(memcached_server_st&, int local_errno, const char *at);
+ memcached_return_t memcached_set_errno(memcached_instance_st&, int local_errno, const char *at);
LIBMEMCACHED_LOCAL
bool memcached_has_current_error(memcached_st&);
LIBMEMCACHED_LOCAL
-bool memcached_has_current_error(memcached_server_st&);
+bool memcached_has_current_error(memcached_instance_st&);
LIBMEMCACHED_LOCAL
void memcached_error_free(memcached_st&);
+void memcached_error_free(memcached_server_st& self);
+
LIBMEMCACHED_LOCAL
-void memcached_error_free(memcached_server_st&);
+void memcached_error_free(memcached_instance_st&);
LIBMEMCACHED_LOCAL
-memcached_error_t *memcached_error_copy(const memcached_server_st&);
+memcached_error_t *memcached_error_copy(const memcached_instance_st&);
+
+memcached_return_t memcached_instance_error_return(memcached_instance_st*);
#endif
}
*error= MEMCACHED_MAXIMUM_RETURN; // We use this to see if we ever go into the loop
- memcached_server_st *server;
+ memcached_instance_st *server;
while ((server= memcached_io_get_readable_server(ptr)))
{
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
{
memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x);
- if (memcached_server_response_count(instance) > 0)
+ if (memcached_instance_response_count(instance) > 0)
{
(void)memcached_response(instance, NULL, 0, NULL);
}
{
memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x);
- if (memcached_server_response_count(instance))
+ if (memcached_instance_response_count(instance))
{
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
memcached_io_write(instance);
}
- while(memcached_server_response_count(instance))
+ while(memcached_instance_response_count(instance))
{
(void)memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, &ptr->result);
}
};
- if (memcached_server_response_count(instance) == 0)
+ if (memcached_instance_response_count(instance) == 0)
{
rc= memcached_connect(instance);
continue;
}
WATCHPOINT_ASSERT(instance->cursor_active == 0);
- memcached_server_response_increment(instance);
+ memcached_instance_response_increment(instance);
WATCHPOINT_ASSERT(instance->cursor_active == 1);
}
else
{
if ((memcached_io_writev(instance, (vector + 1), 3, false)) == false)
{
- memcached_server_response_reset(instance);
+ memcached_instance_response_reset(instance);
failures_occured_in_sending= true;
continue;
}
memcached_server_write_instance_st instance=
memcached_server_instance_fetch(ptr, x);
- if (memcached_server_response_count(instance))
+ if (memcached_instance_response_count(instance))
{
/* We need to do something about non-connnected hosts in the future */
if ((memcached_io_write(instance, "\r\n", 2, true)) == -1)
memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, server_key);
- if (memcached_server_response_count(instance) == 0)
+ if (memcached_instance_response_count(instance) == 0)
{
rc= memcached_connect(instance);
if (memcached_failed(rc))
memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x);
initialize_binary_request(instance, request.message.header);
- if (memcached_server_response_count(instance))
+ if (memcached_instance_response_count(instance))
{
if (memcached_io_write(instance) == false)
{
- memcached_server_response_reset(instance);
+ memcached_instance_response_reset(instance);
memcached_io_reset(instance);
rc= MEMCACHED_SOME_ERRORS;
}
if (memcached_io_write(instance, request.bytes,
sizeof(request.bytes), true) == -1)
{
- memcached_server_response_reset(instance);
+ memcached_instance_response_reset(instance);
memcached_io_reset(instance);
rc= MEMCACHED_SOME_ERRORS;
}
memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, server);
- if (memcached_server_response_count(instance) == 0)
+ if (memcached_instance_response_count(instance) == 0)
{
rc= memcached_connect(instance);
{
memcached_server_write_instance_st instance;
- qsort(memcached_server_list(ptr), memcached_server_count(ptr), sizeof(memcached_server_st), compare_servers);
+ qsort(memcached_instance_list(ptr), memcached_server_count(ptr), sizeof(memcached_instance_st), compare_servers);
instance= memcached_server_instance_fetch(ptr, 0);
instance->number_of_hosts= memcached_server_count(ptr);
}
static memcached_return_t update_continuum(memcached_st *ptr)
{
uint32_t continuum_index= 0;
- memcached_server_st *list;
uint32_t pointer_counter= 0;
uint32_t pointer_per_server= MEMCACHED_POINTS_PER_SERVER;
uint32_t pointer_per_hash= 1;
return memcached_set_errno(*ptr, errno, MEMCACHED_AT);
}
- list= memcached_server_list(ptr);
+ memcached_instance_st *list= memcached_instance_list(ptr);
/* count live servers (those without a retry delay set) */
bool is_auto_ejecting= _is_auto_eject_host(ptr);
{
assert_msg(ptr, "Programmer mistake, somehow server_add() was passed a NULL memcached_st");
- memcached_server_st *new_host_list= libmemcached_xrealloc(ptr, memcached_server_list(ptr), (ptr->number_of_hosts + 1), memcached_server_st);
+ memcached_instance_st *new_host_list= libmemcached_xrealloc(ptr, memcached_instance_list(ptr), (ptr->number_of_hosts + 1), memcached_instance_st);
if (new_host_list == NULL)
{
return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT);
}
- memcached_server_list_set(ptr, new_host_list);
+ memcached_instance_set(ptr, new_host_list);
/* TODO: Check return type */
memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, memcached_server_count(ptr));
- if (__server_create_with(ptr, instance, hostname, port, weight, type) == NULL)
+ if (__instance_create_with(ptr, instance, hostname, port, weight, type) == NULL)
{
return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT);
}
// @note we place the count in the bottom of the server list
instance= memcached_server_instance_fetch(ptr, 0);
- memcached_servers_set_count(instance, memcached_server_count(ptr));
+ memcached_instance_set_count(instance, memcached_server_count(ptr));
return run_distribution(ptr);
}
uint32_t count= memcached_server_list_count(list);
- memcached_server_st *new_host_list;
- new_host_list= libmemcached_xrealloc(ptr, memcached_server_list(ptr), (count + memcached_server_count(ptr)), memcached_server_st);
+ memcached_instance_st *new_host_list= libmemcached_xrealloc(ptr, memcached_instance_list(ptr), (count + memcached_server_count(ptr)), memcached_instance_st);
if (new_host_list == NULL)
{
return MEMCACHED_MEMORY_ALLOCATION_FAILURE;
}
- memcached_server_list_set(ptr, new_host_list);
+ memcached_instance_set(ptr, new_host_list);
for (uint32_t x= 0; x < count; x++)
{
WATCHPOINT_ASSERT(instance);
memcached_string_t hostname= { memcached_string_make_from_cstr(list[x].hostname) };
- if (__server_create_with(ptr, instance,
- hostname,
- list[x].port, list[x].weight, list[x].type) == NULL)
+ if (__instance_create_with(ptr, instance,
+ hostname,
+ list[x].port, list[x].weight, list[x].type) == NULL)
+ {
+ return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT);
+ }
+
+ if (list[x].weight > 1)
+ {
+ ptr->ketama.weighted= true;
+ }
+
+ ptr->number_of_hosts++;
+ }
+
+ // Provides backwards compatibility with server list.
+ {
+ memcached_server_write_instance_st instance;
+ instance= memcached_server_instance_fetch(ptr, 0);
+ instance->number_of_hosts= memcached_server_count(ptr);
+ }
+
+ return run_distribution(ptr);
+}
+
+memcached_return_t memcached_instance_push(memcached_st *ptr, const struct memcached_instance_st* list, uint32_t number_of_hosts)
+{
+ if (list == NULL)
+ {
+ return MEMCACHED_SUCCESS;
+ }
+
+ memcached_instance_st* new_host_list= libmemcached_xrealloc(ptr, memcached_instance_list(ptr), (number_of_hosts +memcached_server_count(ptr)), memcached_instance_st);
+
+ if (new_host_list == NULL)
+ {
+ return MEMCACHED_MEMORY_ALLOCATION_FAILURE;
+ }
+
+ memcached_instance_set(ptr, new_host_list);
+
+ for (uint32_t x= 0; x < number_of_hosts; x++)
+ {
+ memcached_server_write_instance_st instance;
+
+ WATCHPOINT_ASSERT(list[x].hostname[0] != 0);
+
+ // We have extended the array, and now we will find it, and use it.
+ instance= memcached_server_instance_fetch(ptr, memcached_server_count(ptr));
+ WATCHPOINT_ASSERT(instance);
+
+ memcached_string_t hostname= { memcached_string_make_from_cstr(list[x].hostname) };
+ if (__instance_create_with(ptr, instance,
+ hostname,
+ list[x].port, list[x].weight, list[x].type) == NULL)
{
return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT);
}
libmemcached_libmemcached_la_CXXFLAGS= -DBUILDING_LIBMEMCACHED
+libmemcached_libmemcached_la_SOURCES+= libmemcached/instance.cc
libmemcached_libmemcached_la_SOURCES+= \
${libhashkit_libhashkit_la_SOURCES} \
libmemcached/allocators.cc \
--- /dev/null
+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ *
+ * Libmemcached library
+ *
+ * Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ * Copyright (C) 2006-2009 Brian Aker All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * * The names of its contributors may not be used to endorse or
+ * promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/*
+ This is a partial implementation for fetching/creating memcached_instance_st objects.
+*/
+#include <libmemcached/common.h>
+
+static inline void _server_init(memcached_instance_st *self, memcached_st *root,
+ const memcached_string_t& hostname,
+ in_port_t port,
+ uint32_t weight, memcached_connection_t type)
+{
+ 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= INVALID_SOCKET;
+ self->io_bytes_sent= 0;
+ self->request_id= 0;
+ self->server_failure_counter= 0;
+ self->server_failure_counter_query_id= 0;
+ self->weight= weight ? weight : 1; // 1 is the default weight value
+ self->io_wait_count.read= 0;
+ self->io_wait_count.write= 0;
+ self->io_wait_count.timeouts= 0;
+ self->io_wait_count._bytes_read= 0;
+ self->major_version= UINT8_MAX;
+ self->micro_version= UINT8_MAX;
+ self->minor_version= UINT8_MAX;
+ self->type= type;
+ self->error_messages= NULL;
+ self->read_ptr= self->read_buffer;
+ self->read_buffer_length= 0;
+ self->read_data_length= 0;
+ self->write_buffer_offset= 0;
+ self->address_info= NULL;
+ self->address_info_next= NULL;
+
+ self->state= MEMCACHED_SERVER_STATE_NEW;
+ self->next_retry= 0;
+
+ self->root= root;
+ if (root)
+ {
+ self->version= ++root->server_info.version;
+ }
+ else
+ {
+ self->version= UINT_MAX;
+ }
+ self->limit_maxbytes= 0;
+ memcpy(self->hostname, hostname.c_str, hostname.size);
+ self->hostname[hostname.size]= 0;
+}
+
+static memcached_instance_st *_server_create(memcached_instance_st *self, const memcached_st *memc)
+{
+ if (self == NULL)
+ {
+ self= libmemcached_xmalloc(memc, struct memcached_instance_st);
+
+ if (self == NULL)
+ {
+ return NULL; /* MEMCACHED_MEMORY_ALLOCATION_FAILURE */
+ }
+
+ self->options.is_allocated= true;
+ }
+ else
+ {
+ self->options.is_allocated= false;
+ }
+
+ self->options.is_initialized= true;
+
+ return self;
+}
+
+memcached_instance_st *__instance_create_with(memcached_st *memc,
+ memcached_instance_st* self,
+ const memcached_string_t& hostname,
+ const in_port_t port,
+ uint32_t weight,
+ const memcached_connection_t type)
+{
+ if (memcached_is_valid_servername(hostname) == false)
+ {
+ memcached_set_error(*memc, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Invalid hostname provided"));
+ return NULL;
+ }
+
+ self= _server_create(self, memc);
+
+ if (self == NULL)
+ {
+ return NULL;
+ }
+
+ _server_init(self, const_cast<memcached_st *>(memc), hostname, port, weight, type);
+
+ if (memc and memcached_is_udp(memc))
+ {
+ self->write_buffer_offset= UDP_DATAGRAM_HEADER_LENGTH;
+ memcached_io_init_udp_header(self, 0);
+ }
+
+ if (memc)
+ {
+ memcached_connect_try(self);
+ }
+
+ return self;
+}
+
+void __instance_free(memcached_instance_st *self)
+{
+ memcached_quit_server(self, false);
+
+ if (self->address_info)
+ {
+ freeaddrinfo(self->address_info);
+ self->address_info= NULL;
+ self->address_info_next= NULL;
+ }
+
+ memcached_error_free(*self);
+
+ if (memcached_is_allocated(self))
+ {
+ libmemcached_free(self->root, self);
+ }
+ else
+ {
+ self->options.is_initialized= false;
+ }
+}
+
+void memcached_instance_free(memcached_instance_st *self)
+{
+ if (self == NULL)
+ {
+ return;
+ }
+
+ if (memcached_instance_count(self))
+ {
+ memcached_instance_list_free(self, memcached_instance_count(self));
+ return;
+ }
+
+ __instance_free(self);
+}
+
+/*
+ If we do not have a valid object to clone from, we toss an error.
+*/
+memcached_server_st *memcached_instance_2_server(memcached_instance_st *source)
+{
+ /* We just do a normal create if source is missing */
+ if (source == NULL)
+ {
+ return NULL;
+ }
+
+ memcached_string_t hostname= { memcached_string_make_from_cstr(source->hostname) };
+ return __server_create_with(source->root, NULL,
+ hostname,
+ source->port, source->weight,
+ source->type);
+
+}
+
+memcached_return_t memcached_server_cursor(const memcached_st *ptr,
+ const memcached_server_fn *callback,
+ void *context,
+ uint32_t number_of_callbacks)
+{
+ memcached_return_t rc;
+ if (memcached_failed(rc= initialize_const_query(ptr)))
+ {
+ return rc;
+ }
+
+ size_t errors= 0;
+ for (uint32_t x= 0; x < memcached_instance_list_count(ptr); x++)
+ {
+ memcached_server_instance_st instance=
+ memcached_server_instance_by_position(ptr, x);
+
+ for (uint32_t y= 0; y < number_of_callbacks; y++)
+ {
+ memcached_return_t ret= (*callback[y])(ptr, instance, context);
+
+ if (memcached_failed(ret))
+ {
+ errors++;
+ continue;
+ }
+ }
+ }
+
+ return errors ? MEMCACHED_SOME_ERRORS : MEMCACHED_SUCCESS;
+}
+
+memcached_return_t memcached_server_execute(memcached_st *ptr,
+ memcached_server_execute_fn callback,
+ void *context)
+{
+ if (callback == NULL)
+ {
+ return MEMCACHED_INVALID_ARGUMENTS;
+ }
+
+ bool some_errors= false;;
+ for (uint32_t x= 0; x < memcached_instance_list_count(ptr); x++)
+ {
+ memcached_instance_st* instance= memcached_server_instance_fetch(ptr, x);
+
+ memcached_return_t rc= (*callback)(ptr, instance, context);
+ if (rc == MEMCACHED_INVALID_ARGUMENTS)
+ {
+ return rc;
+ }
+ else if (memcached_fatal(rc))
+ {
+ some_errors= true;
+ }
+ }
+
+ (void)some_errors;
+ return MEMCACHED_SUCCESS;
+}
+
+memcached_server_instance_st memcached_server_by_key(memcached_st *ptr,
+ const char *key,
+ size_t key_length,
+ memcached_return_t *error)
+{
+ memcached_return_t unused;
+ if (not error)
+ {
+ error= &unused;
+ }
+
+
+ memcached_return_t rc;
+ if (memcached_failed(rc= initialize_const_query(ptr)))
+ {
+ *error= rc;
+ return NULL;
+ }
+
+ if (memcached_failed((memcached_key_test(*ptr, (const char **)&key, &key_length, 1))))
+ {
+ *error= memcached_last_error(ptr);
+ return NULL;
+ }
+
+ uint32_t server_key= memcached_generate_hash(ptr, key, key_length);
+ return memcached_server_instance_by_position(ptr, server_key);
+}
+
+/*
+ If we do not have a valid object to clone from, we toss an error.
+*/
+static memcached_instance_st *memcached_instance_clone(memcached_instance_st *source)
+{
+ /* We just do a normal create if source is missing */
+ if (source == NULL)
+ {
+ return NULL;
+ }
+
+ memcached_string_t hostname= { memcached_string_make_from_cstr(source->hostname) };
+ return __instance_create_with(source->root,
+ NULL,
+ hostname,
+ source->port, source->weight,
+ source->type);
+}
+
+void set_last_disconnected_host(memcached_server_write_instance_st self)
+{
+ assert(self->root);
+ if (self->root == NULL)
+ {
+ return;
+ }
+
+ if (self->root->last_disconnected_server and self->root->last_disconnected_server->version == self->version)
+ {
+ return;
+ }
+
+ // const_cast
+ memcached_st *root= (memcached_st *)self->root;
+
+ memcached_instance_free(root->last_disconnected_server);
+ root->last_disconnected_server= memcached_instance_clone(self);
+ root->last_disconnected_server->version= self->version;
+}
+
+memcached_server_instance_st memcached_server_get_last_disconnect(const memcached_st *self)
+{
+ WATCHPOINT_ASSERT(self);
+ if (self == NULL)
+ {
+ return 0;
+ }
+
+ return self->last_disconnected_server;
+}
+
+uint32_t memcached_instance_set_count(memcached_instance_st *servers, uint32_t count)
+{
+ WATCHPOINT_ASSERT(servers);
+ if (servers == NULL)
+ {
+ return 0;
+ }
+
+ return servers->number_of_hosts= count;
+}
+
+const char *memcached_instance_name(const memcached_server_instance_st self)
+{
+ WATCHPOINT_ASSERT(self);
+ if (self == NULL)
+ return NULL;
+
+ return self->hostname;
+}
+
+in_port_t memcached_instance_port(const memcached_server_instance_st self)
+{
+ WATCHPOINT_ASSERT(self);
+ if (self == NULL)
+ {
+ return 0;
+ }
+
+ return self->port;
+}
+
+uint32_t memcached_instance_response_count(const memcached_instance_st* self)
+{
+ WATCHPOINT_ASSERT(self);
+ if (self == NULL)
+ {
+ return 0;
+ }
+
+ return self->cursor_active;
+}
--- /dev/null
+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ *
+ * Libmemcached library
+ *
+ * Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * * The names of its contributors may not be used to endorse or
+ * promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+
+#pragma once
+
+#ifndef WIN32
+#include <netdb.h>
+#endif
+
+#ifdef NI_MAXHOST
+#define MEMCACHED_NI_MAXHOST NI_MAXHOST
+#else
+#define MEMCACHED_NI_MAXHOST 1025
+#endif
+
+#ifdef NI_MAXSERV
+#define MEMCACHED_NI_MAXSERV NI_MAXSERV
+#else
+#define MEMCACHED_NI_MAXSERV 32
+#endif
+
+struct memcached_instance_st {
+ struct {
+ bool is_allocated:1;
+ bool is_initialized:1;
+ bool is_shutting_down:1;
+ bool is_dead:1;
+ } options;
+ uint32_t number_of_hosts;
+ uint32_t cursor_active;
+ in_port_t port;
+ memcached_socket_t fd;
+ uint32_t io_bytes_sent; /* # bytes sent since last read */
+ uint32_t request_id;
+ uint32_t server_failure_counter;
+ uint64_t server_failure_counter_query_id;
+ uint32_t weight;
+ uint32_t version;
+ enum memcached_server_state_t state;
+ struct {
+ uint32_t read;
+ uint32_t write;
+ uint32_t timeouts;
+ size_t _bytes_read;
+ } io_wait_count;
+ uint8_t major_version; // Default definition of UINT8_MAX means that it has not been set.
+ uint8_t micro_version; // ditto, and note that this is the third, not second version bit
+ uint8_t minor_version; // ditto
+ memcached_connection_t type;
+ char *read_ptr;
+ size_t read_buffer_length;
+ size_t read_data_length;
+ size_t write_buffer_offset;
+ struct addrinfo *address_info;
+ struct addrinfo *address_info_next;
+ time_t next_retry;
+ struct memcached_st *root;
+ uint64_t limit_maxbytes;
+ struct memcached_error_t *error_messages;
+ char read_buffer[MEMCACHED_MAX_BUFFER];
+ char write_buffer[MEMCACHED_MAX_BUFFER];
+ char hostname[MEMCACHED_NI_MAXHOST];
+};
--- /dev/null
+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ *
+ * Libmemcached library
+ *
+ * Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * * The names of its contributors may not be used to endorse or
+ * promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+
+#pragma once
+
+struct memcached_instance_st *__instance_create_with(memcached_st *memc,
+ struct memcached_instance_st* self,
+ const memcached_string_t& hostname,
+ const in_port_t port,
+ uint32_t weight,
+ const memcached_connection_t type);
+void __instance_free(struct memcached_instance_st *);
+
+memcached_server_st *memcached_instance_2_server(struct memcached_instance_st*);
+
+memcached_return_t memcached_instance_push(memcached_st *ptr, const struct memcached_instance_st*, uint32_t);
+
+uint32_t memcached_instance_set_count(memcached_instance_st *servers, uint32_t count);
+const char *memcached_instance_name(const memcached_server_instance_st self);
+in_port_t memcached_instance_port(const memcached_server_instance_st self);
+uint32_t memcached_instance_response_count(const memcached_instance_st* self);
+uint32_t memcached_instance_count(const memcached_st* self);
+
if (memcached_has_error(ptr))
{
- return memcached_server_error_return(ptr);
+ return memcached_instance_error_return(ptr);
}
return memcached_set_error(*ptr, MEMCACHED_CONNECTION_FAILURE, MEMCACHED_AT,
break;
}
- return memcached_server_error_return(ptr);
+ return memcached_instance_error_return(ptr);
}
else if (data_read == 0)
{
return instance;
}
- if (memcached_server_response_count(instance) > 0)
+ if (memcached_instance_response_count(instance) > 0)
{
- fds[host_index].events = POLLIN;
- fds[host_index].revents = 0;
- fds[host_index].fd = instance->fd;
+ fds[host_index].events= POLLIN;
+ fds[host_index].revents= 0;
+ fds[host_index].fd= instance->fd;
++host_index;
}
}
/* We have 0 or 1 server with pending events.. */
for (uint32_t x= 0; x< memcached_server_count(memc); ++x)
{
- memcached_server_write_instance_st instance=
- memcached_server_instance_fetch(memc, x);
+ memcached_server_write_instance_st instance= memcached_server_instance_fetch(memc, x);
- if (memcached_server_response_count(instance) > 0)
+ if (memcached_instance_response_count(instance) > 0)
{
return instance;
}
{
/* If we have anything open, lets close it now */
send_quit(ptr);
- memcached_server_list_free(memcached_server_list(ptr));
+ memcached_instance_list_free(memcached_instance_list(ptr), memcached_instance_list_count(ptr));
memcached_result_free(&ptr->result);
memcached_virtual_bucket_free(ptr);
- memcached_server_free(ptr->last_disconnected_server);
+ memcached_instance_free(ptr->last_disconnected_server);
if (ptr->on_cleanup)
{
{
if (self)
{
- memcached_server_list_free(memcached_server_list(self));
+ memcached_instance_list_free(memcached_instance_list(self), self->number_of_hosts);
- memcached_server_list_set(self, NULL);
+ memcached_instance_set(self, NULL);
self->number_of_hosts= 0;
- memcached_server_free(self->last_disconnected_server);
+ memcached_instance_free(self->last_disconnected_server);
self->last_disconnected_server= NULL;
}
}
{
if (self)
{
- memcached_server_free(self->last_disconnected_server);
+ memcached_instance_free(self->last_disconnected_server);
self->last_disconnected_server= NULL;
}
}
memcached_return_t memcached_push(memcached_st *destination, const memcached_st *source)
{
- return memcached_server_push(destination, source->servers);
+ return memcached_instance_push(destination, source->servers, source->number_of_hosts);
}
memcached_server_write_instance_st memcached_server_instance_fetch(memcached_st *ptr, uint32_t server_key)
will force data to be completed.
*/
-void memcached_quit_server(memcached_server_st *ptr, bool io_death)
+void memcached_quit_server(memcached_instance_st *ptr, bool io_death)
{
if (ptr->fd != INVALID_SOCKET)
{
#pragma once
-void memcached_quit_server(memcached_server_st *ptr, bool io_death);
+void memcached_quit_server(memcached_instance_st *ptr, bool io_death);
void send_quit(memcached_st *ptr);
* @param raddr remote address (out)
* @return true on success false otherwise (errno contains more info)
*/
-static memcached_return_t resolve_names(memcached_server_st& server, char *laddr, size_t laddr_length, char *raddr, size_t raddr_length)
+static memcached_return_t resolve_names(memcached_instance_st& server, char *laddr, size_t laddr_length, char *raddr, size_t raddr_length)
{
char host[NI_MAXHOST];
char port[NI_MAXSERV];
} // extern "C"
-memcached_return_t memcached_sasl_authenticate_connection(memcached_server_st *server)
+memcached_return_t memcached_sasl_authenticate_connection(memcached_instance_st *server)
{
if (LIBMEMCACHED_WITH_SASL_SUPPORT == 0)
{
memcached_return_t memcached_clone_sasl(memcached_st *clone, const memcached_st *source);
-memcached_return_t memcached_sasl_authenticate_connection(memcached_server_st *server);
+memcached_return_t memcached_sasl_authenticate_connection(memcached_instance_st *server);
}
memcached_server_st *__server_create_with(memcached_st *memc,
- memcached_server_write_instance_st self,
+ memcached_server_st* self,
const memcached_string_t& hostname,
const in_port_t port,
uint32_t weight,
_server_init(self, const_cast<memcached_st *>(memc), hostname, port, weight, type);
- if (memc and memcached_is_udp(memc))
- {
- self->write_buffer_offset= UDP_DATAGRAM_HEADER_LENGTH;
- memcached_io_init_udp_header(self, 0);
- }
-
- if (memc)
- {
- memcached_connect_try(self);
- }
-
return self;
}
void __server_free(memcached_server_st *self)
{
- memcached_quit_server(self, false);
-
- if (self->address_info)
- {
- freeaddrinfo(self->address_info);
- self->address_info= NULL;
- self->address_info_next= NULL;
- }
-
memcached_error_free(*self);
if (memcached_is_allocated(self))
__server_free(self);
}
-/*
- If we do not have a valid object to clone from, we toss an error.
-*/
-memcached_server_st *memcached_server_clone(memcached_server_st *destination,
- memcached_server_st *source)
-{
- /* We just do a normal create if source is missing */
- if (source == NULL)
- {
- return NULL;
- }
-
- memcached_string_t hostname= { memcached_string_make_from_cstr(source->hostname) };
- destination= __server_create_with(source->root, destination,
- hostname,
- source->port, source->weight,
- source->type);
- return destination;
-
-}
-
-memcached_return_t memcached_server_cursor(const memcached_st *ptr,
- const memcached_server_fn *callback,
- void *context,
- uint32_t number_of_callbacks)
-{
- memcached_return_t rc;
- if (memcached_failed(rc= initialize_const_query(ptr)))
- {
- return rc;
- }
-
- size_t errors= 0;
- for (uint32_t x= 0; x < memcached_server_count(ptr); x++)
- {
- memcached_server_instance_st instance=
- memcached_server_instance_by_position(ptr, x);
-
- for (uint32_t y= 0; y < number_of_callbacks; y++)
- {
- memcached_return_t ret= (*callback[y])(ptr, instance, context);
-
- if (memcached_failed(ret))
- {
- errors++;
- continue;
- }
- }
- }
-
- return errors ? MEMCACHED_SOME_ERRORS : MEMCACHED_SUCCESS;
-}
-
-memcached_return_t memcached_server_execute(memcached_st *ptr,
- memcached_server_execute_fn callback,
- void *context)
-{
- if (callback == NULL)
- {
- return MEMCACHED_INVALID_ARGUMENTS;
- }
-
- bool some_errors= false;;
- for (uint32_t x= 0; x < memcached_server_count(ptr); x++)
- {
- memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x);
-
- memcached_return_t rc= (*callback)(ptr, instance, context);
- if (rc == MEMCACHED_INVALID_ARGUMENTS)
- {
- return rc;
- }
- else if (memcached_fatal(rc))
- {
- some_errors= true;
- }
- }
-
- (void)some_errors;
- return MEMCACHED_SUCCESS;
-}
-
-memcached_server_instance_st memcached_server_by_key(memcached_st *ptr,
- const char *key,
- size_t key_length,
- memcached_return_t *error)
-{
- memcached_return_t unused;
- if (not error)
- {
- error= &unused;
- }
-
-
- memcached_return_t rc;
- if (memcached_failed(rc= initialize_const_query(ptr)))
- {
- *error= rc;
- return NULL;
- }
-
- if (memcached_failed((memcached_key_test(*ptr, (const char **)&key, &key_length, 1))))
- {
- *error= memcached_last_error(ptr);
- return NULL;
- }
-
- uint32_t server_key= memcached_generate_hash(ptr, key, key_length);
- return memcached_server_instance_by_position(ptr, server_key);
-
-}
-
void memcached_server_error_reset(memcached_server_st *self)
{
WATCHPOINT_ASSERT(self);
memcached_error_free(*self);
}
-memcached_server_instance_st memcached_server_get_last_disconnect(const memcached_st *self)
-{
- WATCHPOINT_ASSERT(self);
- if (self == NULL)
- {
- return 0;
- }
-
- return self->last_disconnected_server;
-}
-
uint32_t memcached_servers_set_count(memcached_server_st *servers, uint32_t count)
{
WATCHPOINT_ASSERT(servers);
return "UNKNOWN";
}
+
+uint8_t memcached_server_major_version(const memcached_server_instance_st instance)
+{
+ if (instance)
+ {
+ return instance->major_version;
+ }
+
+ return UINT8_MAX;
+}
+
+uint8_t memcached_server_minor_version(const memcached_server_instance_st instance)
+{
+ if (instance)
+ {
+ return instance->minor_version;
+ }
+
+ return UINT8_MAX;
+}
+
+uint8_t memcached_server_micro_version(const memcached_server_instance_st instance)
+{
+ if (instance)
+ {
+ return instance->micro_version;
+ }
+
+ return UINT8_MAX;
+}
#include <cassert>
memcached_server_st *__server_create_with(memcached_st *memc,
- memcached_server_write_instance_st host,
+ memcached_server_st* self,
const memcached_string_t& hostname,
const in_port_t port,
- uint32_t weight,
+ uint32_t weight,
const memcached_connection_t type);
-memcached_server_st *memcached_server_clone(memcached_server_st *destination,
- memcached_server_st *source);
-
memcached_return_t memcached_server_add_parsed(memcached_st *ptr,
const char *hostname,
size_t hostname_length,
server->next_retry= 0;
}
+void memcached_instance_free(memcached_instance_st *);
-static inline void set_last_disconnected_host(memcached_server_write_instance_st self)
-{
- assert(self->root);
- if (self->root == NULL)
- {
- return;
- }
-
- if (self->root->last_disconnected_server and self->root->last_disconnected_server->version == self->version)
- {
- return;
- }
-
- // const_cast
- memcached_st *root= (memcached_st *)self->root;
-
- memcached_server_free(root->last_disconnected_server);
- root->last_disconnected_server= memcached_server_clone(NULL, self);
- root->last_disconnected_server->version= self->version;
-}
+void set_last_disconnected_host(memcached_server_write_instance_st self);
static inline void memcached_mark_server_for_timeout(memcached_server_write_instance_st server)
{
extern "C" {
#endif
-typedef struct memcached_server_st * memcached_server_write_instance_st;
+typedef struct memcached_instance_st * memcached_server_write_instance_st;
#ifdef __cplusplus
}
memcached_return_t *error)
{
uint32_t count;
- memcached_server_list_st new_host_list;
memcached_return_t unused;
if (error == NULL)
count+= memcached_server_list_count(ptr);
}
- new_host_list= (memcached_server_write_instance_st)realloc(ptr, sizeof(memcached_server_st) * count);
- if (not new_host_list)
+ memcached_server_list_st new_host_list= (memcached_server_st*)realloc(ptr, sizeof(memcached_server_st) * count);
+ if (new_host_list == NULL)
{
+#if 0
*error= memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT);
+#endif
return NULL;
}
/* @todo Check return type */
if (__server_create_with(NULL, &new_host_list[count-1], _hostname, port, weight, port ? MEMCACHED_CONNECTION_TCP : MEMCACHED_CONNECTION_UNIX_SOCKET) == NULL)
{
+#if 0
*error= memcached_set_errno(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT);
+#endif
return NULL;
}
: self->number_of_hosts;
}
-memcached_server_st *memcached_server_list(const memcached_st *self)
+uint32_t memcached_instance_list_count(const memcached_st* self)
+{
+ return (self == NULL)
+ ? 0
+ : self->number_of_hosts;
+}
+
+uint32_t memcached_instance_count(const memcached_instance_st* self)
+{
+ return (self == NULL)
+ ? 0
+ : self->number_of_hosts;
+}
+
+memcached_instance_st *memcached_instance_list(const memcached_st *self)
{
if (self)
{
return NULL;
}
-void memcached_server_list_set(memcached_st *self, memcached_server_st *list)
+void memcached_instance_set(memcached_st *self, memcached_instance_st *list)
{
self->servers= list;
}
void memcached_server_list_free(memcached_server_list_st self)
{
- if (not self)
+ if (self == NULL)
+ {
return;
+ }
for (uint32_t x= 0; x < memcached_server_list_count(self); x++)
{
libmemcached_free(self->root, self);
}
+
+void memcached_instance_list_free(memcached_instance_st* self, uint32_t instance_count)
+{
+ if (self == NULL)
+ {
+ return;
+ }
+
+ for (uint32_t x= 0; x < instance_count; x++)
+ {
+ assert_msg(not memcached_is_allocated(&self[x]), "You have called memcached_server_list_free(), but you did not pass it a valid memcached_server_list_st");
+ __instance_free(&self[x]);
+ }
+
+ libmemcached_free(self->root, self);
+}
uint32_t memcached_servers_set_count(memcached_server_list_st servers, uint32_t count);
+uint32_t memcached_instance_set_count(memcached_instance_st* servers, uint32_t count);
-memcached_server_st *memcached_server_list(const memcached_st *);
+memcached_instance_st *memcached_instance_list(const memcached_st *);
-void memcached_server_list_set(memcached_st *self, memcached_server_list_st list);
+void memcached_instance_set(memcached_st *self, memcached_instance_st* list);
+
+void memcached_instance_list_free(memcached_instance_st* self, uint32_t);
+
+uint32_t memcached_server_list_count(const memcached_server_list_st self);
+uint32_t memcached_instance_list_count(const memcached_st*);
+uint32_t memcached_instance_count(const memcached_instance_st*);
};
static memcached_return_t _set_verbosity(const memcached_st *,
- const memcached_server_st *server,
+ const memcached_server_instance_st server,
void *context)
{
libmemcached_io_vector_st *vector= (libmemcached_io_vector_st *)context;
{
memcached_server_instance_st instance= memcached_server_instance_by_position(memc_ptr, 0);
- assert_msg(instance and instance->error_messages, " ");
- if (instance and instance->error_messages)
+ assert_msg(instance and memcached_server_error(instance), " ");
+ if (instance and memcached_server_error(instance))
{
rc= memcached_server_error_return(instance);
}
#if 0
assert_msg(instance and instance->error_messages, " ");
#endif
- if (instance and instance->error_messages)
+ if (instance and memcached_server_error(instance))
{
rc= memcached_server_error_return(instance);
}
memcached_server_instance_st instance=
memcached_server_instance_by_position(memc_ptr, 0);
- assert_msg(instance and instance->error_messages, " ");
- if (instance and instance->error_messages)
+ assert_msg(instance and memcached_server_error(instance), " ");
+ if (instance and memcached_server_error(instance))
{
rc= memcached_server_error_return(instance);
}
memcached_server_instance_st instance=
memcached_server_instance_by_position(memc_ptr, 0);
- assert_msg(instance and instance->error_messages, " ");
- if (instance and instance->error_messages)
+ assert_msg(instance and memcached_server_error(instance), " ");
+ if (instance and memcached_server_error(instance))
{
rc= memcached_server_error_return(instance);
}
};
static memcached_return_t check_server_version(const memcached_st *,
- const memcached_server_st *instance,
+ memcached_server_instance_st instance,
void *context)
{
/* Do Nothing */
struct local_context *check= (struct local_context *)context;
- if (instance->major_version != UINT8_MAX &&
- instance->major_version >= check->major_version and
- instance->minor_version >= check->minor_version and
- instance->micro_version >= check->micro_version )
+ if (memcached_server_major_version(instance) != UINT8_MAX &&
+ memcached_server_major_version(instance) >= check->major_version and
+ memcached_server_minor_version(instance) >= check->minor_version and
+ memcached_server_micro_version(instance) >= check->micro_version )
{
return MEMCACHED_SUCCESS;
}
--- /dev/null
+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ *
+ * Data Differential YATL (i.e. libtest) library
+ *
+ * Copyright (C) 2012 Data Differential, http://datadifferential.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * * The names of its contributors may not be used to endorse or
+ * promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#pragma once
+
+#if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED
+inline bool operator== (const memcached_st& memc, const memcached_return_t rc)
+{
+ if (memcached_last_error(&memc) == rc)
+ {
+ return true;
+ }
+
+ return false;
+}
+
+inline bool operator!= (const memcached_st& memc, const memcached_return_t rc)
+{
+ if (memcached_last_error(&memc) != rc)
+ {
+ return true;
+ }
+
+ return false;
+}
+
+inline bool operator!= (const memcached_return_t rc, const memcached_st& memc)
+{
+ if (memcached_last_error(&memc) != rc)
+ {
+ return true;
+ }
+
+ return false;
+}
+#endif
+
return TEST_SUCCESS;
}
+#include "libmemcached/instance.h"
static test_return_t cull_TEST(memcached_st *memc)
{
uint32_t count= memcached_server_count(memc);
#include <tests/debug.h>
#include <tests/print.h>
+#include "libmemcached/instance.h"
+
/* Dump each server's keys */
static memcached_return_t print_keys_callback(const memcached_st *,
const char *key,
memcached_server_instance_st instance=
memcached_server_instance_by_position(memc, host_index);
- printf("\nserver %u|%s|%u bytes: %llu\n", host_index, instance->hostname, instance->port, (unsigned long long)(stat_p + host_index)->bytes);
+ printf("\nserver %u|%s|%u bytes: %llu\n",
+ host_index,
+ memcached_server_name(instance),
+ memcached_server_port(instance),
+ (unsigned long long)(stat_p + host_index)->bytes);
}
test_true((unsigned long long)(stat_p + host_index)->bytes);
}
#include <libmemcached/memcached.h>
#include <libmemcached/server_instance.h>
#include <libmemcached/continuum.hpp>
+#include <libmemcached/instance.h>
#include <tests/ketama.h>
#include <tests/ketama_test_cases.h>
#include "tests/keys.hpp"
+#include "libmemcached/instance.h"
+
static memcached_st * create_single_instance_memcached(const memcached_st *original_memc, const char *options)
{
/*
in_port_t test_ports[TEST_PORT_COUNT];
static memcached_return_t server_display_function(const memcached_st *ptr,
- const memcached_server_st *server,
+ memcached_server_instance_st server,
void *context)
{
/* Do Nothing */
}
static memcached_return_t dump_server_information(const memcached_st *ptr,
- const memcached_server_st *instance,
+ memcached_server_instance_st instance,
void *context)
{
/* Do Nothing */
}
static memcached_return_t server_display_unsort_function(const memcached_st*,
- const memcached_server_st *server,
+ memcached_server_instance_st server,
void *context)
{
/* Do Nothing */
}
static memcached_return_t server_function(const memcached_st *,
- const memcached_server_st *,
+ memcached_server_instance_st,
void *)
{
/* Do Nothing */
memcached_st *memc= memcached(test_literal_param("--server=localhost:11311/?100 --server=localhost:11312/?100"));
- const memcached_server_st *server= memcached_server_by_key(memc, "a", 1, &res);
+ memcached_server_instance_st server= memcached_server_by_key(memc, "a", 1, &res);
test_true(server);
memcached_free(memc);
}
static memcached_return_t ping_each_server(const memcached_st*,
- const memcached_server_st *instance,
+ memcached_server_instance_st instance,
void*)
{
// Test both the version that returns a code, and the one that does not.
#include <tests/libmemcached-1.0/parser.h>
#include <tests/print.h>
+#include "libmemcached/instance.h"
enum scanner_type_t
{
}
static memcached_return_t dump_server_information(const memcached_st *,
- const memcached_server_st *instance,
+ memcached_server_instance_st instance,
void *)
{
if (strcmp(memcached_server_name(instance), "localhost"))
};
static memcached_return_t dump_socket_information(const memcached_st *,
- const memcached_server_st *instance,
+ memcached_server_instance_st instance,
void *context)
{
socket_weight_t *check= (socket_weight_t *)context;
#include <pthread.h>
#include <poll.h>
+#include "libmemcached/instance.h"
+
#ifndef __INTEL_COMPILER
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#endif
#include "tests/print.h"
memcached_return_t server_print_callback(const memcached_st*,
- const memcached_server_st *server,
+ memcached_server_instance_st server,
void *context)
{
if (context)
memcached_return_t server_print_version_callback(const memcached_st *,
- const memcached_server_st *server,
+ memcached_server_instance_st server,
void *)
{
std::cerr << "Server: " << memcached_server_name(server) << ":" << memcached_server_port(server) << " "
- << int(server->major_version) << "."
- << int(server->minor_version) << "."
- << int(server->micro_version)
+ << int(memcached_server_major_version(server)) << "."
+ << int(memcached_server_minor_version(server)) << "."
+ << int(memcached_server_micro_version(server))
<< std::endl;
return MEMCACHED_SUCCESS;
return TEST_SUCCESS;
}
+#include "libmemcached/instance.h"
+
test_return_t replication_get_test(memcached_st *memc)
{
#include <libtest/server.h>
+#include "libmemcached/instance.h"
+
#ifndef __INTEL_COMPILER
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#endif
#pragma once
memcached_return_t server_print_callback(const memcached_st *ptr,
- const memcached_server_st *server,
+ memcached_server_instance_st server,
void *context);
memcached_return_t server_print_version_callback(const memcached_st *ptr,
- const memcached_server_st *server,
+ memcached_server_instance_st server,
void *context);
const char * print_version(memcached_st *memc);