Skip to content
Snippets Groups Projects
Commit 5d2f36a0 authored by Marek Vavruša's avatar Marek Vavruša
Browse files

tcp: make sure master sockets are not closed, cooperative throttling

parent 78680c6f
Branches
Tags
No related merge requests found
...@@ -352,37 +352,34 @@ static int tcp_wait_for_events(tcp_context_t *tcp) ...@@ -352,37 +352,34 @@ static int tcp_wait_for_events(tcp_context_t *tcp)
/* Process events. */ /* Process events. */
unsigned i = 0; unsigned i = 0;
while (nfds > 0 && i < set->n) { while (nfds > 0 && i < set->n) {
bool should_close = false;
/* Terminate faulty connections. */
int fd = set->pfd[i].fd; int fd = set->pfd[i].fd;
if (set->pfd[i].revents & (POLLERR|POLLHUP|POLLNVAL)) {
/* Active sockets. */ should_close = (i >= tcp->client_threshold);
if (set->pfd[i].revents & POLLIN) { --nfds;
--nfds; /* One less active event. */ } else if (set->pfd[i].revents & (POLLIN)) {
/* Master sockets */
/* Indexes <0, client_threshold) are master sockets. */
if (i < tcp->client_threshold) { if (i < tcp->client_threshold) {
/* Faulty master sockets shall be sorted later. */ if (!is_throttled && tcp_event_accept(tcp, i) == KNOT_EBUSY) {
(void) tcp_event_accept(tcp, i); time_now(&tcp->throttle_end);
tcp->throttle_end.tv_sec += tcp_throttle();
}
/* Client sockets */
} else { } else {
if (tcp_event_serve(tcp, i) != KNOT_EOK) { if (tcp_event_serve(tcp, i) != KNOT_EOK) {
fdset_remove(set, i); should_close = true;
close(fd);
continue; /* Stay on the same index. */
} }
} }
--nfds;
} }
if (set->pfd[i].revents & (POLLERR|POLLHUP|POLLNVAL)) { /* Evaluate */
--nfds; /* One less active event. */ if (should_close) {
fdset_remove(set, i); fdset_remove(set, i);
close(fd); close(fd);
continue; /* Stay on the same index. */ } else {
++i;
} }
/* Next socket. */
++i;
} }
return nfds; return nfds;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment