]> git.localhorst.tv Git - blank.git/blobdiff - src/net/Connection.hpp
transmit chunks from server to client
[blank.git] / src / net / Connection.hpp
index cc13ef60915df48dc676228535c50101f0eccc9d..ed7a946aab01d2296123f9f68229d46a2b9b4b48 100644 (file)
 
 namespace blank {
 
+class ConnectionHandler;
+
 class Connection {
 
 public:
        explicit Connection(const IPaddress &);
 
+       void SetHandler(ConnectionHandler *h) noexcept { handler = h; }
+       void RemoveHandler() noexcept { handler = nullptr; }
+       bool HasHandler() const noexcept { return handler; }
+       ConnectionHandler &Handler() noexcept { return *handler; }
+
        const IPaddress &Address() const noexcept { return addr; }
 
        bool Matches(const IPaddress &) const noexcept;
@@ -23,13 +30,13 @@ public:
        bool TimedOut() const noexcept;
 
        void Close() noexcept { closed = true; }
-       bool Closed() const noexcept { return closed || TimedOut(); }
+       bool Closed() const noexcept { return closed; }
 
        void Update(int dt);
 
-       void SendPing(UDPpacket &, UDPsocket);
+       std::uint16_t SendPing(UDPpacket &, UDPsocket);
 
-       void Send(UDPpacket &, UDPsocket);
+       std::uint16_t Send(UDPpacket &, UDPsocket);
        void Received(const UDPpacket &);
 
 private:
@@ -37,11 +44,13 @@ private:
        void FlagRecv() noexcept;
 
 private:
+       ConnectionHandler *handler;
        IPaddress addr;
        IntervalTimer send_timer;
        IntervalTimer recv_timer;
 
-       Packet::TControl ctrl;
+       Packet::TControl ctrl_out;
+       Packet::TControl ctrl_in;
 
        bool closed;