From a3e5c4d3c52ce4e3150c2bd520d71ca4b4b3eae8 Mon Sep 17 00:00:00 2001 From: Peter Lieven Date: Thu, 2 Apr 2015 08:34:52 +0200 Subject: [PATCH] socket: allow iscsi_which_events to return 0 this is meant as a hint that there can be no event at the moment and in this special case iscsi_service will return immediately. We use this at the moment in the case of a wait for a reconnect in which case we would enter a busy loop waiting for that reconnect. The 0 means do not poll for the client application. Do not poll, just wait a little (a few hundred ms) and call iscsi_which_events again. The wait should be timer driven or at least non busy looping, of course. Signed-off-by: Peter Lieven --- lib/socket.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/socket.c b/lib/socket.c index 7abd9cd..0646532 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -402,6 +402,11 @@ iscsi_which_events(struct iscsi_context *iscsi) { int events = iscsi->is_connected ? POLLIN : POLLOUT; + if (iscsi->pending_reconnect && iscsi->is_reconnecting && + time(NULL) < iscsi->next_reconnect) { + return 0; + } + if (iscsi->outqueue_current != NULL || (iscsi->outqueue != NULL && !iscsi->is_corked && (iscsi_serial32_compare(iscsi->outqueue->cmdsn, iscsi->maxcmdsn) <= 0 || @@ -788,7 +793,7 @@ iscsi_service(struct iscsi_context *iscsi, int revents) } if (iscsi->pending_reconnect) { - if (time(NULL) > iscsi->next_reconnect) { + if (time(NULL) >= iscsi->next_reconnect) { return iscsi_reconnect(iscsi); } else { if (iscsi->is_reconnecting) {