6 #include <netinet/in.h>
10 constexpr size_t size_t_max = numeric_limits<size_t>::max();
12 class thread_exit_exception : exception {};
16 class connection_delegate {
18 virtual bool got_pdu(const shared_ptr<connection> & c, const string & b) = 0;
19 virtual ~connection_delegate() {}
22 class connection : public aio_callback, public enable_shared_from_this<connection> {
26 size_t solong = 0; // number of bytes written or read so far
29 connection(connection_delegate *m1, socket_t && f1, int lossytest=0);
32 int channo() { return fd_; }
33 bool isdead() { lock ml(m_); return dead_; }
36 bool send(const string & b);
40 time_point<steady_clock> create_time() const { return create_time_; }
42 static shared_ptr<connection> to_dst(const sockaddr_in &dst, connection_delegate *mgr, int lossy=0);
49 connection_delegate *mgr_;
56 time_point<steady_clock> create_time_;
68 tcpsconn(connection_delegate *m1, in_port_t port, int lossytest=0);
70 inline in_port_t port() { return port_; }
78 socket_t tcp_; // listens for connections
79 connection_delegate *mgr_;
81 map<int, shared_ptr<connection>> conns_;
83 void process_accept();