HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
socket_event_intf.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/utility.hpp"
8#include "../macros.hpp"
9#include <array>
10#include <cstddef>
11#include <cstdint>
12#include <bit>
13
14hi_export_module(hikogui.dispatch.socket_event : intf);
15
16hi_export namespace hi::inline v1 {
17
18enum class socket_event : uint16_t {
19 none = 0,
20 read = 0x0001,
21 write = 0x0002,
22 close = 0x0004,
23 connect = 0x0008,
24 accept = 0x0010,
25 out_of_band = 0x0020,
26 qos = 0x0040,
27 group_qos = 0x0080,
28 address_list_change = 0x0100,
29 routing_interface_changed = 0x0200
30};
31
32[[nodiscard]] constexpr socket_event operator|(socket_event const& lhs, socket_event const& rhs) noexcept
33{
34 return static_cast<socket_event>(std::to_underlying(lhs) | std::to_underlying(rhs));
35}
36
37[[nodiscard]] constexpr socket_event operator&(socket_event const& lhs, socket_event const& rhs) noexcept
38{
39 return static_cast<socket_event>(std::to_underlying(lhs) & std::to_underlying(rhs));
40}
41
42constexpr socket_event& operator|=(socket_event& lhs, socket_event const& rhs) noexcept
43{
44 return lhs = lhs | rhs;
45}
46
47[[nodiscard]] constexpr bool to_bool(socket_event const& rhs) noexcept
48{
49 return to_bool(std::to_underlying(rhs));
50}
51
54[[nodiscard]] constexpr size_t bit(socket_event const& rhs) noexcept
55{
56 hi_assert(std::popcount(std::to_underlying(rhs)) == 1);
57 return std::countr_zero(std::to_underlying(rhs));
58}
59
60enum class socket_error : uint8_t {
61 success = 0,
62 af_not_supported,
63 connection_refused,
64 network_unreachable,
65 no_buffers,
66 timeout,
67 network_down,
68 connection_reset,
69 connection_aborted
70};
71
72constexpr size_t socket_event_max = 10;
73
75public:
76 socket_event events;
78
79 constexpr socket_events() noexcept : events(socket_event::none), errors{} {}
80};
81
82} // namespace hi::inline v1
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
constexpr size_t bit(socket_event const &rhs) noexcept
Get the bit index of the single bit of the socket_event mask.
Definition socket_event_intf.hpp:54
Definition socket_event_intf.hpp:74