static memcached_return_t set_hostinfo(org::libmemcached::Instance* server)
{
assert(server->type != MEMCACHED_CONNECTION_UNIX_SOCKET);
- if (server->address_info)
- {
- freeaddrinfo(server->address_info);
- server->address_info= NULL;
- server->address_info_next= NULL;
- }
+ server->clear_addrinfo();
char str_port[MEMCACHED_NI_MAXSERV];
int length= snprintf(str_port, MEMCACHED_NI_MAXSERV, "%u", uint32_t(server->port()));
struct addrinfo hints;
memset(&hints, 0, sizeof(struct addrinfo));
-#if 0
hints.ai_family= AF_INET;
-#endif
if (memcached_is_udp(server->root))
{
hints.ai_protocol= IPPROTO_UDP;
assert(server->address_info == NULL);
assert(server->address_info_next == NULL);
int errcode;
- switch(errcode= getaddrinfo(server->hostname, str_port, &hints, &server->address_info))
+ assert(server->hostname());
+ switch(errcode= getaddrinfo(server->hostname(), str_port, &hints, &server->address_info))
{
case 0:
+ server->address_info_next= server->address_info;
+ server->state= MEMCACHED_SERVER_STATE_ADDRINFO;
break;
case EAI_AGAIN:
return memcached_set_error(*server, MEMCACHED_TIMEOUT, MEMCACHED_AT, memcached_string_make_from_cstr(gai_strerror(errcode)));
case EAI_SYSTEM:
- if (server->address_info)
- {
- freeaddrinfo(server->address_info);
- server->address_info= NULL;
- server->address_info_next= NULL;
- }
+ server->clear_addrinfo();
return memcached_set_errno(*server, errno, MEMCACHED_AT, memcached_literal_param("getaddrinfo(EAI_SYSTEM)"));
case EAI_BADFLAGS:
- if (server->address_info)
- {
- freeaddrinfo(server->address_info);
- server->address_info= NULL;
- server->address_info_next= NULL;
- }
+ server->clear_addrinfo();
return memcached_set_error(*server, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("getaddrinfo(EAI_BADFLAGS)"));
case EAI_MEMORY:
- if (server->address_info)
- {
- freeaddrinfo(server->address_info);
- server->address_info= NULL;
- server->address_info_next= NULL;
- }
+ server->clear_addrinfo();
return memcached_set_error(*server, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT, memcached_literal_param("getaddrinfo(EAI_MEMORY)"));
default:
{
- if (server->address_info)
- {
- freeaddrinfo(server->address_info);
- server->address_info= NULL;
- server->address_info_next= NULL;
- }
+ server->clear_addrinfo();
return memcached_set_error(*server, MEMCACHED_HOST_LOOKUP_FAILURE, MEMCACHED_AT, memcached_string_make_from_cstr(gai_strerror(errcode)));
}
}
- server->address_info_next= server->address_info;
- server->state= MEMCACHED_SERVER_STATE_ADDRINFO;
return MEMCACHED_SUCCESS;
}
memset(&servAddr, 0, sizeof (struct sockaddr_un));
servAddr.sun_family= AF_UNIX;
- strncpy(servAddr.sun_path, server->hostname, sizeof(servAddr.sun_path)); /* Copy filename */
+ strncpy(servAddr.sun_path, server->hostname(), sizeof(servAddr.sun_path)); /* Copy filename */
if (connect(server->fd, (struct sockaddr *)&servAddr, sizeof(servAddr)) == -1)
{
}
}
- if (server->address_info_next == NULL)
- {
- server->address_info_next= server->address_info;
- server->state= MEMCACHED_SERVER_STATE_ADDRINFO;
- }
+ assert(server->address_info_next);
+ assert(server->address_info);
/* Create the socket */
while (server->address_info_next and server->fd == INVALID_SOCKET)
return memcached_set_error(*server, MEMCACHED_INVALID_HOST_PROTOCOL, MEMCACHED_AT, memcached_literal_param("SASL is not supported for UDP connections"));
}
- if (server->hostname[0] == '/')
+ if (server->hostname()[0] == '/')
{
server->type= MEMCACHED_CONNECTION_UNIX_SOCKET;
}
if (server->fd != INVALID_SOCKET and server->root->sasl.callbacks)
{
rc= memcached_sasl_authenticate_connection(server);
- fprintf(stderr, "%s:%d %s\n", __FILE__, __LINE__, memcached_strerror(NULL, rc));
if (memcached_failed(rc) and server->fd != INVALID_SOCKET)
{
WATCHPOINT_ASSERT(server->fd != INVALID_SOCKET);
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);
}
}
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:
size+= snprintf(buffer, buffer_length, " socket: %s",
- self.hostname);
+ self.hostname());
break;
}
memcached_server_instance_st a= (memcached_server_instance_st)p1;
memcached_server_instance_st b= (memcached_server_instance_st)p2;
- int return_value= strcmp(a->hostname, b->hostname);
+ int return_value= strcmp(a->_hostname, b->_hostname);
if (return_value == 0)
{
if (DEBUG)
{
printf("ketama_weighted:%s|%d|%llu|%u\n",
- list[host_index].hostname,
+ list[host_index]._hostname,
list[host_index].port(),
(unsigned long long)list[host_index].weight,
pointer_per_server);
// If hostname is not available then: /ip:port-index
sort_host_length= snprintf(sort_host, sizeof(sort_host),
"/%s:%u-%u",
- list[host_index].hostname,
+ list[host_index]._hostname,
(uint32_t)list[host_index].port(),
pointer_index);
{
sort_host_length= snprintf(sort_host, sizeof(sort_host),
"%s-%u",
- list[host_index].hostname,
+ list[host_index]._hostname,
pointer_index - 1);
}
else
{
sort_host_length= snprintf(sort_host, sizeof(sort_host),
"%s:%u-%u",
- list[host_index].hostname,
+ list[host_index]._hostname,
(uint32_t)list[host_index].port(),
pointer_index - 1);
}
// instance allocated.
for (uint32_t x= 0; x < number_of_hosts; ++x, ++original_host_size)
{
- WATCHPOINT_ASSERT(list[x].hostname[0] != 0);
+ WATCHPOINT_ASSERT(list[x]._hostname[0] != 0);
// We have extended the array, and now we will find it, and use it.
org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, original_host_size);
WATCHPOINT_ASSERT(instance);
- memcached_string_t hostname= { memcached_string_make_from_cstr(list[x].hostname) };
+ 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)
self->version= UINT_MAX;
}
self->limit_maxbytes= 0;
- memcpy(self->hostname, hostname.c_str, hostname.size);
- self->hostname[hostname.size]= 0;
+ self->hostname(hostname);
}
static org::libmemcached::Instance* _server_create(org::libmemcached::Instance* self, const memcached_st *memc)
{
memcached_quit_server(self, false);
- if (self->address_info)
- {
- freeaddrinfo(self->address_info);
- self->address_info= NULL;
- self->address_info_next= NULL;
- }
+ self->clear_addrinfo();
assert(self->address_info_next == NULL);
memcached_error_free(*self);
return NULL;
}
- memcached_string_t hostname= { memcached_string_make_from_cstr(source->hostname) };
+ memcached_string_t hostname_= { memcached_string_make_from_cstr(source->hostname()) };
return __instance_create_with(source->root,
NULL,
- hostname,
+ hostname_,
source->port(), source->weight,
source->type);
}
*
* Libmemcached library
*
- * Copyright (C) 2012 Data Differential, http://datadifferential.com/
+ * Copyright (C) 2012-2013 Data Differential, http://datadifferential.com/
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
# define MEMCACHED_NI_MAXSERV 32
#endif
+#include "libmemcached/string.hpp"
+
namespace org {
namespace libmemcached {
return _revents;
}
+ const char* hostname()
+ {
+ return _hostname;
+ }
+
+ void hostname(const memcached_string_t& hostname_)
+ {
+ if (hostname_.size)
+ {
+ memcpy(_hostname, hostname_.c_str, hostname_.size);
+ _hostname[hostname_.size]= 0;
+ }
+ else
+ {
+ memcpy(_hostname, memcached_literal_param("localhost"));
+ _hostname[memcached_literal_param_size("localhost")]= 0;
+ }
+ }
+
void events(short);
void revents(short);
struct memcached_error_t *error_messages;
char read_buffer[MEMCACHED_MAX_BUFFER];
char write_buffer[MEMCACHED_MAX_BUFFER];
- char hostname[MEMCACHED_NI_MAXHOST];
+ char _hostname[MEMCACHED_NI_MAXHOST];
+
+ void clear_addrinfo()
+ {
+ if (address_info)
+ {
+ freeaddrinfo(address_info);
+ address_info= NULL;
+ address_info_next= NULL;
+ }
+ }
};
} // namespace libmemcached
org::libmemcached::Instance* __instance_create_with(memcached_st *memc,
org::libmemcached::Instance* self,
- const memcached_string_t& hostname,
+ const memcached_string_t& _hostname,
const in_port_t port,
uint32_t weight,
const memcached_connection_t type);
sasl_conn_t *conn;
int ret;
- if ((ret= sasl_client_new("memcached", server->hostname, laddr, raddr, server->root->sasl.callbacks, 0, &conn) ) != SASL_OK)
+ if ((ret= sasl_client_new("memcached", server->_hostname, laddr, raddr, server->root->sasl.callbacks, 0, &conn) ) != SASL_OK)
{
const char *sasl_error_msg= sasl_errstring(ret, NULL, NULL);
WATCHPOINT_ASSERT(self);
if (self)
{
- return self->hostname;
+ return self->_hostname;
}
return NULL;
Application::error_t Application::join()
{
pid_t waited_pid= waitpid(_pid, &_status, 0);
+ slurp();
if (waited_pid == _pid and WIFEXITED(_status) == false)
{
+
/*
What we are looking for here is how the exit status happened.
- 127 means that posix_spawn() itself had an error.
std::string error_string("posix_spawn() failed pid:");
error_string+= _pid;
error_string+= " name:";
- error_string+= built_argv[0];
+ error_string+= print_argv(built_argv);
+ if (stderr_result_length())
+ {
+ error_string+= " stderr: ";
+ error_string+= stderr_c_str();
+ }
throw std::logic_error(error_string);
}
else if (WIFSIGNALED(_status))
if (WTERMSIG(_status) != SIGTERM and WTERMSIG(_status) != SIGHUP)
{
_app_exit_state= Application::INVALID_POSIX_SPAWN;
- std::string error_string(built_argv[0]);
+ std::string error_string(print_argv(built_argv));
error_string+= " was killed by signal ";
error_string+= strsignal(WTERMSIG(_status));
+ if (stdout_result_length())
+ {
+ error_string+= " stdout: ";
+ error_string+= stdout_c_str();
+ }
+ if (stderr_result_length())
+ {
+ error_string+= " stderr: ";
+ error_string+= stderr_c_str();
+ }
+
throw std::runtime_error(error_string);
}
return _stdout_buffer.size();
}
+ const char* stdout_c_str() const
+ {
+ return &_stdout_buffer[0];
+ }
+
libtest::vchar_t stderr_result() const
{
return _stderr_buffer;
*
* DataDifferential Utility Library
*
- * Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ * Copyright (C) 2011-2013 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