mirror of
https://github.com/M66B/NetGuard.git
synced 2025-02-24 15:21:19 +00:00
parent
32304b549f
commit
00cc6fea1c
3 changed files with 21 additions and 2 deletions
|
@ -8,6 +8,7 @@
|
|||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <dirent.h>
|
||||
#include <poll.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
|
@ -498,3 +499,5 @@ int compare_u32(uint32_t seq1, uint32_t seq2);
|
|||
const char *strstate(const int state);
|
||||
|
||||
char *hex(const u_int8_t *data, const size_t len);
|
||||
|
||||
int is_readable(int fd);
|
||||
|
|
|
@ -233,8 +233,9 @@ void *handle_events(void *a) {
|
|||
(ev[i].events & EPOLLHUP) != 0);
|
||||
|
||||
// Check upstream
|
||||
if (check_tun(args, &ev[i], epoll_fd, sessions, maxsessions) < 0)
|
||||
error = 1;
|
||||
while (!error && is_readable(args->tun))
|
||||
if (check_tun(args, &ev[i], epoll_fd, sessions, maxsessions) < 0)
|
||||
error = 1;
|
||||
|
||||
} else {
|
||||
log_android(ANDROID_LOG_DEBUG,
|
||||
|
|
|
@ -152,3 +152,18 @@ int32_t get_local_port(const int sock) {
|
|||
return ntohs(sin.sin_port);
|
||||
}
|
||||
|
||||
int is_readable(int fd) {
|
||||
struct pollfd p;
|
||||
p.fd = fd;
|
||||
p.events = POLLIN;
|
||||
p.revents = 0;
|
||||
int r = poll(&p, 1, 0);
|
||||
if (r < 0) {
|
||||
log_android(ANDROID_LOG_ERROR, "poll readable error %d: %s", errno, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
else if (r == 0)
|
||||
return 0;
|
||||
else
|
||||
return (p.revents & POLLIN);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue