Nexus HTTP/3
A QUIC and HTTP/3 library
engine_impl.hpp
1 #pragma once
2 
3 #include <memory>
4 #include <mutex>
5 
6 #include <boost/asio/steady_timer.hpp>
7 
8 #include <nexus/quic/settings.hpp>
9 
10 struct lsquic_engine;
11 struct lsquic_conn;
12 struct lsquic_stream;
13 struct lsquic_out_spec;
14 
15 namespace nexus::quic::detail {
16 
17 struct connection_impl;
18 struct stream_impl;
19 struct socket_impl;
20 
21 struct engine_deleter { void operator()(lsquic_engine* e) const; };
22 using lsquic_engine_ptr = std::unique_ptr<lsquic_engine, engine_deleter>;
23 
24 struct engine_impl {
25  mutable std::mutex mutex;
26  boost::asio::any_io_executor ex;
27  boost::asio::steady_timer timer;
28  lsquic_engine_ptr handle;
29  // pointer to client socket or null if server
30  socket_impl* client;
31  uint32_t max_streams_per_connection;
32  bool is_http;
33 
34  void process(std::unique_lock<std::mutex>& lock);
35  void reschedule(std::unique_lock<std::mutex>& lock);
36  void on_timer();
37 
38  engine_impl(const boost::asio::any_io_executor& ex, socket_impl* client,
39  const settings* s, unsigned flags);
40  ~engine_impl();
41 
42  using executor_type = boost::asio::any_io_executor;
43  executor_type get_executor() const { return ex; }
44 
45  void close();
46 
47  int send_packets(const lsquic_out_spec *specs, unsigned n_specs);
48 
49  stream_impl* on_new_stream(connection_impl& c, lsquic_stream* stream);
50 };
51 
52 } // namespace nexus::quic::detail