Imported Upstream version 1.0.0
[platform/upstream/nghttp2.git] / src / asio_client_session.cc
1 /*
2  * nghttp2 - HTTP/2 C Library
3  *
4  * Copyright (c) 2015 Tatsuhiro Tsujikawa
5  *
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:
13  *
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
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.
24  */
25 #include "nghttp2_config.h"
26
27 #include <nghttp2/asio_http2_client.h>
28
29 #include "asio_client_session_tcp_impl.h"
30 #include "asio_client_session_tls_impl.h"
31 #include "asio_common.h"
32 #include "template.h"
33
34 namespace nghttp2 {
35 namespace asio_http2 {
36 namespace client {
37
38 using boost::asio::ip::tcp;
39
40 session::session(boost::asio::io_service &io_service, const std::string &host,
41                  const std::string &service)
42     : impl_(make_unique<session_tcp_impl>(io_service, host, service)) {}
43
44 session::session(boost::asio::io_service &io_service,
45                  boost::asio::ssl::context &tls_ctx, const std::string &host,
46                  const std::string &service)
47     : impl_(make_unique<session_tls_impl>(io_service, tls_ctx, host, service)) {
48 }
49
50 session::~session() {}
51
52 session::session(session &&other) noexcept : impl_(std::move(other.impl_)) {}
53
54 session &session::operator=(session &&other) noexcept {
55   if (this == &other) {
56     return *this;
57   }
58
59   impl_ = std::move(other.impl_);
60   return *this;
61 }
62
63 void session::on_connect(connect_cb cb) const {
64   impl_->on_connect(std::move(cb));
65 }
66
67 void session::on_error(error_cb cb) const { impl_->on_error(std::move(cb)); }
68
69 void session::shutdown() const { impl_->shutdown(); }
70
71 boost::asio::io_service &session::io_service() const {
72   return impl_->io_service();
73 }
74
75 const request *session::submit(boost::system::error_code &ec,
76                                const std::string &method,
77                                const std::string &uri, header_map h) const {
78   return impl_->submit(ec, method, uri, generator_cb(), std::move(h));
79 }
80
81 const request *session::submit(boost::system::error_code &ec,
82                                const std::string &method,
83                                const std::string &uri, std::string data,
84                                header_map h) const {
85   return impl_->submit(ec, method, uri, string_generator(std::move(data)),
86                        std::move(h));
87 }
88
89 const request *session::submit(boost::system::error_code &ec,
90                                const std::string &method,
91                                const std::string &uri, generator_cb cb,
92                                header_map h) const {
93   return impl_->submit(ec, method, uri, std::move(cb), std::move(h));
94 }
95
96 } // namespace client
97 } // namespace asio_http2
98 } // nghttp2