]> git.sesse.net Git - greproxy/commitdiff
Split Protocol into Sender and Reader.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 7 Feb 2015 10:56:15 +0000 (11:56 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 7 Feb 2015 10:56:15 +0000 (11:56 +0100)
greprotocol.cpp
greprotocol.h
protocol.h
reorderer.cpp
reorderer.h
tunprotocol.cpp
tunprotocol.h

index 0e6b945c371f377ea6506717a0fbd5e8c954f257..2fb2503d3e0cbc240d9220e5c072cf24ca79edd0 100644 (file)
@@ -74,7 +74,7 @@ int GREProtocol::fd() const
        return sock;
 }
 
-void GREProtocol::read_packet(Protocol *sender)
+void GREProtocol::read_packet(Sender *sender)
 {
        struct sockaddr_storage addr;
        socklen_t addrlen = sizeof(addr);
index 9cec54b7658897e0a98f158d2ff130998e0cc9e7..fd595b7a05e9b8bc59501847e6d28ea41aa51903 100644 (file)
@@ -8,14 +8,12 @@
 
 #include "protocol.h"
 
-class Reorderer;
-
-class GREProtocol : public Protocol {
+class GREProtocol : public Sender, public Reader {
 public:
        GREProtocol(const in6_addr &myaddr, const in6_addr &dst);
        virtual void send_packet(uint16_t proto, const std::string &data, int incoming_seq);
        virtual int fd() const;
-       void read_packet(Protocol* sender);
+       virtual void read_packet(Sender* sender);
 
 private:
        int seq;
index 8b06f0a34be907fcd5cc1ef51d06ab43458a32f5..65c4d1d10f538952a2fd6de679953e35168ccdad 100644 (file)
@@ -4,10 +4,15 @@
 #include <stdint.h>
 #include <string>
 
-class Protocol {
+class Sender {
 public:
        virtual void send_packet(uint16_t proto, const std::string &data, int incoming_seq) = 0;
+};
+
+class Reader {
+public:
        virtual int fd() const = 0;
+       virtual void read_packet(Sender* sender) = 0;
 };
 
 #endif  // !defined(_PROTOCOL_H)
index b6ac6a9079906b8aaac5944ef8398f88fdc341e9..e18b63f6007689161bdbf88ef3af03444ab786c2 100644 (file)
@@ -7,7 +7,7 @@
 
 using namespace std;
 
-Reorderer::Reorderer(Protocol* sender)
+Reorderer::Reorderer(Sender* sender)
        : sender(sender), last_seq(-1)
 {
 }
index 393e327f7dbe86053fb374fd9601720c3a9e8195..cdde8146a090a04ddd7d44b7ce836cef4a4850e0 100644 (file)
@@ -22,16 +22,15 @@ struct GREPacket {
        }
 };
 
-class Reorderer : public Protocol {
+class Reorderer : public Sender {
 public:
-       Reorderer(Protocol* sender);
+       Reorderer(Sender* sender);
        void send_packet(uint16_t proto, const std::string& data, int seq);
-       virtual int fd() const { assert(false); }
 
 private:
        void check_ts_discontinuity(uint16_t proto, const std::string &data, bool silence);
 
-       Protocol* sender;
+       Sender* sender;
        int last_seq;
 
        std::priority_queue<GREPacket, std::vector<GREPacket>, std::greater<GREPacket>> packet_buffer;
index 534c8bdabfc77bb8aaad6a642fa1a196676f10bd..f8bde7d3627279dfcf84e8cc3c1cfca00c136c07 100644 (file)
@@ -69,7 +69,7 @@ int TUNProtocol::fd() const
        return tunfd;
 }
 
-void TUNProtocol::read_packet(Protocol *sender)
+void TUNProtocol::read_packet(Sender *sender)
 {
        char buf[4096];
        int ret = read(tunfd, buf, sizeof(buf));
index 9af2e78149787815e9d1994757b2f0c1c9639a3c..7f160668f7973985988f515cd98d925f38263896 100644 (file)
@@ -6,12 +6,12 @@
 #include <stdint.h>
 #include <string>
 
-class TUNProtocol : public Protocol {
+class TUNProtocol : public Sender, public Reader {
 public:
        TUNProtocol(const char *devname);
        virtual void send_packet(uint16_t proto, const std::string &data, int incoming_seq);
        virtual int fd() const;
-       void read_packet(Protocol* sender);
+       virtual void read_packet(Sender* sender);
 
 private:
        int tunfd;