mirror of https://github.com/M66B/NetGuard.git
Read sockets while readable
This commit is contained in:
parent
00cc6fea1c
commit
6b62e9ecb1
|
@ -501,3 +501,4 @@ const char *strstate(const int state);
|
|||
char *hex(const u_int8_t *data, const size_t len);
|
||||
|
||||
int is_readable(int fd);
|
||||
int is_writable(int fd);
|
|
@ -250,12 +250,18 @@ void *handle_events(void *a) {
|
|||
|
||||
// Check downstream
|
||||
struct ng_session *session = (struct ng_session *) ev[i].data.ptr;
|
||||
if (session->protocol == IPPROTO_ICMP || session->protocol == IPPROTO_ICMPV6)
|
||||
check_icmp_socket(args, &ev[i]);
|
||||
else if (session->protocol == IPPROTO_UDP)
|
||||
check_udp_socket(args, &ev[i]);
|
||||
else if (session->protocol == IPPROTO_TCP)
|
||||
check_tcp_socket(args, &ev[i], epoll_fd);
|
||||
do {
|
||||
if (session->protocol == IPPROTO_ICMP ||
|
||||
session->protocol == IPPROTO_ICMPV6)
|
||||
check_icmp_socket(args, &ev[i]);
|
||||
else if (session->protocol == IPPROTO_UDP)
|
||||
check_udp_socket(args, &ev[i]);
|
||||
else if (session->protocol == IPPROTO_TCP) {
|
||||
check_tcp_socket(args, &ev[i], epoll_fd);
|
||||
}
|
||||
} while (!(ev[i].events & EPOLLERR) &&
|
||||
(ev[i].events & EPOLLIN) &&
|
||||
is_readable(session->socket));
|
||||
}
|
||||
|
||||
if (error)
|
||||
|
|
|
@ -152,10 +152,10 @@ int32_t get_local_port(const int sock) {
|
|||
return ntohs(sin.sin_port);
|
||||
}
|
||||
|
||||
int is_readable(int fd) {
|
||||
int is_event(int fd, short event) {
|
||||
struct pollfd p;
|
||||
p.fd = fd;
|
||||
p.events = POLLIN;
|
||||
p.events = event;
|
||||
p.revents = 0;
|
||||
int r = poll(&p, 1, 0);
|
||||
if (r < 0) {
|
||||
|
@ -165,5 +165,13 @@ int is_readable(int fd) {
|
|||
else if (r == 0)
|
||||
return 0;
|
||||
else
|
||||
return (p.revents & POLLIN);
|
||||
return (p.revents & event);
|
||||
}
|
||||
|
||||
int is_readable(int fd) {
|
||||
return is_event(fd, POLLIN);
|
||||
}
|
||||
|
||||
int is_writable(int fd) {
|
||||
return is_event(fd, POLLOUT);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue