Nexus HTTP/3
A QUIC and HTTP/3 library
connection.hpp
1 #pragma once
2 
3 #include <nexus/quic/connection_id.hpp>
4 #include <nexus/quic/detail/connection_impl.hpp>
5 
6 namespace nexus::quic {
7 
8 class acceptor;
9 class client;
10 class stream;
11 
14 class connection {
15  friend class acceptor;
16  friend class client;
17  friend class stream;
18  friend class detail::socket_impl;
19  detail::connection_impl impl;
20  public:
22  using executor_type = detail::connection_impl::executor_type;
23 
25  explicit connection(acceptor& a);
26 
28  explicit connection(client& c);
29 
33  connection(client& c, const udp::endpoint& endpoint, const char* hostname);
34 
37 
39  bool is_open() const;
40 
42  connection_id id(error_code& ec) const;
44  connection_id id() const;
45 
47  udp::endpoint remote_endpoint(error_code& ec) const;
49  udp::endpoint remote_endpoint() const;
50 
52  template <typename CompletionToken> // void(error_code, stream)
53  decltype(auto) async_connect(stream& s, CompletionToken&& token) {
54  return impl.async_connect<stream>(s, std::forward<CompletionToken>(token));
55  }
57  void connect(stream& s, error_code& ec);
59  void connect(stream& s);
60 
62  template <typename CompletionToken> // void(error_code, stream)
63  decltype(auto) async_accept(stream& s, CompletionToken&& token) {
64  return impl.async_accept<stream>(s, std::forward<CompletionToken>(token));
65  }
67  void accept(stream& s, error_code& ec);
69  void accept(stream& s);
70 
72  void go_away(error_code& ec);
74  void go_away();
75 
77  void close(error_code& ec);
79  void close();
80 };
81 
82 } // namespace nexus::quic
a generic QUIC acceptor that owns a UDP socket and uses it to accept and service incoming connections
Definition: server.hpp:39
a generic QUIC client that owns a UDP socket and uses it to service client connections
Definition: client.hpp:15
an opaque connection id string
Definition: connection_id.hpp:12
a generic QUIC connection that can initiate outgoing streams and accept incoming streams
Definition: connection.hpp:14
decltype(auto) async_connect(stream &s, CompletionToken &&token)
open an outgoing stream
Definition: connection.hpp:53
connection(acceptor &a)
construct a server-side connection for use with accept()
void connect(stream &s)
This is an overloaded member function, provided for convenience. It differs from the above function o...
connection_id id() const
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...
void go_away()
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: connection.hpp:63
udp::endpoint remote_endpoint(error_code &ec) const
return the remote's address/port if open
void connect(stream &s, error_code &ec)
This is an overloaded member function, provided for convenience. It differs from the above function o...
connection(client &c)
construct a client-side connection for use with connect()
void close(error_code &ec)
close the connection, along with any related streams
void close()
This is an overloaded member function, provided for convenience. It differs from the above function o...
detail::connection_impl::executor_type executor_type
the polymorphic executor type, boost::asio::any_io_executor
Definition: connection.hpp:22
connection_id id(error_code &ec) const
return the connection id if open
connection(client &c, const udp::endpoint &endpoint, const char *hostname)
open a connection to the given remote endpoint and hostname. this initiates the TLS handshake,...
void go_away(error_code &ec)
stop initiating or accepting new streams
executor_type get_executor() const
return the associated io executor
udp::endpoint remote_endpoint() const
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
void accept(stream &s, error_code &ec)
This is an overloaded member function, provided for convenience. It differs from the above function o...
a generic bidirectional QUIC stream that meets the type requirements of asio's AsyncRead/WriteStream ...
Definition: stream.hpp:21
Generic QUIC library.
Definition: client.hpp:8