MySQL 9.0.0
Source Code Documentation
io_service_base.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2020, 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef MYSQL_HARNESS_NET_TS_IMPL_IO_SERVICE_BASE_H_
27#define MYSQL_HARNESS_NET_TS_IMPL_IO_SERVICE_BASE_H_
28
29#include <chrono>
30#include <system_error>
31
34
35namespace net {
36enum class io_service_errc {
37 no_fds = 1,
38};
39}
40
41namespace std {
42template <>
43struct is_error_code_enum<net::io_service_errc> : public std::true_type {};
44} // namespace std
45
46namespace net {
47inline const std::error_category &io_service_category() noexcept {
48 class io_service_category_impl : public std::error_category {
49 public:
50 const char *name() const noexcept override { return "io_service"; }
51 std::string message(int ev) const override {
52 switch (static_cast<io_service_errc>(ev)) {
54 return "no file-descriptors";
55 default:
56 return "unknown";
57 }
58 }
59 };
60
61 static io_service_category_impl instance;
62 return instance;
63}
64
65inline std::error_code make_error_code(net::io_service_errc e) noexcept {
66 return {static_cast<int>(e), net::io_service_category()};
67}
68
69struct fd_event {
71
72 fd_event() = default;
73 fd_event(native_handle_type _fd, short _event) : fd{_fd}, event{_event} {}
74
76 short event{};
77};
78
79inline constexpr bool operator==(const fd_event &a, const fd_event &b) {
80 return a.event == b.event && a.fd == b.fd;
81}
82
83inline constexpr bool operator!=(const fd_event &a, const fd_event &b) {
84 return !(a == b);
85}
86
88 public:
90
91 virtual ~IoServiceBase() = default;
92
93 /**
94 * open the io-service.
95 *
96 * MUST be called before any of the other functions is called.
97 *
98 * may fail if out of file-descriptors.
99 *
100 * @returns an std::error_code on error
101 */
103
104 virtual void notify() = 0;
105
109 std::chrono::milliseconds timeout) = 0;
110
112 native_handle_type fd) = 0;
113};
114} // namespace net
115
116#endif
Definition: io_service_base.h:87
virtual void notify()=0
virtual ~IoServiceBase()=default
virtual stdx::expected< void, std::error_code > add_fd_interest(native_handle_type fd, impl::socket::wait_type event)=0
virtual stdx::expected< fd_event, std::error_code > poll_one(std::chrono::milliseconds timeout)=0
virtual stdx::expected< void, std::error_code > remove_fd(native_handle_type fd)=0
virtual stdx::expected< void, std::error_code > open()=0
open the io-service.
impl::socket::native_handle_type native_handle_type
Definition: io_service_base.h:89
Definition: expected.h:284
static bool timeout(bool(*wait_condition)())
Timeout function.
Definition: log0meb.cc:498
wait_type
Definition: socket_constants.h:86
int native_handle_type
Definition: socket_constants.h:51
constexpr const native_handle_type kInvalidSocket
Definition: socket_constants.h:52
Definition: buffer.h:45
bool operator!=(const system_executor &, const system_executor &)
Definition: executor.h:559
io_service_errc
Definition: io_service_base.h:36
const std::error_category & io_service_category() noexcept
Definition: io_service_base.h:47
bool operator==(const system_executor &, const system_executor &)
Definition: executor.h:555
std::error_code make_error_code(net::stream_errc e) noexcept
Definition: buffer.h:103
Definition: gcs_xcom_synode.h:64
required string event
Definition: replication_group_member_actions.proto:32
case opt name
Definition: sslopt-case.h:29
Definition: io_service_base.h:69
native_handle_type fd
Definition: io_service_base.h:75
impl::socket::native_handle_type native_handle_type
Definition: io_service_base.h:70
fd_event(native_handle_type _fd, short _event)
Definition: io_service_base.h:73
fd_event()=default
short event
Definition: io_service_base.h:76