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.
This commit is contained in:
Ronnie Sahlberg
2012-05-10 20:02:04 +10:00
parent 935fd9da8c
commit c91de1e35a

View File

@@ -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;
}