From 75a46d2b2e6f3121852e508554dee8aac491bd99 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Wed, 6 Sep 2023 08:54:51 +1000 Subject: [PATCH] Add add a timeout to the event_loop in sync.c This timeout can be used to cancel async connect attempts to a remote target. Signed-off-by: Ronnie Sahlberg --- lib/sync.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/sync.c b/lib/sync.c index 62ce32bb..abbae9eb 100644 --- a/lib/sync.c +++ b/lib/sync.c @@ -54,11 +54,27 @@ static void event_loop(struct iscsi_context *iscsi, struct iscsi_sync_state *state) { struct pollfd pfd; + int scsi_timeout; int ret; + time_t t; + if (iscsi->scsi_timeout) { + scsi_timeout = time(NULL) + iscsi->scsi_timeout; + } else { + scsi_timeout = 0; + } + while (state->finished == 0) { short revents; + if (scsi_timeout) { + t = time(NULL); + if (t > scsi_timeout) { + iscsi_set_error(iscsi, "Connect timedout"); + state->status = -1; + return; + } + } pfd.fd = iscsi_get_fd(iscsi); pfd.events = iscsi_which_events(iscsi);