version 1.1.1.1, 2013/07/21 23:43:41
|
version 1.1.1.2, 2016/11/01 09:33:48
|
Line 16
|
Line 16
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
*/ |
*/ |
|
|
#include <config.h> | #include "config.h" |
| |
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/time.h> |
#include <sys/time.h> |
#include <stdlib.h> |
#include <stdlib.h> |
Line 29
|
Line 30
|
#include <errno.h> |
#include <errno.h> |
|
|
#include "mtr.h" |
#include "mtr.h" |
#include "display.h" |
|
#include "dns.h" |
#include "dns.h" |
#include "net.h" |
#include "net.h" |
#ifndef NO_IPINFO |
|
#include "asn.h" |
#include "asn.h" |
#endif | #include "display.h" |
|
|
extern int Interactive; |
extern int Interactive; |
extern int MaxPing; |
extern int MaxPing; |
Line 47 static struct timeval intervaltime;
|
Line 46 static struct timeval intervaltime;
|
int display_offset = 0; |
int display_offset = 0; |
|
|
|
|
|
#define GRACETIME (5 * 1000*1000) |
|
|
void select_loop(void) { |
void select_loop(void) { |
fd_set readfd; |
fd_set readfd; |
fd_set writefd; |
fd_set writefd; |
Line 59 void select_loop(void) {
|
Line 60 void select_loop(void) {
|
int NumPing = 0; |
int NumPing = 0; |
int paused = 0; |
int paused = 0; |
struct timeval lasttime, thistime, selecttime; |
struct timeval lasttime, thistime, selecttime; |
|
struct timeval startgrace; |
int dt; |
int dt; |
int rv; |
int rv; |
|
int graceperiod = 0; |
|
|
|
memset(&startgrace, 0, sizeof(startgrace)); |
|
|
gettimeofday(&lasttime, NULL); |
gettimeofday(&lasttime, NULL); |
|
|
while(1) { |
while(1) { |
Line 82 void select_loop(void) {
|
Line 87 void select_loop(void) {
|
#ifdef ENABLE_IPV6 |
#ifdef ENABLE_IPV6 |
if (dns) { |
if (dns) { |
dnsfd6 = dns_waitfd6(); |
dnsfd6 = dns_waitfd6(); |
FD_SET(dnsfd6, &readfd); | if (dnsfd6 >= 0) { |
if(dnsfd6 >= maxfd) maxfd = dnsfd6 + 1; | FD_SET(dnsfd6, &readfd); |
| if(dnsfd6 >= maxfd) maxfd = dnsfd6 + 1; |
| } else { |
| dnsfd6 = 0; |
| } |
} else |
} else |
dnsfd6 = 0; |
dnsfd6 = 0; |
#endif |
#endif |
Line 103 void select_loop(void) {
|
Line 112 void select_loop(void) {
|
|
|
do { |
do { |
if(anyset || paused) { |
if(anyset || paused) { |
|
/* Set timeout to 0.1s. |
|
* While this is almost instantaneous for human operators, |
|
* it's slow enough for computers to go do something else; |
|
* this prevents mtr from hogging 100% CPU time on one core. |
|
*/ |
selecttime.tv_sec = 0; |
selecttime.tv_sec = 0; |
selecttime.tv_usec = 0; | selecttime.tv_usec = paused?100000:0; |
|
|
rv = select(maxfd, (void *)&readfd, &writefd, NULL, &selecttime); |
rv = select(maxfd, (void *)&readfd, &writefd, NULL, &selecttime); |
|
|
Line 117 void select_loop(void) {
|
Line 131 void select_loop(void) {
|
(thistime.tv_sec == lasttime.tv_sec + intervaltime.tv_sec && |
(thistime.tv_sec == lasttime.tv_sec + intervaltime.tv_sec && |
thistime.tv_usec >= lasttime.tv_usec + intervaltime.tv_usec)) { |
thistime.tv_usec >= lasttime.tv_usec + intervaltime.tv_usec)) { |
lasttime = thistime; |
lasttime = thistime; |
if(NumPing >= MaxPing && (!Interactive || ForceMaxPing)) | |
| if (!graceperiod) { |
| if (NumPing >= MaxPing && (!Interactive || ForceMaxPing)) { |
| graceperiod = 1; |
| startgrace = thistime; |
| } |
| |
| /* do not send out batch when we've already initiated grace period */ |
| if (!graceperiod && net_send_batch()) |
| NumPing++; |
| } |
| } |
| |
| if (graceperiod) { |
| dt = (thistime.tv_usec - startgrace.tv_usec) + |
| 1000000 * (thistime.tv_sec - startgrace.tv_sec); |
| if (dt > GRACETIME) |
return; |
return; |
if (net_send_batch()) |
|
NumPing++; |
|
} |
} |
|
|
selecttime.tv_usec = (thistime.tv_usec - lasttime.tv_usec); |
selecttime.tv_usec = (thistime.tv_usec - lasttime.tv_usec); |
Line 169 void select_loop(void) {
|
Line 197 void select_loop(void) {
|
|
|
/* Have we finished a nameservice lookup? */ |
/* Have we finished a nameservice lookup? */ |
#ifdef ENABLE_IPV6 |
#ifdef ENABLE_IPV6 |
if(dns && FD_ISSET(dnsfd6, &readfd)) { | if(dns && dnsfd6 && FD_ISSET(dnsfd6, &readfd)) { |
dns_ack6(); |
dns_ack6(); |
anyset = 1; |
anyset = 1; |
} |
} |
#endif |
#endif |
if(dns && FD_ISSET(dnsfd, &readfd)) { | if(dns && dnsfd && FD_ISSET(dnsfd, &readfd)) { |
dns_ack(); |
dns_ack(); |
anyset = 1; |
anyset = 1; |
} |
} |
Line 210 void select_loop(void) {
|
Line 238 void select_loop(void) {
|
display_clear(); |
display_clear(); |
} |
} |
break; |
break; |
#ifndef NO_IPINFO | #ifdef IPINFO |
case ActionII: |
case ActionII: |
if (ipinfo_no >= 0) { |
if (ipinfo_no >= 0) { |
ipinfo_no++; |
ipinfo_no++; |