MySQL 8.1.0
Source Code Documentation
io_service_base.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2020, 2023, 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 also distributed 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 included with MySQL.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23*/
24
25#ifndef MYSQL_HARNESS_NET_TS_IMPL_IO_SERVICE_BASE_H_
26#define MYSQL_HARNESS_NET_TS_IMPL_IO_SERVICE_BASE_H_
27
28#include <chrono>
29#include <system_error>
30
33
34namespace net {
35enum class io_service_errc {
36 no_fds = 1,
37};
38}
39
40namespace std {
41template <>
42struct is_error_code_enum<net::io_service_errc> : public std::true_type {};
43} // namespace std
44
45namespace net {
46inline const std::error_category &io_service_category() noexcept {
47 class io_service_category_impl : public std::error_category {
48 public:
49 const char *name() const noexcept override { return "io_service"; }
50 std::string message(int ev) const override {
51 switch (static_cast<io_service_errc>(ev)) {
53 return "no file-descriptors";
54 default:
55 return "unknown";
56 }
57 }
58 };
59
60 static io_service_category_impl instance;
61 return instance;
62}
63
64inline std::error_code make_error_code(net::io_service_errc e) noexcept {
65 return {static_cast<int>(e), net::io_service_category()};
66}
67
68struct fd_event {
70
71 fd_event() = default;
72 fd_event(native_handle_type _fd, short _event) : fd{_fd}, event{_event} {}
73
75 short event{};
76};
77
78inline constexpr bool operator==(const fd_event &a, const fd_event &b) {
79 return a.event == b.event && a.fd == b.fd;
80}
81
82inline constexpr bool operator!=(const fd_event &a, const fd_event &b) {
83 return !(a == b);
84}
85
87 public:
89
90 virtual ~IoServiceBase() = default;
91
92 /**
93 * open the io-service.
94 *
95 * MUST be called before any of the other functions is called.
96 *
97 * may fail if out of file-descriptors.
98 *
99 * @returns an std::error_code on error
100 */
102
103 virtual void notify() = 0;
104
108 std::chrono::milliseconds timeout) = 0;
109
111 native_handle_type fd) = 0;
112};
113} // namespace net
114
115#endif
Definition: io_service_base.h:86
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:88
Definition: expected.h:943
static bool timeout(bool(*wait_condition)())
Timeout function.
Definition: log0meb.cc:497
wait_type
Definition: socket_constants.h:85
int native_handle_type
Definition: socket_constants.h:50
constexpr const native_handle_type kInvalidSocket
Definition: socket_constants.h:51
Definition: buffer.h:44
bool operator!=(const system_executor &, const system_executor &)
Definition: executor.h:575
io_service_errc
Definition: io_service_base.h:35
const std::error_category & io_service_category() noexcept
Definition: io_service_base.h:46
bool operator==(const system_executor &, const system_executor &)
Definition: executor.h:571
std::error_code make_error_code(net::stream_errc e) noexcept
Definition: buffer.h:102
Definition: varlen_sort.h:183
required string event
Definition: replication_group_member_actions.proto:31
case opt name
Definition: sslopt-case.h:32
Definition: io_service_base.h:68
native_handle_type fd
Definition: io_service_base.h:74
impl::socket::native_handle_type native_handle_type
Definition: io_service_base.h:69
fd_event(native_handle_type _fd, short _event)
Definition: io_service_base.h:72
fd_event()=default
short event
Definition: io_service_base.h:75