aboutsummaryrefslogtreecommitdiff
path: root/src/vpn
diff options
context:
space:
mode:
authorPhilipp Tölke <toelke@in.tum.de>2010-07-20 11:36:45 +0000
committerPhilipp Tölke <toelke@in.tum.de>2010-07-20 11:36:45 +0000
commit4cde4cfe794999bc5337f9e560bd95cdbccdf00f (patch)
tree42a6ebdc83b09390651051d63dad1f963b73a7ee /src/vpn
parent0cf7809e4926f01de6a7a404a9d311b5cf2b421b (diff)
downloadgnunet-4cde4cfe794999bc5337f9e560bd95cdbccdf00f.tar.gz
gnunet-4cde4cfe794999bc5337f9e560bd95cdbccdf00f.zip
only select for write, if it was not possible before
Diffstat (limited to 'src/vpn')
-rw-r--r--src/vpn/gnunet-vpn-helper.c18
1 files 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) {
139 139
140 int rea = 1; 140 int rea = 1;
141 int wri = 1; 141 int wri = 1;
142
143 int write_fd_possible = 0;
144 int write_stdout_possible = 0;
142outer: 145outer:
143 while(rea != 0 && wri != 0 && running == 1) { 146 while(rea != 0 && wri != 0 && running == 1) {
144 FD_ZERO(&fds_w); 147 FD_ZERO(&fds_w);
@@ -146,18 +149,24 @@ outer:
146 149
147 if (rea) { 150 if (rea) {
148 FD_SET(fd_tun, &fds_r); 151 FD_SET(fd_tun, &fds_r);
149 FD_SET(1, &fds_w); 152 if (!write_stdout_possible)
153 FD_SET(1, &fds_w);
150 } 154 }
151 155
152 if (wri) { 156 if (wri) {
153 FD_SET(0, &fds_r); 157 FD_SET(0, &fds_r);
154 FD_SET(fd_tun, &fds_w); 158 if (!write_fd_possible)
159 FD_SET(fd_tun, &fds_w);
155 } 160 }
156 161
157 int r = select(fd_tun+1, &fds_r, &fds_w, (fd_set*)0, 0); 162 int r = select(fd_tun+1, &fds_r, &fds_w, (fd_set*)0, 0);
158 163
159 if(r > 0) { 164 if(r > 0) {
160 if (FD_ISSET(0, &fds_r) && FD_ISSET(fd_tun, &fds_w)) { 165 if (FD_ISSET(fd_tun, &fds_w)) write_fd_possible = 1;
166 if (FD_ISSET(1, &fds_w)) write_stdout_possible = 1;
167
168 if (FD_ISSET(0, &fds_r) && write_fd_possible) {
169 write_fd_possible = 0;
161 struct suid_packet *pkt = (struct suid_packet*) buf; 170 struct suid_packet *pkt = (struct suid_packet*) buf;
162 r = read(0, buf, sizeof(struct suid_packet_header)); 171 r = read(0, buf, sizeof(struct suid_packet_header));
163 if (r < 0) { 172 if (r < 0) {
@@ -190,7 +199,8 @@ outer:
190 } 199 }
191 r += t; 200 r += t;
192 } 201 }
193 } else if (FD_ISSET(1, &fds_w) && FD_ISSET(fd_tun, &fds_r)) { 202 } else if (write_stdout_possible && FD_ISSET(fd_tun, &fds_r)) {
203 write_stdout_possible = 0;
194 r = read(fd_tun, buf, 65600); 204 r = read(fd_tun, buf, 65600);
195 if (r < 0) { 205 if (r < 0) {
196 fprintf(stderr, "read-error: %m\n"); 206 fprintf(stderr, "read-error: %m\n");