int e;
char str_port[NI_MAXSERV];
- sprintf(str_port, "%u", server->port);
+ snprintf(str_port, NI_MAXSERV, "%u", (uint32_t)server->port);
memset(&hints, 0, sizeof(hints));
error= setsockopt(ptr->fd, SOL_SOCKET, SO_SNDTIMEO,
&waittime, (socklen_t)sizeof(struct timeval));
WATCHPOINT_ASSERT(error == 0);
+ if (error)
+ return MEMCACHED_FAILURE;
}
#endif
error= setsockopt(ptr->fd, SOL_SOCKET, SO_RCVTIMEO,
&waittime, (socklen_t)sizeof(struct timeval));
WATCHPOINT_ASSERT(error == 0);
+ if (error)
+ return MEMCACHED_FAILURE;
}
#endif
error= setsockopt(ptr->fd, SOL_SOCKET, SO_LINGER,
&linger, (socklen_t)sizeof(struct linger));
WATCHPOINT_ASSERT(error == 0);
+ if (error)
+ return MEMCACHED_FAILURE;
}
if (ptr->root->flags.tcp_nodelay)
error= setsockopt(ptr->fd, IPPROTO_TCP, TCP_NODELAY,
&flag, (socklen_t)sizeof(int));
WATCHPOINT_ASSERT(error == 0);
+ if (error)
+ return MEMCACHED_FAILURE;
}
- if (ptr->root->send_size)
+ if (ptr->root->send_size > 0)
{
int error;
error= setsockopt(ptr->fd, SOL_SOCKET, SO_SNDBUF,
&ptr->root->send_size, (socklen_t)sizeof(int));
WATCHPOINT_ASSERT(error == 0);
+ if (error)
+ return MEMCACHED_FAILURE;
}
- if (ptr->root->recv_size)
+ if (ptr->root->recv_size > 0)
{
int error;
error= setsockopt(ptr->fd, SOL_SOCKET, SO_RCVBUF,
&ptr->root->recv_size, (socklen_t)sizeof(int));
WATCHPOINT_ASSERT(error == 0);
+ if (error)
+ return MEMCACHED_FAILURE;
}
/* libmemcached will always use nonblocking IO to avoid write deadlocks */
while (flags == -1 && (errno == EINTR || errno == EAGAIN));
unlikely (flags == -1)
+ {
return MEMCACHED_CONNECTION_FAILURE;
+ }
else if ((flags & O_NONBLOCK) == 0)
{
int rval;
while (rval == -1 && (errno == EINTR || errno == EAGAIN));
unlikely (rval == -1)
+ {
return MEMCACHED_CONNECTION_FAILURE;
+ }
}
return MEMCACHED_SUCCESS;
static memcached_return_t unix_socket_connect(memcached_server_st *ptr)
{
struct sockaddr_un servAddr;
- socklen_t addrlen;
if (ptr->fd == -1)
{
servAddr.sun_family= AF_UNIX;
strcpy(servAddr.sun_path, ptr->hostname); /* Copy filename */
- addrlen= (socklen_t) (strlen(servAddr.sun_path) + sizeof(servAddr.sun_family));
-
test_connect:
if (connect(ptr->fd,
(struct sockaddr *)&servAddr,
{
struct addrinfo *use;
- if (!ptr->sockaddr_inited ||
+ WATCHPOINT_ASSERT(ptr->cursor_active == 0);
+
+ if (! ptr->options.sockaddr_inited ||
(!(ptr->root->flags.use_cache_lookups)))
{
memcached_return_t rc;
rc= set_hostinfo(ptr);
if (rc != MEMCACHED_SUCCESS)
return rc;
- ptr->sockaddr_inited= true;
+ ptr->options.sockaddr_inited= true;
}
use= ptr->address_info;
if (ptr->fd != -1)
{
- WATCHPOINT_ASSERT(ptr->cursor_active == 0);
ptr->server_failure_counter= 0;
return MEMCACHED_SUCCESS;
}
if (curr_time.tv_sec < ptr->next_retry)
{
if (memcached_behavior_get(ptr->root, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS))
+ {
run_distribution(ptr->root);
+ }
ptr->root->last_disconnected_server = ptr;
return MEMCACHED_SERVER_MARKED_DEAD;
case MEMCACHED_CONNECTION_UNIX_SOCKET:
rc= unix_socket_connect(ptr);
break;
+ case MEMCACHED_CONNECTION_MAX:
default:
WATCHPOINT_ASSERT(0);
}