2 * nghttp2 - HTTP/2 C Library
4 * Copyright (c) 2015 Tatsuhiro Tsujikawa
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 #ifndef ASIO_CLIENT_SESSION_IMPL_H
26 #define ASIO_CLIENT_SESSION_IMPL_H
28 #include "nghttp2_config.h"
30 #include <boost/array.hpp>
32 #include <nghttp2/asio_http2_client.h>
35 namespace asio_http2 {
40 using boost::asio::ip::tcp;
44 session_impl(boost::asio::io_service &io_service);
45 virtual ~session_impl();
47 void start_resolve(const std::string &host, const std::string &service);
49 void connected(tcp::resolver::iterator endpoint_it);
50 void not_connected(const boost::system::error_code &ec);
52 void on_connect(connect_cb cb);
53 void on_error(error_cb cb);
55 const connect_cb &on_connect() const;
56 const error_cb &on_error() const;
58 int write_trailer(stream &strm, header_map h);
60 void cancel(stream &strm, uint32_t error_code);
61 void resume(stream &strm);
63 std::unique_ptr<stream> create_stream();
64 std::unique_ptr<stream> pop_stream(int32_t stream_id);
65 stream *create_push_stream(int32_t stream_id);
66 stream *find_stream(int32_t stream_id);
68 const request *submit(boost::system::error_code &ec,
69 const std::string &method, const std::string &uri,
70 generator_cb cb, header_map h);
72 virtual void start_connect(tcp::resolver::iterator endpoint_it) = 0;
73 virtual tcp::socket &socket() = 0;
74 virtual void read_socket(std::function<
75 void(const boost::system::error_code &ec, std::size_t n)> h) = 0;
76 virtual void write_socket(std::function<
77 void(const boost::system::error_code &ec, std::size_t n)> h) = 0;
78 virtual void shutdown_socket() = 0;
82 boost::asio::io_service &io_service();
86 void enter_callback();
87 void leave_callback();
93 boost::array<uint8_t, 8192> rb_;
94 boost::array<uint8_t, 65536> wb_;
98 bool should_stop() const;
100 void call_error_cb(const boost::system::error_code &ec);
102 boost::asio::io_service &io_service_;
103 tcp::resolver resolver_;
105 std::map<int32_t, std::unique_ptr<stream>> streams_;
107 connect_cb connect_cb_;
110 nghttp2_session *session_;
112 const uint8_t *data_pending_;
113 std::size_t data_pendinglen_;
116 bool inside_callback_;
119 } // namespace client
120 } // namespace asio_http2
121 } // namespace nghttp2
123 #endif // ASIO_CLIENT_SESSION_IMPL_H