only select for write, if it was not possible before
authorPhilipp Tölke <toelke@in.tum.de>
Tue, 20 Jul 2010 11:36:45 +0000 (11:36 +0000)
committerPhilipp Tölke <toelke@in.tum.de>
Tue, 20 Jul 2010 11:36:45 +0000 (11:36 +0000)
src/vpn/gnunet-vpn-helper.c

index 0577173b05393d4ac77c78ff3f8f702dddc62071..928ede4c61adff475b13ba8bd288cd37e11b93ef 100644 (file)
@@ -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");