X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fio.c;h=3b5d44f570e2003313963a6c70a1600287f382ba;hb=d46b596b82e290141fd97e3c5381efdb792756a4;hp=bc74af7d985962f920be22543a758a6b457c664c;hpb=3fca91c00a13fa7d6650bfe65aabf074fa5579b5;p=awesomized%2Flibmemcached diff --git a/libmemcached/io.c b/libmemcached/io.c index bc74af7d..3b5d44f5 100644 --- a/libmemcached/io.c +++ b/libmemcached/io.c @@ -12,6 +12,8 @@ #include "common.h" +#include + typedef enum { MEM_READ, MEM_WRITE @@ -55,14 +57,10 @@ static memcached_return_t io_wait(memcached_server_write_instance_st ptr, return MEMCACHED_FAILURE; } - int timeout= ptr->root->poll_timeout; - if (ptr->root->flags.no_block == false) - timeout= -1; - size_t loop_max= 5; while (--loop_max) // While loop is for ERESTART or EINTR { - error= poll(&fds, 1, timeout); + error= poll(&fds, 1, ptr->root->poll_timeout); switch (error) { @@ -385,7 +383,10 @@ static ssize_t _io_write(memcached_server_write_instance_st ptr, buffer_end= MAX_UDP_DATAGRAM_LENGTH; should_write= length; if (ptr->write_buffer_offset + should_write > buffer_end) + { + fprintf(stderr, "%s:%d (%s)\n", __FILE__, __LINE__,__func__);fflush(stdout); return -1; + } } else { @@ -408,7 +409,9 @@ static ssize_t _io_write(memcached_server_write_instance_st ptr, WATCHPOINT_ASSERT(ptr->fd != INVALID_SOCKET); sent_length= io_flush(ptr, &rc); if (sent_length == -1) + { return -1; + } /* If io_flush calls memcached_purge, sent_length may be 0 */ unlikely (sent_length != 0) @@ -424,6 +427,7 @@ static ssize_t _io_write(memcached_server_write_instance_st ptr, WATCHPOINT_ASSERT(ptr->fd != INVALID_SOCKET); if (io_flush(ptr, &rc) == -1) { + fprintf(stderr, "%s:%d (%s)\n", __FILE__, __LINE__,__func__);fflush(stdout); return -1; } @@ -574,7 +578,10 @@ static ssize_t io_flush(memcached_server_write_instance_st ptr, rc= memcached_purge(ptr); if (rc != MEMCACHED_SUCCESS && rc != MEMCACHED_STORED) + { + fprintf(stderr, "%s:%d (%s)\n", __FILE__, __LINE__,__func__);fflush(stdout); return -1; + } } ssize_t sent_length; size_t return_length; @@ -587,7 +594,10 @@ static ssize_t io_flush(memcached_server_write_instance_st ptr, // UDP Sanity check, make sure that we are not sending somthing too big if (ptr->type == MEMCACHED_CONNECTION_UDP && write_length > MAX_UDP_DATAGRAM_LENGTH) + { + fprintf(stderr, "%s:%d (%s)\n", __FILE__, __LINE__,__func__);fflush(stdout); return -1; + } if (ptr->write_buffer_offset == 0 || (ptr->type == MEMCACHED_CONNECTION_UDP && ptr->write_buffer_offset == UDP_DATAGRAM_HEADER_LENGTH)) @@ -609,6 +619,7 @@ static ssize_t io_flush(memcached_server_write_instance_st ptr, if (ptr->type == MEMCACHED_CONNECTION_UDP) increment_udp_message_id(ptr); + assert(ptr->fd != -1); sent_length= send(ptr->fd, local_write_ptr, write_length, 0); if (sent_length == SOCKET_ERROR) { @@ -643,11 +654,17 @@ static ssize_t io_flush(memcached_server_write_instance_st ptr, continue; memcached_quit_server(ptr, true); + fprintf(stderr, "%s:%d (%s)\n", __FILE__, __LINE__,__func__);fflush(stdout); return -1; } + case ENOTCONN: + case EPIPE: default: + fprintf(stderr, "%s %u %u %u\n", ptr->hostname, ptr->port, ptr->io_bytes_sent, ptr->server_failure_counter); + fprintf(stderr, "%s:%d (%s)(%s)\n", __FILE__, __LINE__,__func__, strerror(errno));fflush(stdout); memcached_quit_server(ptr, true); *error= MEMCACHED_ERRNO; + assert(ptr->fd == -1); return -1; } } @@ -656,6 +673,7 @@ static ssize_t io_flush(memcached_server_write_instance_st ptr, (size_t)sent_length != write_length) { memcached_quit_server(ptr, true); + fprintf(stderr, "%s:%d (%s)\n", __FILE__, __LINE__,__func__);fflush(stdout); return -1; }