]> git.sesse.net Git - greproxy/blobdiff - tungre.cpp
Merge branch 'master' of /srv/git.sesse.net/www/greproxy
[greproxy] / tungre.cpp
index 55bd973602b888bbf57e5e5c63ce8c399667c422..fd5ef8f973383d0a398a5f8cf348cd7d876d0118 100644 (file)
@@ -10,6 +10,7 @@
 #include "tunprotocol.h"
 #include "rsdecoder.h"
 #include "pacer.h"
+#include "timeutil.h"
 
 using namespace std;
 
@@ -34,12 +35,20 @@ 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);
+               tun_reorderer.possibly_adjust_tv(&tv);
                tun_pacer.possibly_adjust_tv(&tv);
                int ret = select(1024, &fds, NULL, NULL, &tv);
                if (ret == -1) {
@@ -54,5 +63,32 @@ int main(int argc, char **argv)
                        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;
+               }
        }
 }