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)
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)
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,
memcached_behavior_set(ptr, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 1);
rc= memcached_set(ptr, key, key_length,
- memcached_result_value(&ptr->result),
- memcached_result_length(&ptr->result),
- 0, memcached_result_flags(&ptr->result));
+ (memcached_result_value(&ptr->result)),
+ (memcached_result_length(&ptr->result)),
+ 0,
+ (memcached_result_flags(&ptr->result)));
if (rc == MEMCACHED_BUFFERED && latch == 0)
memcached_behavior_set(ptr, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 0);
else
{
rc= memcached_set(ptr, key, key_length,
- memcached_result_value(&ptr->result),
- memcached_result_length(&ptr->result),
- 0, memcached_result_flags(&ptr->result));
+ (memcached_result_value(&ptr->result)),
+ (memcached_result_length(&ptr->result)),
+ 0,
+ (memcached_result_flags(&ptr->result)));
}
if (rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED)
// Spymemcached ketema key format is: hostname/ip:port-index
// If hostname is not available then: /ip:port-index
sort_host_length= (size_t) snprintf(sort_host, MEMCACHED_MAX_HOST_SORT_LENGTH,
- "/%s:%d-%d",
+ "/%s:%u-%u",
list[host_index].hostname,
- list[host_index].port,
+ (uint32_t)list[host_index].port,
pointer_index);
#ifdef DEBUG
printf("update_continuum: key is %s\n", sort_host);
memcached_return_t memcached_io_close(memcached_server_st *ptr)
{
+#ifdef DEBUG
int r;
+#endif
if (ptr->fd == -1)
return MEMCACHED_SUCCESS;
/* in case of death shutdown to avoid blocking at close() */
if (1)
{
- r= shutdown(ptr->fd, SHUT_RDWR);
+#ifdef DEBUG
+ r=
+#endif
+ shutdown(ptr->fd, SHUT_RDWR);
#ifdef DEBUG
if (r && errno != ENOTCONN)
#endif
}
- r= close(ptr->fd);
+#ifdef DEBUG
+ r=
+#endif
+ close(ptr->fd);
#ifdef DEBUG
if (r != 0)
WATCHPOINT_ERRNO(errno);
ssize_t memcached_io_write(memcached_server_st *ptr,
const void *buffer, size_t length, char with_flush);
+
void memcached_io_reset(memcached_server_st *ptr);
+
memcached_return_t memcached_io_read(memcached_server_st *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_st *ptr,
char *buffer_ptr,
size_t size);
+
memcached_return_t memcached_io_close(memcached_server_st *ptr);
+
/* Read n bytes of data from the server and store them in dta */
memcached_return_t memcached_safe_read(memcached_server_st *ptr,
void *dta,
size_t size);
+
/* Read a single response from the server */
memcached_return_t memcached_read_one_response(memcached_server_st *ptr,
char *buffer, size_t buffer_length,
memcached_result_st *result);
+
memcached_return_t memcached_io_init_udp_header(memcached_server_st *ptr,
uint16_t thread_id);
{
char to_write;
size_t write_length;
- ssize_t sent_length;
memcached_return_t rc;
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
unsigned int server_key;
memcpy(buffer_ptr, command, strlen(command));
/* Copy in the key prefix, switch to the buffer_ptr */
- buffer_ptr= memcpy(buffer_ptr + strlen(command) , ptr->prefix_key, strlen(ptr->prefix_key));
+ buffer_ptr= memcpy((buffer_ptr + strlen(command)), ptr->prefix_key, strlen(ptr->prefix_key));
/* Copy in the key, adjust point if a key prefix was used. */
buffer_ptr= memcpy(buffer_ptr + (ptr->prefix_key ? strlen(ptr->prefix_key) : 0),
goto error;
/* Send command body */
- if ((sent_length= memcached_io_write(&ptr->hosts[server_key], value, value_length, 0)) == -1)
+ if (memcached_io_write(&ptr->hosts[server_key], value, value_length, 0) == -1)
{
rc= MEMCACHED_WRITE_FAILURE;
goto error;
to_write= 1;
}
- if ((sent_length= memcached_io_write(&ptr->hosts[server_key], "\r\n", 2, to_write)) == -1)
+ if (memcached_io_write(&ptr->hosts[server_key], "\r\n", 2, to_write) == -1)
{
rc= MEMCACHED_WRITE_FAILURE;
goto error;