From: Steinar H. Gunderson Date: Sat, 7 Feb 2015 10:56:15 +0000 (+0100) Subject: Split Protocol into Sender and Reader. X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=6eb319dbbc9305b984fd70e8e6d5adebf87edbb7;p=greproxy Split Protocol into Sender and Reader. --- diff --git a/greprotocol.cpp b/greprotocol.cpp index 0e6b945..2fb2503 100644 --- a/greprotocol.cpp +++ b/greprotocol.cpp @@ -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); diff --git a/greprotocol.h b/greprotocol.h index 9cec54b..fd595b7 100644 --- a/greprotocol.h +++ b/greprotocol.h @@ -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; diff --git a/protocol.h b/protocol.h index 8b06f0a..65c4d1d 100644 --- a/protocol.h +++ b/protocol.h @@ -4,10 +4,15 @@ #include #include -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) diff --git a/reorderer.cpp b/reorderer.cpp index b6ac6a9..e18b63f 100644 --- a/reorderer.cpp +++ b/reorderer.cpp @@ -7,7 +7,7 @@ using namespace std; -Reorderer::Reorderer(Protocol* sender) +Reorderer::Reorderer(Sender* sender) : sender(sender), last_seq(-1) { } diff --git a/reorderer.h b/reorderer.h index 393e327..cdde814 100644 --- a/reorderer.h +++ b/reorderer.h @@ -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, std::greater> packet_buffer; diff --git a/tunprotocol.cpp b/tunprotocol.cpp index 534c8bd..f8bde7d 100644 --- a/tunprotocol.cpp +++ b/tunprotocol.cpp @@ -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)); diff --git a/tunprotocol.h b/tunprotocol.h index 9af2e78..7f16066 100644 --- a/tunprotocol.h +++ b/tunprotocol.h @@ -6,12 +6,12 @@ #include #include -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;