X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fio.c;h=30a2a1a4921396a967b71bd92bda79ec57ce3bb6;hb=09ef521d2c88955d04d6c91f7b5a1671a1955130;hp=1c8783b29ec71899ecf39733a882a5b6cf37bf57;hpb=ea260e7bce23c9a41c3c60fd68f55b33608714a9;p=m6w6%2Flibmemcached diff --git a/libmemcached/io.c b/libmemcached/io.c index 1c8783b2..30a2a1a4 100644 --- a/libmemcached/io.c +++ b/libmemcached/io.c @@ -62,45 +62,50 @@ static memcached_return_t io_wait(memcached_server_write_instance_st ptr, timeout= -1; size_t loop_max= 5; - while (--loop_max) + while (--loop_max) // While loop is for ERESTART or EINTR { error= poll(&fds, 1, timeout); switch (error) { - case 1: + case 1: // Success! WATCHPOINT_IF_LABELED_NUMBER(read_or_write && loop_max < 4, "read() times we had to loop, decremented down from 5", loop_max); WATCHPOINT_IF_LABELED_NUMBER(!read_or_write && loop_max < 4, "write() times we had to loop, decremented down from 5", loop_max); return MEMCACHED_SUCCESS; - case 0: + case 0: // Timeout occured, we let the while() loop do its thing. return MEMCACHED_TIMEOUT; default: WATCHPOINT_ERRNO(errno); + switch (errno) { - switch (errno) - { #ifdef TARGET_OS_LINUX - case ERESTART: + case ERESTART: #endif - case EINTR: - continue; - default: - ptr->cached_errno= error; - memcached_quit_server(ptr, true); - - return MEMCACHED_FAILURE; + case EINTR: + break; + default: + if (fds.revents & POLLERR) + { + int err; + socklen_t len= sizeof (err); + (void)getsockopt(ptr->fd, SOL_SOCKET, SO_ERROR, &err, &len); + ptr->cached_errno= (err == 0) ? errno : err; } + else + { + ptr->cached_errno= errno; + } + memcached_quit_server(ptr, true); + + return MEMCACHED_FAILURE; } } } - if (loop_max == 0 && error == 0) - return MEMCACHED_TIMEOUT; - /* Imposssible for anything other then -1 */ WATCHPOINT_ASSERT(error == -1); - ptr->cached_errno= error; + ptr->cached_errno= errno; memcached_quit_server(ptr, true); return MEMCACHED_FAILURE; @@ -278,7 +283,7 @@ memcached_return_t memcached_io_read(memcached_server_write_instance_st ptr, else if (data_read == -1) { ptr->cached_errno= errno; - memcached_return_t rc= MEMCACHED_UNKNOWN_READ_FAILURE; + memcached_return_t rc= MEMCACHED_ERRNO; switch (errno) { case EAGAIN: @@ -309,6 +314,7 @@ memcached_return_t memcached_io_read(memcached_server_write_instance_st ptr, for blocking I/O we do not return 0 and for non-blocking case it will return EGAIN if data is not immediatly available. */ + WATCHPOINT_STRING("We had a zero length read()"); memcached_quit_server(ptr, true); *nread= -1; return MEMCACHED_UNKNOWN_READ_FAILURE;