MySQL 8.4.2
Source Code Documentation
poll.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2019, 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_POLL_H_
27#define MYSQL_HARNESS_NET_TS_IMPL_POLL_H_
28
29#include <array>
30#include <chrono>
31#include <system_error>
32
33#ifdef _WIN32
34#include <WinSock2.h>
35#include <Windows.h>
36#else
37#include <poll.h> // poll
38#endif
39
42
43namespace net {
44namespace impl {
45namespace poll {
46
47#ifdef _WIN32
48using poll_fd = WSAPOLLFD;
49#else
51#endif
52
54 poll_fd *fds, size_t num_fds, std::chrono::milliseconds timeout) {
55#ifdef _WIN32
56 constexpr const auto err_res{SOCKET_ERROR};
57 auto res = ::WSAPoll(fds, num_fds, timeout.count());
58#else
59 constexpr const auto err_res{-1};
60 auto res = ::poll(fds, num_fds, timeout.count());
61#endif
62
63 if (res == err_res) {
65 }
66 if (0 == res) {
67 return stdx::unexpected(make_error_code(std::errc::timed_out));
68 }
69
70 return res;
71}
72} // namespace poll
73} // namespace impl
74} // namespace net
75
76#endif
Definition: http_server_component.cc:34
static bool timeout(bool(*wait_condition)())
Timeout function.
Definition: log0meb.cc:498
pollfd poll_fd
Definition: poll.h:50
stdx::expected< size_t, std::error_code > poll(poll_fd *fds, size_t num_fds, std::chrono::milliseconds timeout)
Definition: poll.h:53
std::error_code last_error_code()
get last std::error_code for socket-errors.
Definition: socket_error.h:107
Definition: buffer.h:45
std::error_code make_error_code(net::stream_errc e) noexcept
Definition: buffer.h:103
unexpected(E) -> unexpected< E >
struct pollfd pollfd
Definition: task_os.h:114
#define SOCKET_ERROR
Definition: x_platform.h:284