X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fio.c;h=2515dc1ea7c72b5f5e2a42404d3aa11f23233c4f;hb=d9752c25d2f723d27e355d0c7090b65b0445c4a4;hp=6513492d5007734ec46599bfa287f5193263cd29;hpb=c63b3f26c9e8d0214d3e1c70fb761f7700d61d2d;p=m6w6%2Flibmemcached diff --git a/libmemcached/io.c b/libmemcached/io.c index 6513492d..2515dc1e 100644 --- a/libmemcached/io.c +++ b/libmemcached/io.c @@ -55,14 +55,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) { @@ -109,6 +105,11 @@ static memcached_return_t io_wait(memcached_server_write_instance_st ptr, return MEMCACHED_FAILURE; } +memcached_return_t memcached_io_wait_for_write(memcached_server_write_instance_st ptr) +{ + return io_wait(ptr, MEM_WRITE); +} + /** * Try to fill the input buffer for a server with as much * data as possible. @@ -313,7 +314,7 @@ memcached_return_t memcached_io_read(memcached_server_write_instance_st ptr, and protocol enforcement happens at memcached_response() looking for '\n'. We do not care for UDB which requests 8 bytes at once. Generally, this means that connection went away. Since - for blocking I/O we do not return 0 and for non-blocking case + for blocking I/O we do not return EXIT_SUCCESS and for non-blocking case it will return EGAIN if data is not immediatly available. */ WATCHPOINT_STRING("We had a zero length recv()"); @@ -385,7 +386,9 @@ 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) + { return -1; + } } else { @@ -408,7 +411,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) @@ -574,7 +579,9 @@ static ssize_t io_flush(memcached_server_write_instance_st ptr, rc= memcached_purge(ptr); if (rc != MEMCACHED_SUCCESS && rc != MEMCACHED_STORED) + { return -1; + } } ssize_t sent_length; size_t return_length; @@ -587,11 +594,13 @@ 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) + { return -1; + } if (ptr->write_buffer_offset == 0 || (ptr->type == MEMCACHED_CONNECTION_UDP && ptr->write_buffer_offset == UDP_DATAGRAM_HEADER_LENGTH)) - return 0; + return EXIT_SUCCESS; /* Looking for memory overflows */ #if defined(DEBUG) @@ -609,12 +618,15 @@ static ssize_t io_flush(memcached_server_write_instance_st ptr, if (ptr->type == MEMCACHED_CONNECTION_UDP) increment_udp_message_id(ptr); - sent_length= send(ptr->fd, local_write_ptr, write_length, 0); + WATCHPOINT_ASSERT(ptr->fd != -1); + sent_length= send(ptr->fd, local_write_ptr, write_length, MSG_NOSIGNAL|MSG_DONTWAIT); if (sent_length == SOCKET_ERROR) { ptr->cached_errno= get_socket_errno(); +#if 0 // @todo I should look at why we hit this bit of code hard frequently WATCHPOINT_ERRNO(get_socket_errno()); WATCHPOINT_NUMBER(get_socket_errno()); +#endif switch (get_socket_errno()) { case ENOBUFS: @@ -643,9 +655,12 @@ static ssize_t io_flush(memcached_server_write_instance_st ptr, memcached_quit_server(ptr, true); return -1; } + case ENOTCONN: + case EPIPE: default: memcached_quit_server(ptr, true); *error= MEMCACHED_ERRNO; + WATCHPOINT_ASSERT(ptr->fd == -1); return -1; } }