Skip to content

Commit

Permalink
Add add a timeout to the event_loop in sync.c
Browse files Browse the repository at this point in the history
This timeout can be used to cancel async connect attempts to
a remote target.

Signed-off-by: Ronnie Sahlberg <[email protected]>
  • Loading branch information
sahlberg committed Sep 19, 2023
1 parent a2f9ee5 commit 75a46d2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 75a46d2

Please sign in to comment.