LIBMEMCACHED_API
in_port_t memcached_server_port(const memcached_server_instance_st self);
+LIBMEMCACHED_API
+void memcached_instance_next_retry(memcached_server_instance_st self, const time_t absolute_time);
+
LIBMEMCACHED_API
const char *memcached_server_type(const memcached_server_instance_st ptr);
unsigned int version;
} server_info;
uint32_t number_of_hosts;
- struct memcached_instance_st *servers;
- struct memcached_instance_st *last_disconnected_server;
+#ifdef __cplusplus
+ org::libmemcached::Instance* servers;
+ org::libmemcached::Instance* last_disconnected_server;
+#else
+ void *servers;
+ void *last_disconnected_server;
+#endif
int32_t snd_timeout;
int32_t rcv_timeout;
uint32_t server_failure_limit;
#pragma once
#ifdef __cplusplus
+
+namespace org { namespace libmemcached { class Instance; } }
+
struct memcached_st;
struct memcached_stat_st;
struct memcached_analysis_st;
// All of the flavors of memcache_server_st
struct memcached_server_st;
struct memcached_instance_st;
-typedef const struct memcached_instance_st *memcached_server_instance_st;
+typedef const org::libmemcached::Instance* memcached_server_instance_st;
typedef struct memcached_server_st *memcached_server_list_st;
struct memcached_callback_st;
// All of the flavors of memcache_server_st
typedef struct memcached_server_st memcached_server_st;
-typedef const struct memcached_server_st *memcached_server_instance_st;
+typedef const void *memcached_server_instance_st;
typedef struct memcached_server_st *memcached_server_list_st;
typedef struct memcached_callback_st memcached_callback_st;
#include <libmemcached/common.h>
-static void auto_response(memcached_server_write_instance_st instance, const bool reply, memcached_return_t& rc, uint64_t* value)
+static void auto_response(org::libmemcached::Instance* instance, const bool reply, memcached_return_t& rc, uint64_t* value)
{
// If the message was successfully sent, then get the response, otherwise
// fail.
}
}
-static memcached_return_t text_incr_decr(memcached_server_write_instance_st instance,
+static memcached_return_t text_incr_decr(org::libmemcached::Instance* instance,
const bool is_incr,
const char *key, size_t key_length,
const uint64_t offset,
return memcached_vdo(instance, vector, 7, true);
}
-static memcached_return_t binary_incr_decr(memcached_server_write_instance_st instance,
+static memcached_return_t binary_incr_decr(org::libmemcached::Instance* instance,
protocol_binary_command cmd,
const char *key, const size_t key_length,
const uint64_t offset,
}
uint32_t server_key= memcached_generate_hash_with_redistribution(memc, group_key, group_key_length);
- memcached_server_write_instance_st instance= memcached_server_instance_fetch(memc, server_key);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(memc, server_key);
bool reply= memcached_is_replying(instance->root);
}
uint32_t server_key= memcached_generate_hash_with_redistribution(memc, group_key, group_key_length);
- memcached_server_write_instance_st instance= memcached_server_instance_fetch(memc, server_key);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(memc, server_key);
bool reply= memcached_is_replying(instance->root);
return (uint64_t) ptr->send_size;
}
- memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, 0);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, 0);
if (instance) // If we have an instance we test, otherwise we just set and pray
{
if (ptr->recv_size != -1) // If value is -1 then we are using the default
return (uint64_t) ptr->recv_size;
- memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, 0);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, 0);
/**
@note REFACTOR
#include "poll/poll.h"
#endif
-
#ifdef __cplusplus
extern "C" {
#endif
typedef memcached_return_t (*memcached_server_execute_fn)(memcached_st *ptr, memcached_server_write_instance_st server, void *context);
-LIBMEMCACHED_LOCAL
-memcached_server_write_instance_st memcached_server_instance_fetch(memcached_st *ptr, uint32_t server_key);
-
-LIBMEMCACHED_LOCAL
-memcached_return_t memcached_server_execute(memcached_st *ptr,
- memcached_server_execute_fn callback,
- void *context);
#ifdef __cplusplus
} // extern "C"
#endif
+#ifdef __cplusplus
+org::libmemcached::Instance* memcached_instance_fetch(memcached_st *ptr, uint32_t server_key);
+#endif
+
+memcached_return_t memcached_server_execute(memcached_st *ptr,
+ memcached_server_execute_fn callback,
+ void *context);
/* These are private not to be installed headers */
#include <libmemcached/error.hpp>
#include <libmemcached/memory.h>
extern "C" {
#endif
-LIBMEMCACHED_LOCAL
memcached_return_t run_distribution(memcached_st *ptr);
#define memcached_server_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
+
+#ifdef __cplusplus
+bool memcached_purge(org::libmemcached::Instance*);
+org::libmemcached::Instance* memcached_instance_by_position(const memcached_st *ptr, uint32_t server_key);
+#endif
#define SOCK_CLOEXEC 0
#endif
-static memcached_return_t connect_poll(memcached_instance_st *server)
+static memcached_return_t connect_poll(org::libmemcached::Instance* 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_instance_st *server)
+static memcached_return_t set_hostinfo(org::libmemcached::Instance* server)
{
assert(server->type != MEMCACHED_CONNECTION_UNIX_SOCKET);
if (server->address_info)
}
char str_port[NI_MAXSERV];
- int length= snprintf(str_port, NI_MAXSERV, "%u", (uint32_t)server->port);
- if (length >= NI_MAXSERV or length < 0)
+ int length= snprintf(str_port, NI_MAXSERV, "%u", uint32_t(server->port()));
+ if (length >= NI_MAXSERV or length <= 0)
{
return MEMCACHED_FAILURE;
}
return MEMCACHED_SUCCESS;
}
-static inline void set_socket_nonblocking(memcached_instance_st *server)
+static inline void set_socket_nonblocking(org::libmemcached::Instance* server)
{
#ifdef WIN32
u_long arg= 1;
#endif
}
-static void set_socket_options(memcached_instance_st *server)
+static void set_socket_options(org::libmemcached::Instance* 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_instance_st *server)
+static memcached_return_t unix_socket_connect(org::libmemcached::Instance* server)
{
#ifndef WIN32
WATCHPOINT_ASSERT(server->fd == INVALID_SOCKET);
#endif
}
-static memcached_return_t network_connect(memcached_instance_st *server)
+static memcached_return_t network_connect(org::libmemcached::Instance* server)
{
bool timeout_error_occured= false;
Based on time/failure count fail the connect without trying. This prevents waiting in a state where
we get caught spending cycles just waiting.
*/
-static memcached_return_t backoff_handling(memcached_server_write_instance_st server, bool& in_timeout)
+static memcached_return_t backoff_handling(org::libmemcached::Instance* server, bool& in_timeout)
{
struct timeval curr_time;
bool _gettime_success= (gettimeofday(&curr_time, NULL) == 0);
return MEMCACHED_SUCCESS;
}
-static memcached_return_t _memcached_connect(memcached_server_write_instance_st server, const bool set_last_disconnected)
+static memcached_return_t _memcached_connect(org::libmemcached::Instance* server, const bool set_last_disconnected)
{
if (server->fd != INVALID_SOCKET)
{
if (memcached_success(rc))
{
- memcached_mark_server_as_clean(server);
+ server->mark_server_as_clean();
return rc;
}
else if (set_last_disconnected)
if (in_timeout)
{
char buffer[1024];
- int snprintf_length= snprintf(buffer, sizeof(buffer), "%s:%d", server->hostname, int(server->port));
+ int snprintf_length= snprintf(buffer, sizeof(buffer), "%s:%d", server->hostname, int(server->port()));
return memcached_set_error(*server, MEMCACHED_SERVER_TEMPORARILY_DISABLED, MEMCACHED_AT, buffer, snprintf_length);
}
}
return rc;
}
-memcached_return_t memcached_connect_try(memcached_server_write_instance_st server)
+memcached_return_t memcached_connect_try(org::libmemcached::Instance* server)
{
return _memcached_connect(server, false);
}
-memcached_return_t memcached_connect(memcached_server_write_instance_st server)
+memcached_return_t memcached_connect(org::libmemcached::Instance* server)
{
return _memcached_connect(server, true);
}
#pragma once
-memcached_return_t memcached_connect_try(memcached_server_write_instance_st ptr);
-memcached_return_t memcached_connect(memcached_server_write_instance_st ptr);
+memcached_return_t memcached_connect_try(org::libmemcached::Instance*);
+memcached_return_t memcached_connect(org::libmemcached::Instance*);
return memcached_delete_by_key(memc, key, key_length, key, key_length, expiration);
}
-static inline memcached_return_t ascii_delete(memcached_server_write_instance_st instance,
+static inline memcached_return_t ascii_delete(org::libmemcached::Instance* instance,
uint32_t ,
const char *key,
const size_t key_length,
return memcached_vdo(instance, vector, 6, is_buffering ? false : true);
}
-static inline memcached_return_t binary_delete(memcached_server_write_instance_st instance,
+static inline memcached_return_t binary_delete(org::libmemcached::Instance* instance,
uint32_t server_key,
const char *key,
const size_t key_length,
server_key= 0;
}
- memcached_server_write_instance_st replica= memcached_server_instance_fetch(instance->root, server_key);
+ org::libmemcached::Instance* replica= memcached_instance_fetch(instance->root, server_key);
if (memcached_fatal(memcached_vdo(replica, vector, 4, should_flush)))
{
}
uint32_t server_key= memcached_generate_hash_with_redistribution(memc, group_key, group_key_length);
- memcached_server_write_instance_st instance= memcached_server_instance_fetch(memc, server_key);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(memc, server_key);
bool is_buffering= memcached_is_buffering(instance->root);
bool is_replying= memcached_is_replying(instance->root);
#include <libmemcached/common.h>
-memcached_return_t memcached_vdo(memcached_server_write_instance_st instance,
+memcached_return_t memcached_vdo(org::libmemcached::Instance* instance,
libmemcached_io_vector_st vector[],
const size_t count,
const bool with_flush)
if (memcached_failed(rc= memcached_connect(instance)))
{
WATCHPOINT_ERROR(rc);
- assert_msg(instance->error_messages, "memcached_connect() returned an error but the memcached_server_write_instance_st showed none.");
+ assert_msg(instance->error_messages, "memcached_connect() returned an error but the Instance showed none.");
return rc;
}
#pragma once
-memcached_return_t memcached_vdo(memcached_server_write_instance_st ptr,
+memcached_return_t memcached_vdo(org::libmemcached::Instance* ptr,
libmemcached_io_vector_st vector[],
const size_t count,
const bool with_flush);
// Send message to all servers
for (uint32_t server_key= 0; server_key < memcached_server_count(memc); server_key++)
{
- memcached_server_write_instance_st instance= memcached_server_instance_fetch(memc, server_key);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(memc, server_key);
memcached_return_t vdo_rc;
if (memcached_success((vdo_rc= memcached_vdo(instance, vector, 3, true))))
}
// Collect the returned items
- memcached_server_write_instance_st instance;
+ org::libmemcached::Instance* instance;
while ((instance= memcached_io_get_readable_server(memc)))
{
memcached_return_t response_rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
char message[MAX_ERROR_LENGTH];
};
-static void _set(memcached_instance_st& server, memcached_st& memc)
+static void _set(org::libmemcached::Instance& 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_instance_st& self, memcached_return_t rc, const char *at, const char *str, size_t length)
+memcached_return_t memcached_set_error(org::libmemcached::Instance& 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_instance_st");
+ assert_msg(rc != MEMCACHED_SOME_ERRORS, "Programmer error, MEMCACHED_SOME_ERRORS was about to be set on a Instance");
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_instance_st& self, char* buffer, const size_t buffer_length)
+static inline size_t append_host_to_string(org::libmemcached::Instance& self, char* buffer, const size_t buffer_length)
{
size_t size= 0;
switch (self.type)
case MEMCACHED_CONNECTION_TCP:
case MEMCACHED_CONNECTION_UDP:
size+= snprintf(buffer, buffer_length, " host: %s:%d",
- self.hostname, int(self.port));
+ self.hostname, int(self.port()));
break;
case MEMCACHED_CONNECTION_UNIX_SOCKET:
return size;
}
-memcached_return_t memcached_set_error(memcached_instance_st& self, memcached_return_t rc, const char *at, memcached_string_t& str)
+memcached_return_t memcached_set_error(org::libmemcached::Instance& 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_instance_st");
+ assert_msg(rc != MEMCACHED_SOME_ERRORS, "Programmer error, MEMCACHED_SOME_ERRORS was about to be set on a org::libmemcached::Instance");
if (memcached_fatal(rc) == false)
{
return rc;
return rc;
}
-memcached_return_t memcached_set_error(memcached_instance_st& self, memcached_return_t rc, const char *at)
+memcached_return_t memcached_set_error(org::libmemcached::Instance& 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_instance_st");
+ assert_msg(rc != MEMCACHED_SOME_ERRORS, "Programmer error, MEMCACHED_SOME_ERRORS was about to be set on a org::libmemcached::Instance");
if (memcached_fatal(rc) == false)
{
return rc;
return memcached_set_errno(self, local_errno, at, tmp);
}
-memcached_return_t memcached_set_errno(memcached_instance_st& self, int local_errno, const char *at, const char *str, size_t length)
+memcached_return_t memcached_set_errno(org::libmemcached::Instance& 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_instance_st& self, int local_errno, const char *at, memcached_string_t& str)
+memcached_return_t memcached_set_errno(org::libmemcached::Instance& self, int local_errno, const char *at, memcached_string_t& str)
{
if (local_errno == 0)
{
return rc;
}
-memcached_return_t memcached_set_errno(memcached_instance_st& self, int local_errno, const char *at)
+memcached_return_t memcached_set_errno(org::libmemcached::Instance& self, int local_errno, const char *at)
{
if (local_errno == 0)
{
for (uint32_t x= 0; x < memcached_server_count(self); x++)
{
- memcached_server_instance_st instance= memcached_server_instance_by_position(self, x);
+ org::libmemcached::Instance* instance= memcached_instance_by_position(self, x);
_error_print(instance->error_messages);
}
self.error_messages= NULL;
}
-void memcached_error_free(memcached_instance_st& self)
+void memcached_error_free(org::libmemcached::Instance& self)
{
_error_free(self.error_messages);
self.error_messages= NULL;
return false;
}
-bool memcached_has_current_error(memcached_instance_st& server)
+bool memcached_has_current_error(org::libmemcached::Instance& server)
{
return memcached_has_current_error(*(server.root));
}
}
-memcached_error_t *memcached_error_copy(const memcached_instance_st& server)
+memcached_error_t *memcached_error_copy(const org::libmemcached::Instance& server)
{
if (server.error_messages == NULL)
{
return MEMCACHED_SUCCESS;
}
-memcached_return_t memcached_instance_error_return(memcached_instance_st* instance)
+memcached_return_t memcached_instance_error_return(org::libmemcached::Instance* instance)
{
if (instance == NULL)
{
#define TOSTRING(x) STRINGIFY(x)
#define MEMCACHED_AT __FILE__ ":" TOSTRING(__LINE__)
-LIBMEMCACHED_LOCAL
memcached_return_t memcached_set_parser_error(memcached_st& memc,
const char *at,
const char *format, ...);
-LIBMEMCACHED_LOCAL
- memcached_return_t memcached_set_error(memcached_st&, memcached_return_t rc, const char *at);
+memcached_return_t memcached_set_error(memcached_st&, memcached_return_t rc, const char *at);
-LIBMEMCACHED_LOCAL
- memcached_return_t memcached_set_error(memcached_instance_st&, memcached_return_t rc, const char *at);
+memcached_return_t memcached_set_error(org::libmemcached::Instance&, 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);
+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_instance_st&, memcached_return_t rc, const char *at, const char *str, size_t length);
+memcached_return_t memcached_set_error(org::libmemcached::Instance&, 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);
+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_instance_st&, memcached_return_t rc, const char *at, memcached_string_t& str);
+memcached_return_t memcached_set_error(org::libmemcached::Instance&, 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);
+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_instance_st&, int local_errno, const char *at, memcached_string_t& str);
+memcached_return_t memcached_set_errno(org::libmemcached::Instance&, 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);
+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_instance_st&, int local_errno, const char *at, const char *str, size_t length);
+memcached_return_t memcached_set_errno(org::libmemcached::Instance&, 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);
+memcached_return_t memcached_set_errno(memcached_st& memc, int local_errno, const char *at);
-LIBMEMCACHED_LOCAL
- memcached_return_t memcached_set_errno(memcached_instance_st&, int local_errno, const char *at);
+memcached_return_t memcached_set_errno(org::libmemcached::Instance&, int local_errno, const char *at);
-LIBMEMCACHED_LOCAL
bool memcached_has_current_error(memcached_st&);
-LIBMEMCACHED_LOCAL
-bool memcached_has_current_error(memcached_instance_st&);
+bool memcached_has_current_error(org::libmemcached::Instance&);
-LIBMEMCACHED_LOCAL
void memcached_error_free(memcached_st&);
-void memcached_error_free(memcached_server_st& self);
+void memcached_error_free(memcached_server_st&);
-LIBMEMCACHED_LOCAL
-void memcached_error_free(memcached_instance_st&);
+void memcached_error_free(org::libmemcached::Instance& self);
-LIBMEMCACHED_LOCAL
-memcached_error_t *memcached_error_copy(const memcached_instance_st&);
+memcached_error_t *memcached_error_copy(const org::libmemcached::Instance&);
-memcached_return_t memcached_instance_error_return(memcached_instance_st*);
+memcached_return_t memcached_instance_error_return(org::libmemcached::Instance*);
#endif
#include <libmemcached/common.h>
-static memcached_return_t ascii_exist(memcached_st *memc, memcached_server_write_instance_st instance, const char *key, size_t key_length)
+static memcached_return_t ascii_exist(memcached_st *memc, org::libmemcached::Instance* instance, const char *key, size_t key_length)
{
libmemcached_io_vector_st vector[]=
{
return rc;
}
-static memcached_return_t binary_exist(memcached_st *memc, memcached_server_write_instance_st instance, const char *key, size_t key_length)
+static memcached_return_t binary_exist(memcached_st *memc, org::libmemcached::Instance* instance, const char *key, size_t key_length)
{
protocol_binary_request_set request= {};
size_t send_length= sizeof(request.bytes);
}
uint32_t server_key= memcached_generate_hash_with_redistribution(memc, group_key, group_key_length);
- memcached_server_write_instance_st instance= memcached_server_instance_fetch(memc, server_key);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(memc, server_key);
if (memcached_is_binary(memc))
{
}
*error= MEMCACHED_MAXIMUM_RETURN; // We use this to see if we ever go into the loop
- memcached_instance_st *server;
+ org::libmemcached::Instance *server;
while ((server= memcached_io_get_readable_server(ptr)))
{
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
for (uint32_t x= 0; x < memcached_server_count(ptr); x++)
{
- memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, x);
initialize_binary_request(instance, request.message.header);
if (reply)
for (uint32_t x= 0; x < memcached_server_count(ptr); x++)
{
- memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, x);
if (memcached_instance_response_count(instance) > 0)
{
memcached_return_t rc= MEMCACHED_SUCCESS;
for (uint32_t x= 0; x < memcached_server_count(ptr); x++)
{
- memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, x);
libmemcached_io_vector_st vector[]=
{
for (uint32_t x= 0; x < memcached_server_count(memc); ++x)
{
- memcached_server_write_instance_st instance=
- memcached_server_instance_fetch(memc, x);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(memc, x);
if (instance->write_buffer_offset != 0)
{
*/
for (uint32_t x= 0; x < memcached_server_count(ptr); x++)
{
- memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, x);
if (memcached_instance_response_count(instance))
{
size_t hosts_connected= 0;
for (uint32_t x= 0; x < number_of_keys; x++)
{
- memcached_server_write_instance_st instance;
uint32_t server_key;
if (is_group_key_set)
server_key= memcached_generate_hash_with_redistribution(ptr, keys[x], key_length[x]);
}
- instance= memcached_server_instance_fetch(ptr, server_key);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, server_key);
libmemcached_io_vector_st vector[]=
{
bool success_happened= false;
for (uint32_t x= 0; x < memcached_server_count(ptr); x++)
{
- memcached_server_write_instance_st instance=
- memcached_server_instance_fetch(ptr, x);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, x);
if (memcached_instance_response_count(instance))
{
server_key= memcached_generate_hash_with_redistribution(ptr, keys[x], key_length[x]);
}
- memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, server_key);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, server_key);
if (memcached_instance_response_count(instance) == 0)
{
for (uint32_t x= 0; x < memcached_server_count(ptr); ++x)
{
- memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, x);
initialize_binary_request(instance, request.message.header);
if (memcached_instance_response_count(instance))
continue;
}
- memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, server);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, server);
if (memcached_instance_response_count(instance) == 0)
{
if (return_value == 0)
{
- return_value= (int) (a->port - b->port);
+ return_value= int(a->port() - b->port());
}
return return_value;
{
if (memcached_server_count(ptr))
{
- memcached_server_write_instance_st instance;
- qsort(memcached_instance_list(ptr), memcached_server_count(ptr), sizeof(memcached_instance_st), compare_servers);
- instance= memcached_server_instance_fetch(ptr, 0);
+ qsort(memcached_instance_list(ptr), memcached_server_count(ptr), sizeof(org::libmemcached::Instance), compare_servers);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, 0);
instance->number_of_hosts= memcached_server_count(ptr);
}
}
return memcached_set_errno(*ptr, errno, MEMCACHED_AT);
}
- memcached_instance_st *list= memcached_instance_list(ptr);
+ org::libmemcached::Instance* list= memcached_instance_list(ptr);
/* count live servers (those without a retry delay set) */
bool is_auto_ejecting= _is_auto_eject_host(ptr);
uint64_t is_ketama_weighted= memcached_behavior_get(ptr, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED);
uint32_t points_per_server= (uint32_t) (is_ketama_weighted ? MEMCACHED_POINTS_PER_SERVER_KETAMA : MEMCACHED_POINTS_PER_SERVER);
- if (not live_servers)
+ if (live_servers == 0)
{
return MEMCACHED_SUCCESS;
}
{
printf("ketama_weighted:%s|%d|%llu|%u\n",
list[host_index].hostname,
- list[host_index].port,
+ list[host_index].port(),
(unsigned long long)list[host_index].weight,
pointer_per_server);
}
sort_host_length= snprintf(sort_host, sizeof(sort_host),
"/%s:%u-%u",
list[host_index].hostname,
- (uint32_t)list[host_index].port,
+ (uint32_t)list[host_index].port(),
pointer_index);
if (size_t(sort_host_length) >= sizeof(sort_host) or sort_host_length < 0)
char sort_host[MEMCACHED_NI_MAXHOST +1 +MEMCACHED_NI_MAXSERV +1 +MEMCACHED_NI_MAXSERV]= "";
int sort_host_length;
- if (list[host_index].port == MEMCACHED_DEFAULT_PORT)
+ if (list[host_index].port() == MEMCACHED_DEFAULT_PORT)
{
sort_host_length= snprintf(sort_host, sizeof(sort_host),
"%s-%u",
sort_host_length= snprintf(sort_host, sizeof(sort_host),
"%s:%u-%u",
list[host_index].hostname,
- (uint32_t)list[host_index].port,
+ (uint32_t)list[host_index].port(),
pointer_index - 1);
}
{
assert_msg(ptr, "Programmer mistake, somehow server_add() was passed a NULL memcached_st");
- memcached_instance_st *new_host_list= libmemcached_xrealloc(ptr, memcached_instance_list(ptr), (ptr->number_of_hosts + 1), memcached_instance_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)
{
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));
+ org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, memcached_server_count(ptr));
if (__instance_create_with(ptr, instance, hostname, port, weight, type) == NULL)
{
ptr->number_of_hosts++;
// @note we place the count in the bottom of the server list
- instance= memcached_server_instance_fetch(ptr, 0);
+ instance= memcached_instance_fetch(ptr, 0);
memcached_instance_set_count(instance, memcached_server_count(ptr));
return run_distribution(ptr);
uint32_t count= memcached_server_list_count(list);
- memcached_instance_st *new_host_list= libmemcached_xrealloc(ptr, memcached_instance_list(ptr), (count + memcached_server_count(ptr)), memcached_instance_st);
+ org::libmemcached::Instance* new_host_list= libmemcached_xrealloc(ptr, memcached_instance_list(ptr), (count + memcached_server_count(ptr)), org::libmemcached::Instance);
if (new_host_list == NULL)
{
for (uint32_t x= 0; x < count; 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));
+ org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, memcached_server_count(ptr));
WATCHPOINT_ASSERT(instance);
memcached_string_t hostname= { memcached_string_make_from_cstr(list[x].hostname) };
// Provides backwards compatibility with server list.
{
- memcached_server_write_instance_st instance;
- instance= memcached_server_instance_fetch(ptr, 0);
+ org::libmemcached::Instance* instance= memcached_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)
+memcached_return_t memcached_instance_push(memcached_st *ptr, const struct org::libmemcached::Instance* 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);
+ org::libmemcached::Instance* new_host_list= libmemcached_xrealloc(ptr, memcached_instance_list(ptr), (number_of_hosts +memcached_server_count(ptr)), org::libmemcached::Instance);
if (new_host_list == NULL)
{
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));
+ org::libmemcached::Instance* instance= memcached_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)
+ list[x].port(), list[x].weight, list[x].type) == NULL)
{
return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT);
}
// Provides backwards compatibility with server list.
{
- memcached_server_write_instance_st instance;
- instance= memcached_server_instance_fetch(ptr, 0);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, 0);
instance->number_of_hosts= memcached_server_count(ptr);
}
*
*/
-/*
- 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,
+static inline void _server_init(org::libmemcached::Instance* self, memcached_st *root,
const memcached_string_t& hostname,
in_port_t port,
uint32_t weight, memcached_connection_t type)
self->options.is_dead= false;
self->number_of_hosts= 0;
self->cursor_active= 0;
- self->port= port;
+ self->port_= port;
self->fd= INVALID_SOCKET;
self->io_bytes_sent= 0;
self->request_id= 0;
self->hostname[hostname.size]= 0;
}
-static memcached_instance_st *_server_create(memcached_instance_st *self, const memcached_st *memc)
+static org::libmemcached::Instance* _server_create(org::libmemcached::Instance* self, const memcached_st *memc)
{
if (self == NULL)
{
- self= libmemcached_xmalloc(memc, struct memcached_instance_st);
+ self= libmemcached_xmalloc(memc, org::libmemcached::Instance);
if (self == NULL)
{
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)
+org::libmemcached::Instance* __instance_create_with(memcached_st *memc,
+ org::libmemcached::Instance* 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)
{
return self;
}
-void __instance_free(memcached_instance_st *self)
+void __instance_free(org::libmemcached::Instance* self)
{
memcached_quit_server(self, false);
}
}
-void memcached_instance_free(memcached_instance_st *self)
+void memcached_instance_free(org::libmemcached::Instance* 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)
+memcached_server_st *memcached_instance_2_server(org::libmemcached::Instance* source)
{
/* We just do a normal create if source is missing */
if (source == 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->port(), source->weight,
source->type);
}
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);
+ org::libmemcached::Instance* instance= memcached_instance_by_position(ptr, x);
for (uint32_t y= 0; y < number_of_callbacks; y++)
{
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);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, x);
memcached_return_t rc= (*callback)(ptr, instance, context);
if (rc == MEMCACHED_INVALID_ARGUMENTS)
memcached_return_t *error)
{
memcached_return_t unused;
- if (not error)
+ if (error == NULL)
{
error= &unused;
}
}
uint32_t server_key= memcached_generate_hash(ptr, key, key_length);
- return memcached_server_instance_by_position(ptr, server_key);
+ return memcached_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)
+static org::libmemcached::Instance* memcached_instance_clone(org::libmemcached::Instance* source)
{
/* We just do a normal create if source is missing */
if (source == NULL)
return __instance_create_with(source->root,
NULL,
hostname,
- source->port, source->weight,
+ source->port(), source->weight,
source->type);
}
-void set_last_disconnected_host(memcached_server_write_instance_st self)
+void set_last_disconnected_host(org::libmemcached::Instance* self)
{
assert(self->root);
if (self->root == NULL)
return;
}
- if (self->root->last_disconnected_server and self->root->last_disconnected_server->version == self->version)
+ if (memcached_server_get_last_disconnect(self->root) and
+ memcached_server_get_last_disconnect(self->root)->version == self->version)
{
return;
}
// const_cast
memcached_st *root= (memcached_st *)self->root;
- memcached_instance_free(root->last_disconnected_server);
+ memcached_instance_free((org::libmemcached::Instance*)(root->last_disconnected_server));
root->last_disconnected_server= memcached_instance_clone(self);
- root->last_disconnected_server->version= self->version;
+ ((org::libmemcached::Instance*)memcached_server_get_last_disconnect(root))->version= self->version;
}
memcached_server_instance_st memcached_server_get_last_disconnect(const memcached_st *self)
return 0;
}
- return self->last_disconnected_server;
+ return (memcached_server_instance_st)self->last_disconnected_server;
}
-uint32_t memcached_instance_set_count(memcached_instance_st *servers, uint32_t count)
+uint32_t memcached_instance_set_count(org::libmemcached::Instance* servers, uint32_t count)
{
WATCHPOINT_ASSERT(servers);
if (servers == NULL)
return 0;
}
- return self->port;
+ return self->port();
+}
+
+void memcached_instance_next_retry(memcached_server_instance_st self, const time_t absolute_time)
+{
+ WATCHPOINT_ASSERT(self);
+ if (self)
+ {
+ ((org::libmemcached::Instance*)self)->next_retry= absolute_time;
+ }
}
-uint32_t memcached_instance_response_count(const memcached_instance_st* self)
+uint32_t memcached_instance_response_count(const org::libmemcached::Instance* self)
{
WATCHPOINT_ASSERT(self);
if (self == NULL)
#define MEMCACHED_NI_MAXSERV 32
#endif
-struct memcached_instance_st {
+#ifdef __cplusplus
+
+namespace org {
+namespace libmemcached {
+
+struct Instance {
+ in_port_t port() const
+ {
+ return port_;
+ }
+
+ void port(in_port_t arg)
+ {
+ port_= arg;
+ }
+
+ inline void mark_server_as_clean()
+ {
+ server_failure_counter= 0;
+ next_retry= 0;
+ }
+
struct {
bool is_allocated:1;
bool is_initialized:1;
} options;
uint32_t number_of_hosts;
uint32_t cursor_active;
- in_port_t port;
+ in_port_t port_;
memcached_socket_t fd;
uint32_t io_bytes_sent; /* # bytes sent since last read */
uint32_t request_id;
char write_buffer[MEMCACHED_MAX_BUFFER];
char hostname[MEMCACHED_NI_MAXHOST];
};
+
+} // namespace libmemcached
+} // namespace org
+
+#endif
#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);
-const char *memcached_instance_name(const memcached_server_instance_st self);
+org::libmemcached::Instance* __instance_create_with(memcached_st *memc,
+ org::libmemcached::Instance* self,
+ const memcached_string_t& hostname,
+ const in_port_t port,
+ uint32_t weight,
+ const memcached_connection_t type);
-in_port_t memcached_instance_port(const memcached_server_instance_st self);
+const char *memcached_instance_name(const org::libmemcached::Instance* self);
-memcached_return_t memcached_instance_push(memcached_st *ptr, const struct memcached_instance_st*, uint32_t);
+in_port_t memcached_instance_port(const org::libmemcached::Instance* self);
-memcached_server_st *memcached_instance_2_server(struct memcached_instance_st*);
+memcached_return_t memcached_instance_push(memcached_st *ptr, const org::libmemcached::Instance*, uint32_t);
+
+memcached_server_st *memcached_instance_2_server(org::libmemcached::Instance* source);
uint32_t memcached_instance_count(const memcached_st* self);
-uint32_t memcached_instance_response_count(const memcached_instance_st* self);
+uint32_t memcached_instance_response_count(const org::libmemcached::Instance* self);
-uint32_t memcached_instance_set_count(memcached_instance_st *servers, uint32_t count);
+uint32_t memcached_instance_set_count(org::libmemcached::Instance *servers, uint32_t count);
-void __instance_free(struct memcached_instance_st *);
+void __instance_free(org::libmemcached::Instance *);
#include <libmemcached/common.h>
-void initialize_binary_request(memcached_server_write_instance_st server, protocol_binary_request_header& header)
+void initialize_binary_request(org::libmemcached::Instance* server, protocol_binary_request_header& header)
{
server->request_id++;
header.request.magic= PROTOCOL_BINARY_REQ;
*
* @param ptr the server to pack
*/
-static bool repack_input_buffer(memcached_server_write_instance_st ptr)
+static bool repack_input_buffer(org::libmemcached::Instance* ptr)
{
if (ptr->read_ptr != ptr->read_buffer)
{
* @param ptr the server to star processing iput messages for
* @return true if we processed anything, false otherwise
*/
-static bool process_input_buffer(memcached_server_write_instance_st ptr)
+static bool process_input_buffer(org::libmemcached::Instance* ptr)
{
/*
** We might be able to process some of the response messages if we
return false;
}
-static memcached_return_t io_wait(memcached_server_write_instance_st ptr,
+static memcached_return_t io_wait(org::libmemcached::Instance* ptr,
const memc_read_or_write read_or_write)
{
/*
memcached_literal_param("number of attempts to call io_wait() failed"));
}
-static bool io_flush(memcached_server_write_instance_st ptr,
+static bool io_flush(org::libmemcached::Instance* ptr,
const bool with_flush,
memcached_return_t& error)
{
return true;
}
-memcached_return_t memcached_io_wait_for_write(memcached_server_write_instance_st ptr)
+memcached_return_t memcached_io_wait_for_write(org::libmemcached::Instance* ptr)
{
return io_wait(ptr, MEM_WRITE);
}
-static memcached_return_t _io_fill(memcached_server_write_instance_st ptr)
+static memcached_return_t _io_fill(org::libmemcached::Instance* ptr)
{
ssize_t data_read;
do
return MEMCACHED_SUCCESS;
}
-memcached_return_t memcached_io_read(memcached_server_write_instance_st ptr,
+memcached_return_t memcached_io_read(org::libmemcached::Instance* ptr,
void *buffer, size_t length, ssize_t& nread)
{
assert(memcached_is_udp(ptr->root) == false);
- assert_msg(ptr, "Programmer error, memcached_io_read() recieved an invalid memcached_server_write_instance_st"); // Programmer error
+ assert_msg(ptr, "Programmer error, memcached_io_read() recieved an invalid Instance"); // Programmer error
char *buffer_ptr= static_cast<char *>(buffer);
if (ptr->fd == INVALID_SOCKET)
return MEMCACHED_SUCCESS;
}
-memcached_return_t memcached_io_slurp(memcached_server_write_instance_st ptr)
+memcached_return_t memcached_io_slurp(org::libmemcached::Instance* ptr)
{
- assert_msg(ptr, "Programmer error, invalid memcached_server_write_instance_st");
+ assert_msg(ptr, "Programmer error, invalid Instance");
assert(memcached_is_udp(ptr->root) == false);
if (ptr->fd == INVALID_SOCKET)
return MEMCACHED_CONNECTION_FAILURE;
}
-static bool _io_write(memcached_server_write_instance_st ptr,
+static bool _io_write(org::libmemcached::Instance* ptr,
const void *buffer, size_t length, bool with_flush,
size_t& written)
{
return true;
}
-bool memcached_io_write(memcached_server_write_instance_st ptr)
+bool memcached_io_write(org::libmemcached::Instance* ptr)
{
size_t written;
return _io_write(ptr, NULL, 0, true, written);
}
-ssize_t memcached_io_write(memcached_server_write_instance_st ptr,
+ssize_t memcached_io_write(org::libmemcached::Instance* ptr,
const void *buffer, const size_t length, const bool with_flush)
{
size_t written;
return ssize_t(written);
}
-bool memcached_io_writev(memcached_server_write_instance_st ptr,
- libmemcached_io_vector_st vector[],
- const size_t number_of, const bool with_flush)
+bool memcached_io_writev(org::libmemcached::Instance* ptr,
+ libmemcached_io_vector_st vector[],
+ const size_t number_of, const bool with_flush)
{
ssize_t complete_total= 0;
ssize_t total= 0;
}
-void memcached_io_close(memcached_server_write_instance_st ptr)
+void memcached_io_close(org::libmemcached::Instance* ptr)
{
if (ptr->fd == INVALID_SOCKET)
{
ptr->fd= INVALID_SOCKET;
}
-memcached_server_write_instance_st memcached_io_get_readable_server(memcached_st *memc)
+org::libmemcached::Instance* memcached_io_get_readable_server(memcached_st *memc)
{
#define MAX_SERVERS_TO_POLL 100
struct pollfd fds[MAX_SERVERS_TO_POLL];
for (uint32_t x= 0; x < memcached_server_count(memc) and host_index < MAX_SERVERS_TO_POLL; ++x)
{
- memcached_server_write_instance_st instance= memcached_server_instance_fetch(memc, x);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(memc, x);
if (instance->read_buffer_length > 0) /* I have data in the buffer */
{
/* 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);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(memc, x);
if (memcached_instance_response_count(instance) > 0)
{
{
for (uint32_t y= 0; y < memcached_server_count(memc); ++y)
{
- memcached_server_write_instance_st instance= memcached_server_instance_fetch(memc, y);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(memc, y);
if (instance->fd == fds[x].fd)
{
/*
Eventually we will just kill off the server with the problem.
*/
-void memcached_io_reset(memcached_server_write_instance_st ptr)
+void memcached_io_reset(org::libmemcached::Instance* ptr)
{
memcached_quit_server(ptr, true);
}
* Read a given number of bytes from the server and place it into a specific
* buffer. Reset the IO channel on this server if an error occurs.
*/
-memcached_return_t memcached_safe_read(memcached_server_write_instance_st ptr,
+memcached_return_t memcached_safe_read(org::libmemcached::Instance* ptr,
void *dta,
const size_t size)
{
return MEMCACHED_SUCCESS;
}
-memcached_return_t memcached_io_readline(memcached_server_write_instance_st ptr,
+memcached_return_t memcached_io_readline(org::libmemcached::Instance* ptr,
char *buffer_ptr,
size_t size,
size_t& total_nr)
#pragma once
-void initialize_binary_request(memcached_server_write_instance_st server, protocol_binary_request_header&);
+void initialize_binary_request(org::libmemcached::Instance* server, protocol_binary_request_header&);
-bool memcached_io_write(memcached_server_write_instance_st ptr);
+bool memcached_io_write(org::libmemcached::Instance* ptr);
-ssize_t memcached_io_write(memcached_server_write_instance_st ptr,
+ssize_t memcached_io_write(org::libmemcached::Instance* ptr,
const void *buffer, size_t length, bool with_flush);
-bool memcached_io_writev(memcached_server_write_instance_st ptr,
+bool memcached_io_writev(org::libmemcached::Instance* ptr,
libmemcached_io_vector_st vector[],
const size_t number_of, const bool with_flush);
-memcached_return_t memcached_io_wait_for_write(memcached_server_write_instance_st ptr);
+memcached_return_t memcached_io_wait_for_write(org::libmemcached::Instance* ptr);
-void memcached_io_reset(memcached_server_write_instance_st ptr);
+void memcached_io_reset(org::libmemcached::Instance* ptr);
-memcached_return_t memcached_io_read(memcached_server_write_instance_st ptr,
+memcached_return_t memcached_io_read(org::libmemcached::Instance* ptr,
void *buffer, size_t length, ssize_t& nread);
/* Read a line (terminated by '\n') into the buffer */
-memcached_return_t memcached_io_readline(memcached_server_write_instance_st ptr,
+memcached_return_t memcached_io_readline(org::libmemcached::Instance* ptr,
char *buffer_ptr,
size_t size,
size_t& total);
-void memcached_io_close(memcached_server_write_instance_st ptr);
+void memcached_io_close(org::libmemcached::Instance* ptr);
/* Read n bytes of data from the server and store them in dta */
-memcached_return_t memcached_safe_read(memcached_server_write_instance_st ptr,
+memcached_return_t memcached_safe_read(org::libmemcached::Instance* ptr,
void *dta,
const size_t size);
-memcached_server_write_instance_st memcached_io_get_readable_server(memcached_st *memc);
+org::libmemcached::Instance* memcached_io_get_readable_server(memcached_st *memc);
-memcached_return_t memcached_io_slurp(memcached_server_write_instance_st ptr);
+memcached_return_t memcached_io_slurp(org::libmemcached::Instance* ptr);
memcached_virtual_bucket_free(ptr);
- memcached_instance_free(ptr->last_disconnected_server);
+ memcached_instance_free((org::libmemcached::Instance*)ptr->last_disconnected_server);
if (ptr->on_cleanup)
{
memcached_instance_set(self, NULL);
self->number_of_hosts= 0;
- memcached_instance_free(self->last_disconnected_server);
+ memcached_instance_free((org::libmemcached::Instance*)self->last_disconnected_server);
self->last_disconnected_server= NULL;
}
}
{
if (self)
{
- memcached_instance_free(self->last_disconnected_server);
+ memcached_instance_free((org::libmemcached::Instance*)self->last_disconnected_server);
self->last_disconnected_server= NULL;
}
}
memcached_return_t memcached_push(memcached_st *destination, const memcached_st *source)
{
- return memcached_instance_push(destination, source->servers, source->number_of_hosts);
+ return memcached_instance_push(destination, (org::libmemcached::Instance*)source->servers, source->number_of_hosts);
}
-memcached_server_write_instance_st memcached_server_instance_fetch(memcached_st *ptr, uint32_t server_key)
+org::libmemcached::Instance* memcached_instance_fetch(memcached_st *ptr, uint32_t server_key)
{
if (ptr == NULL)
{
return &ptr->servers[server_key];
}
+org::libmemcached::Instance* memcached_instance_by_position(const memcached_st *ptr, uint32_t server_key)
+{
+ if (ptr == NULL)
+ {
+ return NULL;
+ }
+
+ return &ptr->servers[server_key];
+}
+
uint64_t memcached_query_id(const memcached_st *self)
{
if (self == NULL)
return self->query_id;
}
+
+org::libmemcached::Instance* memcached_instance_list(const memcached_st *self)
+{
+ if (self)
+ {
+ return (org::libmemcached::Instance*)self->servers;
+ }
+
+ return NULL;
+}
+
int32_t& _origin;
};
-bool memcached_purge(memcached_server_write_instance_st ptr)
+bool memcached_purge(org::libmemcached::Instance* ptr)
{
memcached_st *root= (memcached_st *)ptr->root;
will force data to be completed.
*/
-void memcached_quit_server(memcached_instance_st *ptr, bool io_death)
+void memcached_quit_server(org::libmemcached::Instance* ptr, bool io_death)
{
if (ptr->fd != INVALID_SOCKET)
{
{
for (uint32_t x= 0; x < memcached_server_count(ptr); x++)
{
- memcached_server_write_instance_st instance=
- memcached_server_instance_fetch(ptr, x);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, x);
memcached_quit_server(instance, false);
}
#pragma once
-void memcached_quit_server(memcached_instance_st *ptr, bool io_death);
+void memcached_quit_server(org::libmemcached::Instance* ptr, bool io_death);
void send_quit(memcached_st *ptr);
#include <libmemcached/common.h>
#include <libmemcached/string.hpp>
-static memcached_return_t textual_value_fetch(memcached_server_write_instance_st instance,
+static memcached_return_t textual_value_fetch(org::libmemcached::Instance* instance,
char *buffer,
memcached_result_st *result)
{
return MEMCACHED_PARTIAL_READ;
}
-static memcached_return_t textual_read_one_response(memcached_server_write_instance_st instance,
+static memcached_return_t textual_read_one_response(org::libmemcached::Instance* instance,
char *buffer, const size_t buffer_length,
memcached_result_st *result)
{
buffer, total_read);
}
-static memcached_return_t binary_read_one_response(memcached_server_write_instance_st instance,
+static memcached_return_t binary_read_one_response(org::libmemcached::Instance* instance,
char *buffer, const size_t buffer_length,
memcached_result_st *result)
{
return rc;
}
-static memcached_return_t _read_one_response(memcached_server_write_instance_st instance,
+static memcached_return_t _read_one_response(org::libmemcached::Instance* instance,
char *buffer, const size_t buffer_length,
memcached_result_st *result)
{
return rc;
}
-memcached_return_t memcached_read_one_response(memcached_server_write_instance_st instance,
+memcached_return_t memcached_read_one_response(org::libmemcached::Instance* instance,
memcached_result_st *result)
{
char buffer[SMALL_STRING_LEN];
return _read_one_response(instance, buffer, sizeof(buffer), result);
}
-memcached_return_t memcached_response(memcached_server_write_instance_st instance,
+memcached_return_t memcached_response(org::libmemcached::Instance* instance,
memcached_result_st *result)
{
char buffer[1024];
return memcached_response(instance, buffer, sizeof(buffer), result);
}
-memcached_return_t memcached_response(memcached_server_write_instance_st instance,
+memcached_return_t memcached_response(org::libmemcached::Instance* instance,
char *buffer, size_t buffer_length,
memcached_result_st *result)
{
#pragma once
/* Read a single response from the server */
-memcached_return_t memcached_read_one_response(memcached_server_write_instance_st ptr,
+memcached_return_t memcached_read_one_response(org::libmemcached::Instance* ptr,
memcached_result_st *result);
-memcached_return_t memcached_response(memcached_server_write_instance_st ptr,
+memcached_return_t memcached_response(org::libmemcached::Instance* ptr,
memcached_result_st *result);
-memcached_return_t memcached_response(memcached_server_write_instance_st ptr,
+memcached_return_t memcached_response(org::libmemcached::Instance* ptr,
char *buffer, size_t buffer_length,
memcached_result_st *result);
} // extern "C"
-memcached_return_t memcached_sasl_authenticate_connection(memcached_instance_st *server)
+memcached_return_t memcached_sasl_authenticate_connection(org::libmemcached::Instance* 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_instance_st *server);
+memcached_return_t memcached_sasl_authenticate_connection(org::libmemcached::Instance* server);
}
memcached_server_st *__server_create_with(memcached_st *memc,
- memcached_server_st* self,
+ memcached_server_st* allocated_instance,
const memcached_string_t& hostname,
const in_port_t port,
uint32_t weight,
return NULL;
}
- self= _server_create(self, memc);
+ allocated_instance= _server_create(allocated_instance, memc);
- if (self == NULL)
+ if (allocated_instance == NULL)
{
return NULL;
}
- _server_init(self, const_cast<memcached_st *>(memc), hostname, port, weight, type);
+ _server_init(allocated_instance, const_cast<memcached_st *>(memc), hostname, port, weight, type);
- return self;
+ return allocated_instance;
}
void __server_free(memcached_server_st *self)
return 0;
}
- return self->port;
+ return self->port();
}
uint32_t memcached_server_response_count(const memcached_server_instance_st self)
return arg.size > 0 or arg.size < NI_MAXHOST;
}
-static inline void memcached_mark_server_as_clean(memcached_server_write_instance_st server)
-{
- server->server_failure_counter= 0;
- server->next_retry= 0;
-}
-
-void memcached_instance_free(memcached_instance_st *);
+void memcached_instance_free(org::libmemcached::Instance *);
-void set_last_disconnected_host(memcached_server_write_instance_st self);
+void set_last_disconnected_host(org::libmemcached::Instance* self);
-static inline void memcached_mark_server_for_timeout(memcached_server_write_instance_st server)
+static inline void memcached_mark_server_for_timeout(org::libmemcached::Instance* server)
{
if (server->state != MEMCACHED_SERVER_STATE_IN_TIMEOUT)
{
#pragma once
#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct memcached_instance_st * memcached_server_write_instance_st;
-
-#ifdef __cplusplus
-}
+typedef struct org::libmemcached::Instance* memcached_server_write_instance_st;
+#else
+typedef void* memcached_server_write_instance_st;
#endif
: self->number_of_hosts;
}
-uint32_t memcached_instance_count(const memcached_instance_st* self)
+uint32_t memcached_instance_count(const memcached_st* self)
{
return (self == NULL)
? 0
: self->number_of_hosts;
}
-memcached_instance_st *memcached_instance_list(const memcached_st *self)
+void memcached_instance_set(memcached_st* memc, org::libmemcached::Instance* list)
{
- if (self)
- {
- return self->servers;
- }
-
- return NULL;
-}
-
-void memcached_instance_set(memcached_st *self, memcached_instance_st *list)
-{
- self->servers= list;
+ memc->servers= list;
}
void memcached_server_list_free(memcached_server_list_st self)
libmemcached_free(self->root, self);
}
-void memcached_instance_list_free(memcached_instance_st* self, uint32_t instance_count)
+void memcached_instance_list_free(org::libmemcached::Instance* self, uint32_t instance_count)
{
if (self == NULL)
{
#pragma once
-memcached_instance_st *memcached_instance_list(const memcached_st *);
+org::libmemcached::Instance* memcached_instance_list(const memcached_st *);
-uint32_t memcached_instance_count(const memcached_instance_st*);
+uint32_t memcached_instance_count(const memcached_st*);
uint32_t memcached_instance_list_count(const memcached_st*);
uint32_t memcached_servers_set_count(memcached_server_list_st servers, uint32_t count);
-void memcached_instance_list_free(memcached_instance_st* self, uint32_t count);
+void memcached_instance_list_free(org::libmemcached::Instance* self, uint32_t count);
-void memcached_instance_set(memcached_st *self, memcached_instance_st* list);
+void memcached_instance_set(memcached_st*, org::libmemcached::Instance*);
static memcached_return_t binary_stats_fetch(memcached_stat_st *memc_stat,
const char *args,
const size_t args_length,
- memcached_server_write_instance_st instance,
+ org::libmemcached::Instance* instance,
struct local_context *check)
{
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
static memcached_return_t ascii_stats_fetch(memcached_stat_st *memc_stat,
const char *args,
const size_t args_length,
- memcached_server_write_instance_st instance,
+ org::libmemcached::Instance* instance,
struct local_context *check)
{
libmemcached_io_vector_st vector[]=
stat_instance->pid= -1;
stat_instance->root= self;
- memcached_server_write_instance_st instance= memcached_server_instance_fetch(self, x);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(self, x);
memcached_return_t temp_return;
if (memcached_is_binary(self))
if (memcached_success(rc))
{
- memcached_server_write_instance_st instance= memcached_server_instance_fetch(memc_ptr, 0);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(memc_ptr, 0);
if (memc.flags.binary_protocol)
{
rc= binary_stats_fetch(memc_stat, args, args_length, instance, NULL);
}
static memcached_return_t call_stat_fn(memcached_st *ptr,
- memcached_server_write_instance_st instance,
+ org::libmemcached::Instance* instance,
void *context)
{
memcached_return_t rc;
}
static memcached_return_t memcached_send_binary(memcached_st *ptr,
- memcached_server_write_instance_st server,
+ org::libmemcached::Instance* server,
uint32_t server_key,
const char *key,
const size_t key_length,
server_key= 0;
}
- memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, server_key);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, server_key);
if (memcached_vdo(instance, vector, 5, false) != MEMCACHED_SUCCESS)
{
}
static memcached_return_t memcached_send_ascii(memcached_st *ptr,
- memcached_server_write_instance_st instance,
+ org::libmemcached::Instance* instance,
const char *key,
const size_t key_length,
const char *value,
}
uint32_t server_key= memcached_generate_hash_with_redistribution(ptr, group_key, group_key_length);
- memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, server_key);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, server_key);
WATCHPOINT_SET(instance->io_wait_count.read= 0);
WATCHPOINT_SET(instance->io_wait_count.write= 0);
#include <libmemcached/common.h>
#include <libmemcached/memcached/protocol_binary.h>
-static memcached_return_t ascii_touch(memcached_server_write_instance_st instance,
+static memcached_return_t ascii_touch(org::libmemcached::Instance* instance,
const char *key, size_t key_length,
time_t expiration)
{
return rc;
}
-static memcached_return_t binary_touch(memcached_server_write_instance_st instance,
+static memcached_return_t binary_touch(org::libmemcached::Instance* instance,
const char *key, size_t key_length,
time_t expiration)
{
}
uint32_t server_key= memcached_generate_hash_with_redistribution(ptr, group_key, group_key_length);
- memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, server_key);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, server_key);
if (ptr->flags.binary_protocol)
{
* extracts the message number from message_id, increments it and then
* writes the new value back into the header
*/
-void increment_udp_message_id(memcached_server_write_instance_st ptr)
+void increment_udp_message_id(org::libmemcached::Instance* ptr)
{
struct udp_datagram_header_st *header= (struct udp_datagram_header_st *)ptr->write_buffer;
uint16_t cur_req= get_udp_datagram_request_id(header);
header->request_id= htons((uint16_t) (thread_id | msg_num));
}
-bool memcached_io_init_udp_header(memcached_server_write_instance_st ptr, const uint16_t thread_id)
+bool memcached_io_init_udp_header(org::libmemcached::Instance* ptr, const uint16_t thread_id)
{
if (thread_id > UDP_REQUEST_ID_MAX_THREAD_ID)
{
uint16_t reserved;
};
-bool memcached_io_init_udp_header(memcached_server_write_instance_st ptr, const uint16_t thread_id);
-void increment_udp_message_id(memcached_server_write_instance_st ptr);
+bool memcached_io_init_udp_header(org::libmemcached::Instance*, const uint16_t thread_id);
+void increment_udp_message_id(org::libmemcached::Instance*);
if (rc == MEMCACHED_SUCCESS)
{
- memcached_server_write_instance_st instance= memcached_server_instance_fetch(memc_ptr, 0);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(memc_ptr, 0);
rc= memcached_vdo(instance, vector, 4, true);
bool errors_happened= false;
for (uint32_t x= 0; x < memcached_server_count(ptr); x++)
{
- memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, x);
// Optimization, we only fetch version once.
if (instance->major_version != UINT8_MAX)
if (success)
{
// Collect the returned items
- memcached_server_write_instance_st instance;
+ org::libmemcached::Instance* instance;
while ((instance= memcached_io_get_readable_server(ptr)))
{
memcached_return_t rrc= memcached_response(instance, NULL);
bool errors_happened= false;
for (uint32_t x= 0; x < memcached_server_count(ptr); x++)
{
- memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, x);
initialize_binary_request(instance, request.message.header);
if (success)
{
// Collect the returned items
- memcached_server_write_instance_st instance;
+ org::libmemcached::Instance* instance;
while ((instance= memcached_io_get_readable_server(ptr)))
{
char buffer[32];
{
memcached_st *memc= memcached_create(NULL);
- if (server->type == MEMCACHED_CONNECTION_UNIX_SOCKET)
+ if (strcmp(memcached_server_type(server), "SOCKET") == 0)
{
if (memcached_failed(memcached_server_add_unix_socket(memc, memcached_server_name(server))))
{
test_return_t auto_eject_hosts(memcached_st *trash)
{
(void) trash;
- memcached_server_instance_st instance;
memcached_return_t rc;
memcached_st *memc= memcached_create(NULL);
test_true(server_pool[7].port == 11211);
test_true(server_pool[7].weight == 100);
- instance= memcached_server_instance_by_position(memc, 2);
- ((memcached_server_write_instance_st)instance)->next_retry = time(NULL) + 15;
+ memcached_server_instance_st instance= memcached_server_instance_by_position(memc, 2);
+ memcached_instance_next_retry(instance, time(NULL) +15);
memc->ketama.next_distribution_rebuild= time(NULL) - 1;
/*
}
/* and re-added when it's back. */
- ((memcached_server_write_instance_st)instance)->next_retry = time(NULL) - 1;
- memc->ketama.next_distribution_rebuild= time(NULL) - 1;
+ time_t absolute_time= time(NULL) -1;
+ memcached_instance_next_retry(instance, absolute_time);
+ memc->ketama.next_distribution_rebuild= absolute_time;
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION,
memc->distribution);
for (ptrdiff_t x= 0; x < 99; x++)
/* Do Nothing */
uint32_t x= *((uint32_t *)(context));
- if (! (test_ports[x] == server->port))
+ if (! (test_ports[x] == memcached_server_port(server)))
{
- fprintf(stderr, "%lu -> %lu\n", (unsigned long)test_ports[x], (unsigned long)server->port);
+ fprintf(stderr, "%lu -> %lu\n", (unsigned long)test_ports[x], (unsigned long)memcached_server_port(server));
return MEMCACHED_FAILURE;
}
*/
memcached_server_instance_st instance_one= memcached_server_instance_by_position(memc, 0);
memcached_server_instance_st instance_two= memcached_server_instance_by_position(memc, 2);
- in_port_t port0= instance_one->port;
- in_port_t port2= instance_two->port;
+ in_port_t port0= instance_one->port();
+ in_port_t port2= instance_two->port();
- ((memcached_server_write_instance_st)instance_one)->port= 0;
- ((memcached_server_write_instance_st)instance_two)->port= 0;
+ ((memcached_server_write_instance_st)instance_one)->port(0);
+ ((memcached_server_write_instance_st)instance_two)->port(0);
test_compare(MEMCACHED_SUCCESS,
memcached_mget(memc,
test_compare(counter, keys.size());
/* restore the memc handle */
- ((memcached_server_write_instance_st)instance_one)->port= port0;
- ((memcached_server_write_instance_st)instance_two)->port= port2;
+ ((memcached_server_write_instance_st)instance_one)->port(port0);
+ ((memcached_server_write_instance_st)instance_two)->port(port2);
memcached_quit(memc);
}
memcached_quit(memc);
- ((memcached_server_write_instance_st)instance_one)->port= 0;
- ((memcached_server_write_instance_st)instance_two)->port= 0;
+ ((memcached_server_write_instance_st)instance_one)->port(0);
+ ((memcached_server_write_instance_st)instance_two)->port(0);
/* now retry the command, this time we should have cache misses */
test_compare(MEMCACHED_SUCCESS,
test_compare(counter, (unsigned int)(keys.size() >> 1));
/* restore the memc handle */
- ((memcached_server_write_instance_st)instance_one)->port= port0;
- ((memcached_server_write_instance_st)instance_two)->port= port2;
+ ((memcached_server_write_instance_st)instance_one)->port(port0);
+ ((memcached_server_write_instance_st)instance_two)->port(port2);
return TEST_SUCCESS;
}
for (uint32_t host= 0; host < memcached_server_count(memc); ++host)
{
memcached_st *memc_clone= memcached_clone(NULL, memc);
- memcached_server_instance_st instance=
- memcached_server_instance_by_position(memc_clone, host);
+ org::libmemcached::Instance* instance= (org::libmemcached::Instance*)memcached_server_instance_by_position(memc_clone, host);
- ((memcached_server_write_instance_st)instance)->port= 0;
+ instance->port(0);
for (int x= 'a'; x <= 'z'; ++x)
{
for (uint32_t host= 0; host < memcached_server_count(memc_clone); host++)
{
memcached_st *new_clone= memcached_clone(NULL, memc);
- memcached_server_instance_st instance=
- memcached_server_instance_by_position(new_clone, host);
- ((memcached_server_write_instance_st)instance)->port= 0;
+ memcached_server_instance_st instance= memcached_server_instance_by_position(new_clone, host);
+ ((memcached_server_write_instance_st)instance)->port(0);
for (int x= 'a'; x <= 'z'; ++x)
{
// We need to now cause a failure in one server, never do this in your own
// code.
close(memc_clone->servers[1].fd);
- memc_clone->servers[1].port= 1;
+ memc_clone->servers[1].port(1);
memc_clone->servers[1].address_info_next= NULL;
for (int x= int(MEMCACHED_SUCCESS); x < int(MEMCACHED_MAXIMUM_RETURN); ++x)