]> git.sesse.net Git - greproxy/blobdiff - pacer.h
Add some packet pacing, to reduce the burstiness many parts of the networking do...
[greproxy] / pacer.h
diff --git a/pacer.h b/pacer.h
new file mode 100644 (file)
index 0000000..90d0c4f
--- /dev/null
+++ b/pacer.h
@@ -0,0 +1,28 @@
+#ifndef _PACER_H
+#define _PACER_H 1
+
+#include <stdint.h>
+#include <sys/time.h>
+#include <deque>
+#include <string>
+
+#include "protocol.h"
+#include "reorderer.h"
+
+struct Pacer : public Sender {
+public:
+       Pacer(Sender *sender, int max_rate_kbit_per_sec, int burst_num_packets);
+       virtual void send_packet(uint16_t proto, const std::string &data, int incoming_seq);
+
+       void possibly_adjust_tv(timeval *tv);
+       void possibly_flush_packets();
+
+private:
+       Sender *sender;
+       int burst_num_packets;
+       double seconds_per_byte;
+       timeval next_send_packet;
+       std::deque<GREPacket> waiting_packets;
+};
+
+#endif  // !defined(_PACER_H)