Skip to content

Commit

Permalink
Allow fast close
Browse files Browse the repository at this point in the history
  • Loading branch information
scaprile committed Nov 2, 2023
1 parent 129bf93 commit 18d13f9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mongoose.c
Original file line number Diff line number Diff line change
Expand Up @@ -6823,6 +6823,7 @@ static void mg_iotest(struct mg_mgr *mgr, int ms) {
if (can_read(c))
FreeRTOS_FD_SET(c->fd, mgr->ss, eSELECT_READ | eSELECT_EXCEPT);
if (can_write(c)) FreeRTOS_FD_SET(c->fd, mgr->ss, eSELECT_WRITE);
if (c->is_closing) ms = 1;
}
FreeRTOS_select(mgr->ss, pdMS_TO_TICKS(ms));
for (c = mgr->conns; c != NULL; c = c->next) {
Expand All @@ -6839,6 +6840,7 @@ static void mg_iotest(struct mg_mgr *mgr, int ms) {
c->is_readable = c->is_writable = 0;
if (mg_tls_pending(c) > 0) ms = 1, c->is_readable = 1;
if (can_write(c)) MG_EPOLL_MOD(c, 1);
if (c->is_closing) ms = 1;
max++;
}
struct epoll_event *evs = (struct epoll_event *) alloca(max * sizeof(evs[0]));
Expand Down Expand Up @@ -6871,6 +6873,7 @@ static void mg_iotest(struct mg_mgr *mgr, int ms) {
fds[n].fd = FD(c);
if (can_read(c)) fds[n].events |= POLLIN;
if (can_write(c)) fds[n].events |= POLLOUT;
if (c->is_closing) ms = 1;
n++;
}
}
Expand Down Expand Up @@ -6918,6 +6921,7 @@ static void mg_iotest(struct mg_mgr *mgr, int ms) {
if (can_write(c)) FD_SET(FD(c), &wset);
if (mg_tls_pending(c) > 0) tvp = &tv_zero;
if (FD(c) > maxfd) maxfd = FD(c);
if (c->is_closing) ms = 1;
}

if ((rc = select((int) maxfd + 1, &rset, &wset, &eset, tvp)) < 0) {
Expand Down
4 changes: 4 additions & 0 deletions src/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ static void mg_iotest(struct mg_mgr *mgr, int ms) {
if (can_read(c))
FreeRTOS_FD_SET(c->fd, mgr->ss, eSELECT_READ | eSELECT_EXCEPT);
if (can_write(c)) FreeRTOS_FD_SET(c->fd, mgr->ss, eSELECT_WRITE);
if (c->is_closing) ms = 1;
}
FreeRTOS_select(mgr->ss, pdMS_TO_TICKS(ms));
for (c = mgr->conns; c != NULL; c = c->next) {
Expand All @@ -458,6 +459,7 @@ static void mg_iotest(struct mg_mgr *mgr, int ms) {
c->is_readable = c->is_writable = 0;
if (mg_tls_pending(c) > 0) ms = 1, c->is_readable = 1;
if (can_write(c)) MG_EPOLL_MOD(c, 1);
if (c->is_closing) ms = 1;
max++;
}
struct epoll_event *evs = (struct epoll_event *) alloca(max * sizeof(evs[0]));
Expand Down Expand Up @@ -490,6 +492,7 @@ static void mg_iotest(struct mg_mgr *mgr, int ms) {
fds[n].fd = FD(c);
if (can_read(c)) fds[n].events |= POLLIN;
if (can_write(c)) fds[n].events |= POLLOUT;
if (c->is_closing) ms = 1;
n++;
}
}
Expand Down Expand Up @@ -537,6 +540,7 @@ static void mg_iotest(struct mg_mgr *mgr, int ms) {
if (can_write(c)) FD_SET(FD(c), &wset);
if (mg_tls_pending(c) > 0) tvp = &tv_zero;
if (FD(c) > maxfd) maxfd = FD(c);
if (c->is_closing) ms = 1;
}

if ((rc = select((int) maxfd + 1, &rset, &wset, &eset, tvp)) < 0) {
Expand Down

0 comments on commit 18d13f9

Please sign in to comment.