26#ifndef MYSQL_HARNESS_NET_TS_IMPL_POLL_IO_SERVICE_H_
27#define MYSQL_HARNESS_NET_TS_IMPL_POLL_IO_SERVICE_H_
33#include <system_error>
86 auto non_block_wakeup_0_res =
88 if (!non_block_wakeup_0_res)
return non_block_wakeup_0_res;
89 auto non_block_wakeup_1_res =
91 if (!non_block_wakeup_1_res)
return non_block_wakeup_1_res;
120 return POLLERR | POLLHUP;
145 std::lock_guard<std::mutex> lk(
mtx_);
147 auto it =
std::find_if(b.begin(), b.end(), [fd = t.fd](
auto fd_ev) {
148 return fd_ev.fd == fd;
151 b.push_back(std::move(t));
153 it->event |= t.event;
160 std::lock_guard<std::mutex> lk(
mtx_);
161 const auto end = b.end();
163 for (
auto cur = b.begin(); cur != end;) {
179 std::vector<pollfd> fds;
181 std::lock_guard<std::mutex> lk(
mtx_);
192 for (
auto const &fd_int : b) {
193 if (fd_int.event != 0) {
196 static_cast<short>(fd_int.event & ~kAlwaysEnabledEvents),
210 std::lock_guard<std::mutex> lk(
mtx_);
212 [fd](
auto fd_ev) { return fd_ev.fd == fd; });
226 std::lock_guard<std::mutex> lk(
mtx_);
228 for (
auto const &fd_ev : b) {
229 if (fd_ev.fd == fd)
return fd_ev.event;
263 std::array<container_type, bucket_count_>
buckets_;
289 std::lock_guard<std::mutex> lk(
mtx_);
325 if (head.event & POLLOUT) {
326 head.event &= ~POLLOUT;
328 }
else if (head.event & POLLIN) {
330 if (head.event & POLLHUP) head.event &= ~POLLHUP;
332 head.event &= ~POLLIN;
334 }
else if (head.event & POLLERR) {
335 head.event &= ~POLLERR;
337 }
else if (head.event & POLLHUP) {
338 head.event &= ~POLLHUP;
342 if ((head.event & (POLLIN | POLLOUT | POLLERR | POLLHUP)) == 0) {
350 std::chrono::milliseconds
timeout) {
357 size_t num_revents = res.value();
360 std::lock_guard lk(
mtx_);
362 for (
auto ev : poll_fds) {
363 if (ev.revents != 0) {
389 ((ev.events & (POLLIN | POLLOUT)) &&
390 ((ev.revents & (POLLIN | POLLOUT | POLLHUP)) == POLLHUP))
391 ? ev.revents | (ev.events & (POLLIN | POLLOUT))
403 if (0 == num_revents)
break;
410 std::chrono::milliseconds
timeout)
override {
416 std::lock_guard<std::mutex> lk(
mtx_);
428 if (ev_res.error() == std::errc::no_such_file_or_directory) {
448 std::array<uint8_t, 256>
buf;
462 std::array<uint8_t, 1>
buf = {{
'.'}};
483 std::pair<impl::socket::native_handle_type, impl::socket::native_handle_type>
Definition: io_service_base.h:87
impl::socket::native_handle_type native_handle_type
Definition: io_service_base.h:89
Definition: poll_io_service.h:130
stdx::expected< void, std::error_code > erase_fd_event(native_handle_type fd, short event)
Definition: poll_io_service.h:206
std::vector< pollfd > poll_fds() const
Definition: poll_io_service.h:178
std::vector< element_type > container_type
Definition: poll_io_service.h:140
static constexpr const size_t bucket_count_
Definition: poll_io_service.h:260
std::array< container_type, bucket_count_ > buckets_
Definition: poll_io_service.h:263
const container_type & bucket(native_handle_type fd) const
Definition: poll_io_service.h:242
stdx::expected< void, std::error_code > erase_all(native_handle_type fd)
Definition: poll_io_service.h:157
std::mutex mtx_
Definition: poll_io_service.h:262
std::optional< int32_t > interest(native_handle_type fd) const
Definition: poll_io_service.h:223
void push_back(element_type &&t)
Definition: poll_io_service.h:142
container_type & bucket(native_handle_type fd)
Definition: poll_io_service.h:236
io_service based on the poll() system-call.
Definition: poll_io_service.h:52
~poll_io_service() override
Definition: poll_io_service.h:54
stdx::expected< void, std::error_code > remove_fd_interest(native_handle_type fd, short event)
remove interest of event from fd.
Definition: poll_io_service.h:473
static stdx::expected< short, std::error_code > poll_event_from_wait_type(impl::socket::wait_type event)
Definition: poll_io_service.h:112
stdx::expected< fd_event, std::error_code > update_fd_events(std::chrono::milliseconds timeout)
Definition: poll_io_service.h:349
FdInterests fd_interests_
Definition: poll_io_service.h:486
stdx::expected< void, std::error_code > add_fd_interest(native_handle_type fd, impl::socket::wait_type event) override
Definition: poll_io_service.h:266
bool is_open() const noexcept
Definition: poll_io_service.h:61
static constexpr const short kAlwaysEnabledEvents
Definition: poll_io_service.h:57
std::optional< int32_t > interest(native_handle_type fd) const
get current fd-interest.
Definition: poll_io_service.h:313
static constexpr const short kAllEvents
Definition: poll_io_service.h:58
std::mutex mtx_
Definition: poll_io_service.h:491
void notify() override
Definition: poll_io_service.h:456
std::list< fd_event > triggered_events_
Definition: poll_io_service.h:488
stdx::expected< fd_event, std::error_code > poll_one(std::chrono::milliseconds timeout) override
Definition: poll_io_service.h:409
stdx::expected< fd_event, std::error_code > pop_event()
Definition: poll_io_service.h:317
stdx::expected< void, std::error_code > close()
Definition: poll_io_service.h:98
static constexpr const short kSettableEvents
Definition: poll_io_service.h:56
std::pair< impl::socket::native_handle_type, impl::socket::native_handle_type > wakeup_fds_
Definition: poll_io_service.h:484
stdx::expected< void, std::error_code > remove_fd(native_handle_type fd) override
remove fd from interest set.
Definition: poll_io_service.h:283
void on_notify()
Definition: poll_io_service.h:445
stdx::expected< void, std::error_code > open() noexcept override
open the io-service.
Definition: poll_io_service.h:66
Definition: expected.h:286
constexpr const error_type & error() const &
Definition: expected.h:760
Definition: expected.h:112
static char buf[MAX_BUF]
Definition: conf_to_src.cc:73
static int count
Definition: myisam_ftdump.cc:45
static bool interrupted
Definition: mysqladmin.cc:72
Definition: buf0block_hint.cc:30
Container::const_iterator find_if(const Container &c, Find_if &&find_if)
Definition: generic.h:54
static bool timeout(bool(*wait_condition)())
Timeout function.
Definition: log0meb.cc:498
stdx::expected< size_t, std::error_code > poll(poll_fd *fds, size_t num_fds, std::chrono::milliseconds timeout)
Definition: poll.h:53
stdx::expected< std::pair< native_handle_type, native_handle_type >, error_type > socketpair(int family, int sock_type, int protocol)
socketpair().
Definition: socket.h:452
stdx::expected< size_t, error_type > send(native_handle_type native_handle, const void *buf, size_t buf_len, message_flags flags)
wrap send() in a portable way.
Definition: socket.h:273
stdx::expected< size_t, error_type > recv(native_handle_type native_handle, void *buf, size_t buf_len, message_flags flags)
wrap recv() in a portable way.
Definition: socket.h:199
stdx::expected< void, std::error_code > close(native_handle_type native_handle)
Definition: socket.h:75
wait_type
Definition: socket_constants.h:86
stdx::expected< bool, error_type > native_non_blocking(native_handle_type native_handle)
Definition: socket.h:106
constexpr const native_handle_type kInvalidSocket
Definition: socket_constants.h:52
std::error_condition make_error_condition(net::stream_errc e) noexcept
Definition: buffer.h:107
std::error_code make_error_code(net::stream_errc e) noexcept
Definition: buffer.h:103
unexpected(E) -> unexpected< E >
required string event
Definition: replication_group_member_actions.proto:32
Definition: io_service_base.h:69
native_handle_type fd
Definition: io_service_base.h:75
short event
Definition: io_service_base.h:76