@@ -29,29 +29,30 @@ namespace http {
2929
3030 class Connection {
3131 public:
32- using TCP_conn = net::tcp::Connection_ptr;
32+ using Stream = net::tcp::Connection::Stream;
33+ using Stream_ptr = std::unique_ptr<Stream>;
3334 using Peer = net::tcp::Socket;
3435 using buffer_t = net::tcp::buffer_t ;
3536
3637 public:
37- inline explicit Connection (TCP_conn tcpconn , bool keep_alive = true );
38+ inline explicit Connection (Stream_ptr stream , bool keep_alive = true );
3839
3940 template <typename TCP>
4041 explicit Connection (TCP&, Peer);
4142
4243 inline explicit Connection () noexcept ;
4344
4445 net::tcp::port_t local_port () const noexcept
45- { return (tcpconn_ ) ? tcpconn_ ->local_port () : 0 ; }
46+ { return (stream_ ) ? stream_ ->local_port () : 0 ; }
4647
4748 Peer peer () const noexcept
4849 { return peer_; }
4950
5051 void timeout ()
51- { tcpconn_ ->is_closing () ? tcpconn_ ->abort () : tcpconn_ ->close (); }
52+ { stream_ ->is_closing () ? stream_ ->abort () : stream_ ->close (); }
5253
53- auto && tcp () const
54- { return tcpconn_ ; }
54+ auto & stream () const
55+ { return stream_ ; }
5556
5657 /* *
5758 * @brief Shutdown the underlying TCP connection
@@ -64,15 +65,15 @@ namespace http {
6465 *
6566 * @return The underlying TCP connection
6667 */
67- inline TCP_conn release ();
68+ inline Stream_ptr release ();
6869
6970 /* *
7071 * @brief Whether the underlying TCP connection has been released or not
7172 *
7273 * @return true if the underlying TCP connection is released
7374 */
7475 bool released () const
75- { return tcpconn_ == nullptr ; }
76+ { return stream_ == nullptr ; }
7677
7778 static Connection& empty () noexcept
7879 {
@@ -101,52 +102,50 @@ namespace http {
101102 virtual ~Connection () {}
102103
103104 protected:
104- TCP_conn tcpconn_ ;
105+ Stream_ptr stream_ ;
105106 bool keep_alive_;
106107 Peer peer_;
107108
108109 virtual void close () {}
109110
110111 }; // < class Connection
111112
112- inline Connection::Connection (TCP_conn tcpconn , bool keep_alive)
113- : tcpconn_ {std::move (tcpconn )},
113+ inline Connection::Connection (Stream_ptr stream , bool keep_alive)
114+ : stream_ {std::move (stream )},
114115 keep_alive_{keep_alive},
115- peer_{tcpconn_ ->remote ()}
116+ peer_{stream_ ->remote ()}
116117 {
117- Ensures (tcpconn_ != nullptr );
118+ Ensures (stream_ != nullptr );
118119 debug (" <http::Connection> Created %u -> %s %p\n " , local_port (), peer ().to_string ().c_str (), this );
119120 }
120121
121122 template <typename TCP>
122123 Connection::Connection (TCP& tcp, Peer addr)
123- : Connection(tcp.connect(addr))
124+ : Connection(std::make_unique<Stream>( tcp.connect(addr) ))
124125 {
125126 }
126127
127128 inline Connection::Connection () noexcept
128- : tcpconn_ (nullptr ),
129+ : stream_ (nullptr ),
129130 keep_alive_(false ),
130131 peer_{}
131132 {
132133 }
133134
134135 inline void Connection::shutdown ()
135136 {
136- if (not released () and not tcpconn_ ->is_closing ())
137- tcpconn_ ->close ();
137+ if (not released () and not stream_ ->is_closing ())
138+ stream_ ->close ();
138139 }
139140
140- inline Connection::TCP_conn Connection::release ()
141+ inline Connection::Stream_ptr Connection::release ()
141142 {
142- auto copy = tcpconn_ ;
143+ auto copy = std::move (stream_) ;
143144
144145 // this is expensive and may be unecessary,
145146 // but just to be safe for now
146147 copy->reset_callbacks ();
147148
148- tcpconn_ = nullptr ;
149-
150149 return copy;
151150 }
152151
0 commit comments