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 <ronniesahlberg@gmail.com>
This commit is contained in:
Ronnie Sahlberg
2023-09-06 08:54:51 +10:00
parent a2f9ee5d78
commit 75a46d2b2e

View File

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