]> git.sesse.net Git - greproxy/commitdiff
Make Reorderer handle multi-timeouts.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 8 Feb 2015 22:35:42 +0000 (23:35 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 8 Feb 2015 22:35:42 +0000 (23:35 +0100)
greproxy.cpp
reorderer.cpp
reorderer.h

index bf28295d02dd79aa9fc3bdbd6b91a4b55c1d913e..79db570b60c8a733e9e3cf36b4825ababa4465ba 100644 (file)
@@ -43,6 +43,8 @@ int main(int argc, char **argv)
                FD_SET(gre_b.fd(), &fds);
                pacer_a.possibly_adjust_tv(&tv);
                pacer_b.possibly_adjust_tv(&tv);
+               reorder_a.possibly_adjust_tv(&tv);
+               reorder_b.possibly_adjust_tv(&tv);
                int ret = select(1024, &fds, NULL, NULL, &tv);
                if (ret == -1) {
                        perror("select");
index 1fe3c08275ba859dbe8f6a3307e1e356ccc2d3a8..2533aadc042064a7577e55c45a56718ad04faa6f 100644 (file)
@@ -15,6 +15,21 @@ Reorderer::Reorderer(Sender* sender)
        gettimeofday(&last_sent_packet, NULL);
 }
 
+void Reorderer::possibly_adjust_tv(timeval *tv)
+{
+       if (packet_buffer.empty()) {
+               return;
+       }
+
+       timeval now;
+       gettimeofday(&now, NULL);
+       timeval tdiff = subtract_timeval_saturate(
+               offset_timeval_seconds(packet_buffer.top().ts, TIMEOUT_SEC), now);
+       if (less_than(tdiff, *tv)) {
+               *tv = tdiff;
+       }
+}
+
 void Reorderer::send_packet(uint16_t proto, const string& data, int seq)
 {
        timeval now;
@@ -32,8 +47,6 @@ void Reorderer::send_packet(uint16_t proto, const string& data, int seq)
                        last_seq + 1, packet_buffer.top().seq);
                silence = true;
                last_seq = packet_buffer.top().seq - 1;
-               // TODO: Rerun immediately after we've cleared out,
-               // in case there are more timeouts.
        }
 
        // In case of restarts.
index 0007a2bcd00314779818bff24a7b577ba4057781..622083e0563da0f968161e98654f144cc2666fd1 100644 (file)
@@ -28,6 +28,7 @@ class Reorderer : public Sender {
 public:
        Reorderer(Sender* sender);
        void send_packet(uint16_t proto, const std::string& data, int seq);
+       void possibly_adjust_tv(timeval *tv);
 
 private:
        void check_ts_discontinuity(uint16_t proto, const std::string &data, bool silence);