Skip to content

Commit

Permalink
refactor set_select_fds goto
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed Aug 18, 2023
1 parent 1c2b558 commit a647879
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,33 +287,35 @@ static void fd_handler(struct re_fhs *fhs, int flags)
#ifdef HAVE_SELECT
static int set_select_fds(struct re *re, struct re_fhs *fhs)
{
int i;
int i = -1;

if (!re || !fhs)
return EINVAL;

if (fhs->index != -1) {
i = fhs->index;
goto update;
}

/* if nothing is found a linear search for the first
* zeroed handler */
for (i = 0; i < re->maxfds; i++) {
if (!re->fhsl[i])
goto update;
else {
/* if nothing is found a linear search for the first
* zeroed handler */
for (int j = 0; j < re->maxfds; j++) {
if (!re->fhsl[j]) {
i = j;
break;
}
}
}

return ERANGE;
if (i == -1)
return ERANGE;

update:
if (fhs->flags) {
re->fhsl[i] = fhs;
fhs->index = i;
fhs->index = i;
}
else {
re->fhsl[i] = NULL;
fhs->index = -1;
fhs->index = -1;
}

return 0;
Expand Down

0 comments on commit a647879

Please sign in to comment.