Use fcntl(O_NONBLOCK) instead of old FIONBIO and set tun.fd to be non-blocking
This commit is contained in:
15
glorytun.c
15
glorytun.c
@@ -22,15 +22,20 @@ volatile sig_atomic_t running;
|
|||||||
|
|
||||||
static void fd_set_nonblock (int fd)
|
static void fd_set_nonblock (int fd)
|
||||||
{
|
{
|
||||||
int val, ret;
|
int ret;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
val = 1;
|
ret = fcntl(fd, F_GETFL, 0);
|
||||||
ret = ioctl(fd, FIONBIO, &val);
|
} while (ret==-1 && errno==EINTR);
|
||||||
|
|
||||||
|
int flags = (ret==-1)?0:ret;
|
||||||
|
|
||||||
|
do {
|
||||||
|
ret = fcntl(fd, F_SETFL, flags|O_NONBLOCK);
|
||||||
} while (ret==-1 && errno==EINTR);
|
} while (ret==-1 && errno==EINTR);
|
||||||
|
|
||||||
if (ret==-1)
|
if (ret==-1)
|
||||||
perror("ioctl FIONBIO");
|
perror("fcntl O_NONBLOCK");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fd_set_nodelay (int fd)
|
static void fd_set_nodelay (int fd)
|
||||||
@@ -318,6 +323,8 @@ int main (int argc, char **argv)
|
|||||||
if (tun.fd==-1)
|
if (tun.fd==-1)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
fd_set_nonblock(tun.fd);
|
||||||
|
|
||||||
buffer_setup(&tun.recv, NULL, GT_BUFFER_SIZE);
|
buffer_setup(&tun.recv, NULL, GT_BUFFER_SIZE);
|
||||||
buffer_setup(&sock.recv, NULL, GT_BUFFER_SIZE);
|
buffer_setup(&sock.recv, NULL, GT_BUFFER_SIZE);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user