Imported Upstream version 1.0.0
[platform/upstream/nghttp2.git] / src / asio_server_http2.cc
1 /*
2  * nghttp2 - HTTP/2 C Library
3  *
4  * Copyright (c) 2014 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_server.h>
28
29 #include "asio_server_http2_impl.h"
30 #include "asio_server.h"
31 #include "template.h"
32
33 namespace nghttp2 {
34
35 namespace asio_http2 {
36
37 namespace server {
38
39 http2::http2() : impl_(make_unique<http2_impl>()) {}
40
41 http2::~http2() {}
42
43 http2::http2(http2 &&other) noexcept : impl_(std::move(other.impl_)) {}
44
45 http2 &http2::operator=(http2 &&other) noexcept {
46   if (this == &other) {
47     return *this;
48   }
49
50   impl_ = std::move(other.impl_);
51
52   return *this;
53 }
54
55 boost::system::error_code http2::listen_and_serve(boost::system::error_code &ec,
56                                                   const std::string &address,
57                                                   const std::string &port,
58                                                   bool asynchronous) {
59   return impl_->listen_and_serve(ec, nullptr, address, port, asynchronous);
60 }
61
62 boost::system::error_code http2::listen_and_serve(
63     boost::system::error_code &ec, boost::asio::ssl::context &tls_context,
64     const std::string &address, const std::string &port, bool asynchronous) {
65   return impl_->listen_and_serve(ec, &tls_context, address, port, asynchronous);
66 }
67
68 void http2::num_threads(size_t num_threads) { impl_->num_threads(num_threads); }
69
70 void http2::backlog(int backlog) { impl_->backlog(backlog); }
71
72 bool http2::handle(std::string pattern, request_cb cb) {
73   return impl_->handle(std::move(pattern), std::move(cb));
74 }
75
76 void http2::stop() { impl_->stop(); }
77
78 void http2::join() { return impl_->join(); }
79
80 } // namespace server
81
82 } // namespace asio_http2
83
84 } // namespace nghttp2