Nexus HTTP/3
A QUIC and HTTP/3 library
server.hpp
1 #pragma once
2 
3 #include <nexus/udp.hpp>
4 #include <nexus/ssl.hpp>
5 #include <nexus/quic/server.hpp>
6 
7 namespace nexus::h3 {
8 
9 class acceptor;
10 class server_connection;
11 class stream;
12 
15 class server {
16  friend class acceptor;
17  quic::detail::engine_impl engine;
18  public:
20  using executor_type = quic::detail::engine_impl::executor_type;
21 
23  explicit server(const executor_type& ex);
24 
26  server(const executor_type& ex, const quic::settings& s);
27 
30 
34  void close();
35 };
36 
39 class acceptor {
40  friend class server_connection;
41  quic::detail::socket_impl impl;
42  public:
44  using executor_type = quic::detail::socket_impl::executor_type;
45 
47  acceptor(server& s, udp::socket&& socket, ssl::context& ctx);
48 
50  acceptor(server& s, const udp::endpoint& endpoint, ssl::context& ctx);
51 
54 
56  udp::endpoint local_endpoint() const;
57 
61  void listen(int backlog);
62 
65  template <typename CompletionToken> // void(error_code)
66  decltype(auto) async_accept(server_connection& conn,
67  CompletionToken&& token) {
68  return impl.async_accept(conn, std::forward<CompletionToken>(token));
69  }
70 
73  void accept(server_connection& conn, error_code& ec);
76 
78  void close();
79 };
80 
84  friend class acceptor;
85  friend class stream;
86  friend class quic::detail::socket_impl;
87  quic::detail::connection_impl impl;
88  public:
90  using executor_type = quic::detail::connection_impl::executor_type;
91 
93  explicit server_connection(acceptor& a) : impl(a.impl) {}
94 
97 
99  bool is_open() const;
100 
102  quic::connection_id id(error_code& ec) const;
105 
107  udp::endpoint remote_endpoint(error_code& ec) const;
109  udp::endpoint remote_endpoint() const;
110 
112  template <typename CompletionToken> // void(error_code)
113  decltype(auto) async_accept(stream& s, CompletionToken&& token) {
114  return impl.async_accept<stream>(s, std::forward<CompletionToken>(token));
115  }
117  void accept(stream& s, error_code& ec);
119  void accept(stream& s);
120 
121  // TODO: push stream
122 
124  void go_away(error_code& ec);
126  void go_away();
127 
129  void close(error_code& ec);
131  void close();
132 };
133 
134 } // namespace nexus::h3
an HTTP/3 acceptor that owns a UDP socket and uses it to accept and service incoming connections
Definition: server.hpp:39
udp::endpoint local_endpoint() const
return the socket's locally-bound address/port
executor_type get_executor() const
return the associated io executor
quic::detail::socket_impl::executor_type executor_type
the polymorphic executor type, boost::asio::any_io_executor
Definition: server.hpp:44
void accept(server_connection &conn, error_code &ec)
accept an incoming connection whose TLS handshake has completed successfully
acceptor(server &s, udp::socket &&socket, ssl::context &ctx)
construct the acceptor, taking ownership of a bound UDP socket
void close()
close the socket, along with any related connections
acceptor(server &s, const udp::endpoint &endpoint, ssl::context &ctx)
construct the acceptor and bind a UDP socket to the given endpoint
decltype(auto) async_accept(server_connection &conn, CompletionToken &&token)
accept an incoming connection whose TLS handshake has completed successfully
Definition: server.hpp:66
void accept(server_connection &conn)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void listen(int backlog)
start receiving packets on the socket. incoming connections can be accepted with accept()/async_accep...
an HTTP/3 connection that can accept incoming streams and push associated outgoing streams
Definition: server.hpp:83
executor_type get_executor() const
return the associated io executor
quic::detail::connection_impl::executor_type executor_type
the polymorphic executor type, boost::asio::any_io_executor
Definition: server.hpp:90
void go_away(error_code &ec)
send a GOAWAY frame and stop initiating or accepting new streams
void accept(stream &s, error_code &ec)
This is an overloaded member function, provided for convenience. It differs from the above function o...
quic::connection_id id() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
decltype(auto) async_accept(stream &s, CompletionToken &&token)
accept an incoming stream
Definition: server.hpp:113
udp::endpoint remote_endpoint(error_code &ec) const
return the remote's address/port if open
void close(error_code &ec)
close the connection, along with any related streams
void go_away()
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool is_open() const
determine whether the connection is open
server_connection(acceptor &a)
construct a server-side connection for use with accept()
Definition: server.hpp:93
void close()
This is an overloaded member function, provided for convenience. It differs from the above function o...
void accept(stream &s)
This is an overloaded member function, provided for convenience. It differs from the above function o...
quic::connection_id id(error_code &ec) const
return the connection id if open
udp::endpoint remote_endpoint() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
an HTTP/3 server capable of managing one or more UDP sockets via class acceptor
Definition: server.hpp:15
executor_type get_executor() const
return the associated io executor
server(const executor_type &ex)
construct the server with its associated executor
quic::detail::engine_impl::executor_type executor_type
the polymorphic executor type, boost::asio::any_io_executor
Definition: server.hpp:20
void close()
stop accepting new connections and streams entirely, and mark existing connections as 'going away'....
server(const executor_type &ex, const quic::settings &s)
construct the server with its associated executor and transport settings
a bidirectional HTTP/3 stream that can send and receive HTTP headers, and meets the type requirements...
Definition: stream.hpp:14
an opaque connection id string
Definition: connection_id.hpp:12
HTTP/3 library.
Definition: client.hpp:6
quic transport settings used to initialize a client or server
Definition: settings.hpp:16