1
0
Fork 0
mirror of https://github.com/M66B/NetGuard.git synced 2025-02-24 15:21:19 +00:00

Read tun while readable

Refs #431
This commit is contained in:
M66B 2016-06-25 09:28:34 +02:00
parent 32304b549f
commit 00cc6fea1c
3 changed files with 21 additions and 2 deletions

View file

@ -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);

View file

@ -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,

View file

@ -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);
}