From: Brian Aker Date: Thu, 17 Dec 2009 08:03:27 +0000 (-0800) Subject: ICC fixes X-Git-Tag: 0.37~67 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=7f9bc55d79a4e7133fdeaaa1150451717c103b28;p=awesomized%2Flibmemcached ICC fixes --- diff --git a/libmemcached/connect.c b/libmemcached/connect.c index 98ef44d5..96f26fb8 100644 --- a/libmemcached/connect.c +++ b/libmemcached/connect.c @@ -10,7 +10,7 @@ static memcached_return_t set_hostinfo(memcached_server_st *server) 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)); @@ -63,6 +63,8 @@ static memcached_return_t set_socket_options(memcached_server_st *ptr) error= setsockopt(ptr->fd, SOL_SOCKET, SO_SNDTIMEO, &waittime, (socklen_t)sizeof(struct timeval)); WATCHPOINT_ASSERT(error == 0); + if (error) + return MEMCACHED_FAILURE; } #endif @@ -78,6 +80,8 @@ static memcached_return_t set_socket_options(memcached_server_st *ptr) error= setsockopt(ptr->fd, SOL_SOCKET, SO_RCVTIMEO, &waittime, (socklen_t)sizeof(struct timeval)); WATCHPOINT_ASSERT(error == 0); + if (error) + return MEMCACHED_FAILURE; } #endif @@ -91,6 +95,8 @@ static memcached_return_t set_socket_options(memcached_server_st *ptr) 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) @@ -101,6 +107,8 @@ static memcached_return_t set_socket_options(memcached_server_st *ptr) 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) @@ -110,6 +118,8 @@ static memcached_return_t set_socket_options(memcached_server_st *ptr) 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) @@ -119,6 +129,8 @@ static memcached_return_t set_socket_options(memcached_server_st *ptr) 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 */ @@ -129,7 +141,9 @@ static memcached_return_t set_socket_options(memcached_server_st *ptr) while (flags == -1 && (errno == EINTR || errno == EAGAIN)); unlikely (flags == -1) + { return MEMCACHED_CONNECTION_FAILURE; + } else if ((flags & O_NONBLOCK) == 0) { int rval; @@ -139,7 +153,9 @@ static memcached_return_t set_socket_options(memcached_server_st *ptr) while (rval == -1 && (errno == EINTR || errno == EAGAIN)); unlikely (rval == -1) + { return MEMCACHED_CONNECTION_FAILURE; + } } return MEMCACHED_SUCCESS; @@ -148,7 +164,6 @@ static memcached_return_t set_socket_options(memcached_server_st *ptr) static memcached_return_t unix_socket_connect(memcached_server_st *ptr) { struct sockaddr_un servAddr; - socklen_t addrlen; if (ptr->fd == -1) { @@ -162,8 +177,6 @@ static memcached_return_t unix_socket_connect(memcached_server_st *ptr) 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, diff --git a/libmemcached/get.c b/libmemcached/get.c index 30682427..9a570585 100644 --- a/libmemcached/get.c +++ b/libmemcached/get.c @@ -82,9 +82,10 @@ char *memcached_get_by_key(memcached_st *ptr, 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); @@ -92,9 +93,10 @@ char *memcached_get_by_key(memcached_st *ptr, 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) diff --git a/libmemcached/hosts.c b/libmemcached/hosts.c index a5649a6d..09924f10 100644 --- a/libmemcached/hosts.c +++ b/libmemcached/hosts.c @@ -215,9 +215,9 @@ memcached_return_t update_continuum(memcached_st *ptr) // 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); diff --git a/libmemcached/io.c b/libmemcached/io.c index 8f96bc32..9f98b8b4 100644 --- a/libmemcached/io.c +++ b/libmemcached/io.c @@ -333,7 +333,9 @@ ssize_t memcached_io_write(memcached_server_st *ptr, memcached_return_t memcached_io_close(memcached_server_st *ptr) { +#ifdef DEBUG int r; +#endif if (ptr->fd == -1) return MEMCACHED_SUCCESS; @@ -341,7 +343,10 @@ memcached_return_t memcached_io_close(memcached_server_st *ptr) /* 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) @@ -353,7 +358,10 @@ memcached_return_t memcached_io_close(memcached_server_st *ptr) #endif } - r= close(ptr->fd); +#ifdef DEBUG + r= +#endif + close(ptr->fd); #ifdef DEBUG if (r != 0) WATCHPOINT_ERRNO(errno); diff --git a/libmemcached/io.h b/libmemcached/io.h index 2929aace..7aab7bae 100644 --- a/libmemcached/io.h +++ b/libmemcached/io.h @@ -42,22 +42,29 @@ struct udp_datagram_header_st 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); diff --git a/libmemcached/storage.c b/libmemcached/storage.c index 5aa1d771..d3e44e9c 100644 --- a/libmemcached/storage.c +++ b/libmemcached/storage.c @@ -67,7 +67,6 @@ static inline memcached_return_t memcached_send(memcached_st *ptr, { 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; @@ -114,7 +113,7 @@ static inline memcached_return_t memcached_send(memcached_st *ptr, 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), @@ -152,7 +151,7 @@ static inline memcached_return_t memcached_send(memcached_st *ptr, 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; @@ -167,7 +166,7 @@ static inline memcached_return_t memcached_send(memcached_st *ptr, 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;