]> git.sesse.net Git - greproxy/blob - reorderer.h
Make Reorderer handle multi-timeouts.
[greproxy] / reorderer.h
1 #ifndef _REORDERER_H
2 #define _REORDERER_H 1
3
4 #include <assert.h>
5 #include <stdint.h>
6 #include <sys/time.h>
7
8 #include <algorithm>
9 #include <map>
10 #include <queue>
11 #include <string>
12 #include <vector>
13
14 #include "protocol.h"
15
16 struct GREPacket {
17         int seq;
18         uint16_t proto;
19         std::string data;
20         timeval ts;
21
22         bool operator> (const GREPacket &other) const {
23                 return seq > other.seq;
24         }
25 };
26
27 class Reorderer : public Sender {
28 public:
29         Reorderer(Sender* sender);
30         void send_packet(uint16_t proto, const std::string& data, int seq);
31         void possibly_adjust_tv(timeval *tv);
32
33 private:
34         void check_ts_discontinuity(uint16_t proto, const std::string &data, bool silence);
35
36         Sender* sender;
37         int last_seq;
38         timeval last_sent_packet;
39
40         std::priority_queue<GREPacket, std::vector<GREPacket>, std::greater<GREPacket>> packet_buffer;
41         std::map<int, int> ccs;
42 };
43
44 #endif  // !defined(_REORDERER_H)