HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
network_event.hpp
1// Copyright Take Vos 2022.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "../utility/module.hpp"
8#include <array>
9#include <cstddef>
10#include <cstdint>
11#include <bit>
12
13namespace hi::inline v1 {
14
15enum class network_event : uint16_t {
16 none = 0,
17 read = 0x0001,
18 write = 0x0002,
19 close = 0x0004,
20 connect = 0x0008,
21 accept = 0x0010,
22 out_of_band = 0x0020,
23 qos = 0x0040,
24 group_qos = 0x0080,
25 address_list_change = 0x0100,
26 routing_interface_changed = 0x0200
27};
28
29[[nodiscard]] constexpr network_event operator|(network_event const& lhs, network_event const& rhs) noexcept
30{
31 return static_cast<network_event>(to_underlying(lhs) | to_underlying(rhs));
32}
33
34[[nodiscard]] constexpr network_event operator&(network_event const& lhs, network_event const& rhs) noexcept
35{
36 return static_cast<network_event>(to_underlying(lhs) & to_underlying(rhs));
37}
38
39constexpr network_event& operator|=(network_event& lhs, network_event const& rhs) noexcept
40{
41 return lhs = lhs | rhs;
42}
43
44[[nodiscard]] constexpr bool to_bool(network_event const& rhs) noexcept
45{
46 return to_bool(to_underlying(rhs));
47}
48
51[[nodiscard]] constexpr size_t bit(network_event const& rhs) noexcept
52{
53 hi_assert(std::popcount(to_underlying(rhs)) == 1);
54 return std::countr_zero(to_underlying(rhs));
55}
56
57enum class network_error : uint8_t {
58 success = 0,
59 af_not_supported,
60 connection_refused,
61 network_unreachable,
62 no_buffers,
63 timeout,
64 network_down,
65 connection_reset,
66 connection_aborted
67};
68
69constexpr static size_t network_event_max = 10;
70
72public:
73 network_event events;
75
76 constexpr network_events() noexcept : events(network_event::none), errors{} {}
77};
78
79} // namespace hi::inline v1
#define hi_assert(expression,...)
Assert if expression is true.
Definition assert.hpp:199
@ read
Allow read access to a file.
@ write
Allow write access to a file.
DOXYGEN BUG.
Definition algorithm.hpp:13
constexpr size_t bit(network_event const &rhs) noexcept
Get the bit index of the single bit of the network_event mask.
Definition network_event.hpp:51
Definition network_event.hpp:71