Eliminate extra 'ping' message when server sends data to client which generates a reply

This commit is contained in:
Erik Ekman 2008-08-07 15:05:51 +00:00 committed by Erik Ekman
parent b1bab9c3dc
commit a07187a629
2 changed files with 18 additions and 8 deletions

View file

@ -12,6 +12,8 @@ CHANGES:
- The server now replies to all received queries. - The server now replies to all received queries.
- Fixed segfault in server when sending version reject. - Fixed segfault in server when sending version reject.
- The interval between "pings" from clients is now 5 seconds. - The interval between "pings" from clients is now 5 seconds.
- Eliminited extra "ping" messages from client to server when server
sends data and gets data back directly.
2008-08-06: 0.4.2 "Opened Zone" 2008-08-06: 0.4.2 "Opened Zone"
- Applied a few small patches from Maxim Bourmistrov and Gregor Herrmann - Applied a few small patches from Maxim Bourmistrov and Gregor Herrmann

View file

@ -233,10 +233,6 @@ tunnel_dns(int tun_fd, int dns_fd)
write_tun(tun_fd, out, outlen); write_tun(tun_fd, out, outlen);
/* Server may have more data to send me, ask for it */
if (!is_sending())
send_ping(dns_fd);
return read; return read;
} }
@ -247,12 +243,20 @@ tunnel(int tun_fd, int dns_fd)
fd_set fds; fd_set fds;
int rv; int rv;
int i; int i;
int short_ping;
rv = 0; rv = 0;
short_ping = 0;
while (running) { while (running) {
if (short_ping) {
tv.tv_sec = 0;
tv.tv_usec = 5000;
short_ping = 0;
} else {
tv.tv_sec = 5; tv.tv_sec = 5;
tv.tv_usec = 0; tv.tv_usec = 0;
}
FD_ZERO(&fds); FD_ZERO(&fds);
if (!is_sending()) if (!is_sending())
@ -267,9 +271,9 @@ tunnel(int tun_fd, int dns_fd)
if (i < 0) if (i < 0)
err(1, "select"); err(1, "select");
if (i == 0) /* timeout */ if (i == 0) { /* timeout */
send_ping(dns_fd); send_ping(dns_fd);
else { } else {
if (FD_ISSET(tun_fd, &fds)) { if (FD_ISSET(tun_fd, &fds)) {
if (tunnel_tun(tun_fd, dns_fd) <= 0) if (tunnel_tun(tun_fd, dns_fd) <= 0)
continue; continue;
@ -277,6 +281,10 @@ tunnel(int tun_fd, int dns_fd)
if (FD_ISSET(dns_fd, &fds)) { if (FD_ISSET(dns_fd, &fds)) {
if (tunnel_dns(tun_fd, dns_fd) <= 0) if (tunnel_dns(tun_fd, dns_fd) <= 0)
continue; continue;
/* If we have nothing to send within x ms, send a ping
* to get more data from server */
if (!is_sending())
short_ping = 1;
} }
} }
} }