Lely core libraries 2.3.4
poll.hpp
Go to the documentation of this file.
1
24#ifndef LELY_IO2_WIN32_POLL_HPP_
25#define LELY_IO2_WIN32_POLL_HPP_
26
27#include <lely/ev/poll.hpp>
28#include <lely/io2/win32/poll.h>
29#include <lely/io2/ctx.hpp>
30#include <lely/util/error.hpp>
31
32#include <utility>
33
34namespace lely {
35namespace io {
36
41class Poll {
42 public:
44 Poll(ContextBase& ctx) : poll_(io_poll_create(ctx)) {
45 if (!poll_) util::throw_errc("Poll");
46 }
47
48 Poll(const Poll&) = delete;
49
50 Poll(Poll&& other) noexcept : poll_(other.poll_) { other.poll_ = nullptr; }
51
52 Poll& operator=(const Poll&) = delete;
53
54 Poll&
55 operator=(Poll&& other) noexcept {
56 using ::std::swap;
57 swap(poll_, other.poll_);
58 return *this;
59 }
60
62 ~Poll() { io_poll_destroy(*this); }
63
64 operator io_poll_t*() const noexcept { return poll_; }
65
67 ContextBase
68 get_ctx() const noexcept {
69 return ContextBase(io_poll_get_ctx(*this));
70 }
71
74 get_poll() const noexcept {
75 return ev::Poll(io_poll_get_poll(*this));
76 }
77
79 void
80 register_handle(HANDLE handle, ::std::error_code& ec) noexcept {
81 DWORD dwErrCode = GetLastError();
82 SetLastError(0);
83 if (!io_poll_register_handle(*this, handle))
84 ec.clear();
85 else
87 SetLastError(dwErrCode);
88 }
89
91 void
92 register_handle(HANDLE handle) {
93 ::std::error_code ec;
94 register_handle(handle, ec);
95 if (ec) throw ::std::system_error(ec, "register_handle");
96 }
97
98 protected:
99 io_poll_t* poll_{nullptr};
100};
101
102} // namespace io
103} // namespace lely
104
105#endif // !LELY_IO2_WIN32_POLL_HPP_
The abstract polling interface.
Definition: poll.hpp:36
A refence to an I/O context. This class is a wrapper around #io_ctx_t*.
Definition: ctx.hpp:49
The system-dependent I/O polling interface.
Definition: poll.hpp:42
ContextBase get_ctx() const noexcept
Definition: poll.hpp:68
Poll(ContextBase &ctx)
Definition: poll.hpp:44
void register_handle(HANDLE handle, ::std::error_code &ec) noexcept
Definition: poll.hpp:80
Poll(ContextBase &ctx, int signo=0)
Definition: poll.hpp:45
void register_handle(HANDLE handle)
Definition: poll.hpp:92
ev::Poll get_poll() const noexcept
Definition: poll.hpp:74
This header file is part of the I/O library; it contains the C++ interface for the I/O context.
This header file is part of the utilities library; it contains C++ convenience functions for creating...
This header file is part of the event library; it contains the C++ interface for the abstract polling...
ev_poll_t * io_poll_get_poll(const io_poll_t *poll)
Returns a pointer to the ev_poll_t instance corresponding to the I/O polling instance.
Definition: poll.c:281
io_ctx_t * io_poll_get_ctx(const io_poll_t *poll)
Returns a pointer to the I/O context with which the I/O polling instance is registered.
Definition: poll.c:275
This header file is part of the I/O library; it contains the I/O polling declarations for Windows.
int io_poll_register_handle(io_poll_t *poll, HANDLE handle)
Registers a file handle with (the I/O completion port of) an I/O polling instance.
void io_poll_destroy(io_poll_t *poll)
Destroys an I/O polling interface.
Definition: poll.c:243
io_poll_t * io_poll_create(void)
Creates a new I/O polling interface.
Definition: poll.c:218
::std::error_code make_error_code(SdoErrc e) noexcept
Creates an error code corresponding to an SDO abort code.
Definition: sdo_error.cpp:170
An I/O polling interface.
Definition: poll.c:51