From 4cde4cfe794999bc5337f9e560bd95cdbccdf00f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Philipp=20T=C3=B6lke?= Date: Tue, 20 Jul 2010 11:36:45 +0000 Subject: [PATCH] only select for write, if it was not possible before --- src/vpn/gnunet-vpn-helper.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/vpn/gnunet-vpn-helper.c b/src/vpn/gnunet-vpn-helper.c index 0577173b0..928ede4c6 100644 --- a/src/vpn/gnunet-vpn-helper.c +++ b/src/vpn/gnunet-vpn-helper.c @@ -139,6 +139,9 @@ int main(int argc, char** argv) { int rea = 1; int wri = 1; + + int write_fd_possible = 0; + int write_stdout_possible = 0; outer: while(rea != 0 && wri != 0 && running == 1) { FD_ZERO(&fds_w); @@ -146,18 +149,24 @@ outer: if (rea) { FD_SET(fd_tun, &fds_r); - FD_SET(1, &fds_w); + if (!write_stdout_possible) + FD_SET(1, &fds_w); } if (wri) { FD_SET(0, &fds_r); - FD_SET(fd_tun, &fds_w); + if (!write_fd_possible) + FD_SET(fd_tun, &fds_w); } int r = select(fd_tun+1, &fds_r, &fds_w, (fd_set*)0, 0); if(r > 0) { - if (FD_ISSET(0, &fds_r) && FD_ISSET(fd_tun, &fds_w)) { + if (FD_ISSET(fd_tun, &fds_w)) write_fd_possible = 1; + if (FD_ISSET(1, &fds_w)) write_stdout_possible = 1; + + if (FD_ISSET(0, &fds_r) && write_fd_possible) { + write_fd_possible = 0; struct suid_packet *pkt = (struct suid_packet*) buf; r = read(0, buf, sizeof(struct suid_packet_header)); if (r < 0) { @@ -190,7 +199,8 @@ outer: } r += t; } - } else if (FD_ISSET(1, &fds_w) && FD_ISSET(fd_tun, &fds_r)) { + } else if (write_stdout_possible && FD_ISSET(fd_tun, &fds_r)) { + write_stdout_possible = 0; r = read(fd_tun, buf, 65600); if (r < 0) { fprintf(stderr, "read-error: %m\n"); -- 2.25.1