From c91de1e35a7715eb08151106c48c28d5a4f904c8 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Thu, 10 May 2012 20:02:04 +1000 Subject: [PATCH] We might be called by some eventsystems with POLLIN eventhough there is no data to read from the socket and there is no error. For this case, if FIONREAD tells us that there are 0 bytes to read, check if there is a socket error and return ok/error based on that. Some eventsystems may cause this to burn some cpu if the socket is ok but there are no bytes available to read by invoking POLLIN over and over, but it is better than failing the application. --- lib/socket.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/socket.c b/lib/socket.c index c88cdfb..6bcfd3e 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -235,6 +235,14 @@ iscsi_read_from_socket(struct iscsi_context *iscsi) return -1; } if (socket_count == 0) { + int ret, err = 0; + socklen_t err_size = sizeof(err); + + ret = getsockopt(iscsi->fd, SOL_SOCKET, SO_ERROR, &err, &err_size); + /* someone just called us without the socket being readable */ + if (ret == 0 && err == 0) { + return 0; + } iscsi_set_error(iscsi, "Socket failure. Socket is readable but no bytes available in FIONREAD"); return -1; }