X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=tungre.cpp;h=fd5ef8f973383d0a398a5f8cf348cd7d876d0118;hb=HEAD;hp=ea736fbc2fa600d78738da8c750e0ebd6a1fb77c;hpb=45fc511092347489c5cb6ed76cd5fba593b93fa6;p=greproxy diff --git a/tungre.cpp b/tungre.cpp index ea736fb..fd5ef8f 100644 --- a/tungre.cpp +++ b/tungre.cpp @@ -10,6 +10,7 @@ #include "tunprotocol.h" #include "rsdecoder.h" #include "pacer.h" +#include "timeutil.h" using namespace std; @@ -34,12 +35,22 @@ int main(int argc, char **argv) Reorderer tun_reorderer(&tun_pacer); RSDecoder tun_decoder(&tun_reorderer); + int last_rcvd = 0, last_reorders = 0; + int last_fec_recovered = 0, last_lost = 0; + int last_output = 0, last_ts_discontinuities = 0; + int last_sent = 0; + timeval last_print; + gettimeofday(&last_print, NULL); + fd_set fds; FD_ZERO(&fds); for ( ;; ) { + timeval tv = { 1, 0 }; FD_SET(gre.fd(), &fds); FD_SET(tun.fd(), &fds); - int ret = select(1024, &fds, NULL, NULL, NULL); + tun_reorderer.possibly_adjust_tv(&tv); + tun_pacer.possibly_adjust_tv(&tv); + int ret = select(1024, &fds, NULL, NULL, &tv); if (ret == -1) { perror("select"); continue; @@ -51,5 +62,33 @@ int main(int argc, char **argv) if (FD_ISSET(tun.fd(), &fds)) { tun.read_packet(&gre_pacer); } + tun_pacer.possibly_flush_packets(); + + timeval now; + gettimeofday(&now, NULL); + + if (tdiff(last_print, now) > 10.0) { + int rcvd = gre.get_received_packets(); + int fec_recovered = tun_decoder.get_recovered_packets(); + int reorders = tun_reorderer.get_reorders(); + int lost = tun_reorderer.get_lost_packets(); + int output = tun.get_sent_packets(); + int ts_discontinuities = tun_reorderer.get_ts_discontinuities(); + int sent = gre.get_sent_packets(); + fprintf(stderr, "%5dp rcvd, %3dp FEC recovered, %4d reorders, %3dp lost, %5dp output, %3d TS discontinuities. %5dp sent\n", + rcvd - last_rcvd, fec_recovered - last_fec_recovered, + reorders - last_reorders, lost - last_lost, + output - last_output, + ts_discontinuities - last_ts_discontinuities, + sent - last_sent); + last_rcvd = rcvd; + last_fec_recovered = fec_recovered; + last_reorders = reorders; + last_lost = lost; + last_output = output; + last_ts_discontinuities = ts_discontinuities; + last_sent = sent; + last_print = now; + } } }