Nexus HTTP/3
A QUIC and HTTP/3 library
context.hpp
1 #pragma once
2 
3 #include <utility>
4 
5 #include <nexus/global/error.hpp>
6 
7 namespace nexus::global {
8 
9 class context;
10 
11 namespace detail {
12 
13 context init(int flags, error_code& ec);
14 
15 } // namespace detail
16 
19 class context {
20  friend context detail::init(int flags, error_code& ec);
21  using cleanup_fn = void (*)();
22  cleanup_fn cleanup;
23  context(cleanup_fn cleanup) noexcept : cleanup(cleanup) {}
24  public:
26  context() noexcept : cleanup(nullptr) {}
28  context(context&& o) noexcept : cleanup(std::exchange(o.cleanup, nullptr)) {}
30  context& operator=(context&& o) noexcept {
31  std::swap(cleanup, o.cleanup);
32  return *this;
33  }
36  if (cleanup) {
37  shutdown();
38  }
39  }
40 
42  operator bool() const { return cleanup; }
43 
46  void log_to_stderr(const char* level);
47 
49  void shutdown() {
50  cleanup();
51  }
52 };
53 
54 } // namespace nexus::global
a context object representing the global initialization of the nexus QUIC/HTTP library,...
Definition: context.hpp:19
void shutdown()
perform global shutdown of an initialized context
Definition: context.hpp:49
context & operator=(context &&o) noexcept
move assign, swapping ownership with another context
Definition: context.hpp:30
void log_to_stderr(const char *level)
enable log output to stderr, where the log level is one of: emerg, alert, crit, error,...
~context()
perform global shutdown if initialized
Definition: context.hpp:35
context() noexcept
construct an uninitialized context
Definition: context.hpp:26
context(context &&o) noexcept
move construct, claiming ownership of another context's cleanup
Definition: context.hpp:28
global initialization
Definition: context.hpp:7