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 
http2()39 http2::http2() : impl_(std::make_unique<http2_impl>()) {}
40 
~http2()41 http2::~http2() {}
42 
http2(http2 && other)43 http2::http2(http2 &&other) noexcept : impl_(std::move(other.impl_)) {}
44 
operator =(http2 && other)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 
listen_and_serve(boost::system::error_code & ec,const std::string & address,const std::string & port,bool asynchronous)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 
listen_and_serve(boost::system::error_code & ec,boost::asio::ssl::context & tls_context,const std::string & address,const std::string & port,bool asynchronous)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 
num_threads(size_t num_threads)68 void http2::num_threads(size_t num_threads) { impl_->num_threads(num_threads); }
69 
backlog(int backlog)70 void http2::backlog(int backlog) { impl_->backlog(backlog); }
71 
tls_handshake_timeout(const boost::posix_time::time_duration & t)72 void http2::tls_handshake_timeout(const boost::posix_time::time_duration &t) {
73   impl_->tls_handshake_timeout(t);
74 }
75 
read_timeout(const boost::posix_time::time_duration & t)76 void http2::read_timeout(const boost::posix_time::time_duration &t) {
77   impl_->read_timeout(t);
78 }
79 
handle(std::string pattern,request_cb cb)80 bool http2::handle(std::string pattern, request_cb cb) {
81   return impl_->handle(std::move(pattern), std::move(cb));
82 }
83 
stop()84 void http2::stop() { impl_->stop(); }
85 
join()86 void http2::join() { return impl_->join(); }
87 
88 const std::vector<std::shared_ptr<boost::asio::io_service>> &
io_services() const89 http2::io_services() const {
90   return impl_->io_services();
91 }
92 
ports() const93 std::vector<int> http2::ports() const { return impl_->ports(); }
94 
95 } // namespace server
96 
97 } // namespace asio_http2
98 
99 } // namespace nghttp2
100