mirror of
https://github.com/M66B/NetGuard.git
synced 2025-03-09 21:55:09 +00:00
Yield while reading TUN / UDP socket
This commit is contained in:
parent
7dc998150a
commit
8b6d0146ef
2 changed files with 14 additions and 3 deletions
|
@ -41,6 +41,8 @@
|
|||
#define EPOLL_EVENTS 20
|
||||
#define EPOLL_MIN_CHECK 100 // milliseconds
|
||||
|
||||
#define TUN_YIELD 10 // packets
|
||||
|
||||
#define ICMP4_MAXMSG (IP_MAXPACKET - 20 - 8) // bytes (socket)
|
||||
#define ICMP6_MAXMSG (IPV6_MAXPACKET - 40 - 8) // bytes (socket)
|
||||
#define UDP4_MAXMSG (IP_MAXPACKET - 20 - 8) // bytes (socket)
|
||||
|
@ -51,6 +53,7 @@
|
|||
#define UDP_TIMEOUT_53 15 // seconds
|
||||
#define UDP_TIMEOUT_ANY 300 // seconds
|
||||
#define UDP_KEEP_TIMEOUT 60 // seconds
|
||||
#define UDP_YIELD 10 // packets
|
||||
|
||||
#define TCP_INIT_TIMEOUT 20 // seconds ~net.inet.tcp.keepinit
|
||||
#define TCP_IDLE_TIMEOUT 3600 // seconds ~net.inet.tcp.keepidle
|
||||
|
|
|
@ -222,9 +222,13 @@ void *handle_events(void *a) {
|
|||
(ev[i].events & EPOLLERR) != 0,
|
||||
(ev[i].events & EPOLLHUP) != 0);
|
||||
|
||||
while (!error && is_readable(args->tun))
|
||||
int count = 0;
|
||||
while (count < TUN_YIELD && !error && !args->ctx->stopping &&
|
||||
is_readable(args->tun)) {
|
||||
count++;
|
||||
if (check_tun(args, &ev[i], epoll_fd, sessions, maxsessions) < 0)
|
||||
error = 1;
|
||||
}
|
||||
|
||||
} else {
|
||||
// Check downstream
|
||||
|
@ -243,9 +247,13 @@ void *handle_events(void *a) {
|
|||
session->protocol == IPPROTO_ICMPV6)
|
||||
check_icmp_socket(args, &ev[i]);
|
||||
else if (session->protocol == IPPROTO_UDP) {
|
||||
while (!(ev[i].events & EPOLLERR) && (ev[i].events & EPOLLIN) &&
|
||||
is_readable(session->socket))
|
||||
int count = 0;
|
||||
while (count < UDP_YIELD && !args->ctx->stopping &&
|
||||
!(ev[i].events & EPOLLERR) && (ev[i].events & EPOLLIN) &&
|
||||
is_readable(session->socket)) {
|
||||
count++;
|
||||
check_udp_socket(args, &ev[i]);
|
||||
}
|
||||
} else if (session->protocol == IPPROTO_TCP)
|
||||
check_tcp_socket(args, &ev[i], epoll_fd);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue