4 #include "include/types.h"
6 #include <netinet/in.h>
7 #include "include/t4.h"
8 #include "include/rpc/poll_mgr.h"
9 #include "include/rpc/file.h"
10 #include "include/debug.h"
14 class connection_delegate {
16 virtual bool got_pdu(const shared_ptr<connection> & c, const string & b) = 0;
17 virtual ~connection_delegate();
20 using std::chrono::steady_clock;
21 using time_point = std::chrono::time_point<steady_clock>;
23 class connection : private aio_callback, public std::enable_shared_from_this<connection> {
25 connection(connection_delegate * delegate, socket_t && f1, int lossytest=0);
28 bool isdead() { return dead_; }
30 bool send(const string & b);
32 static shared_ptr<connection> to_dst(const sockaddr_in & dst, connection_delegate *mgr, int lossy=0);
34 const time_point create_time = steady_clock::now();
44 connection_delegate * delegate_;
47 enum charbuf_status_t { unused, inflight, error };
50 charbuf_status_t status;
52 size_t cursor; // number of bytes written or read so far
55 charbuf wpdu_ = {unused, "", 0};
56 charbuf rpdu_ = {unused, "", 0};
65 class connection_listener : private aio_callback {
67 connection_listener(connection_delegate * delegate, in_port_t port, int lossytest=0);
68 ~connection_listener();
69 inline in_port_t port() { return port_; }
77 socket_t tcp_; // listens for connections
78 connection_delegate * delegate_;
80 std::map<int, shared_ptr<connection>> conns_;