Dont try to poll for write, use a timeout

This commit is contained in:
angt
2015-12-03 18:49:18 +01:00
parent d787fa1dca
commit cbdba8cba3

View File

@@ -862,9 +862,8 @@ int main (int argc, char **argv)
break; break;
} }
fd_set rfds, wfds; fd_set rfds;
FD_ZERO(&rfds); FD_ZERO(&rfds);
FD_ZERO(&wfds);
int stop_loop = 0; int stop_loop = 0;
@@ -886,16 +885,17 @@ int main (int argc, char **argv)
FD_SET(sock.fd, &rfds); FD_SET(sock.fd, &rfds);
if _0_(select(sock.fd+1, &rfds, &wfds, NULL, NULL)==-1) { struct timeval timeout = {
.tv_usec = 1000,
};
if _0_(select(sock.fd+1, &rfds, NULL, NULL, &timeout)==-1) {
if (errno==EINTR) if (errno==EINTR)
continue; continue;
perror("select"); perror("select");
return 1; return 1;
} }
FD_CLR(sock.fd, &wfds);
FD_CLR(tun.fd, &wfds);
// TODO // TODO
// struct timeval now; // struct timeval now;
// gettimeofday(&now, NULL); // gettimeofday(&now, NULL);
@@ -969,11 +969,8 @@ int main (int argc, char **argv)
if (r>0) { if (r>0) {
sock.write.read += r; sock.write.read += r;
} else { } else {
if (!r) { if (!r)
stop_loop |= (1<<2); stop_loop |= (1<<2);
} else {
FD_SET(sock.fd, &wfds);
}
break; break;
} }
} }
@@ -1028,7 +1025,6 @@ int main (int argc, char **argv)
tun.write.read += r; tun.write.read += r;
} else { } else {
gt_close |= !r; gt_close |= !r;
FD_SET(tun.fd, &wfds);
break; break;
} }
} }