Lely core libraries  2.2.5
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 
34 namespace lely {
35 namespace io {
36 
41 class 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 
73  ev::Poll
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
86  ec = util::make_error_code();
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_
io_poll_destroy
void io_poll_destroy(io_poll_t *poll)
Destroys an I/O polling interface.
Definition: poll.c:240
lely::io::Poll::get_ctx
ContextBase get_ctx() const noexcept
Definition: poll.hpp:68
lely::io::Poll::Poll
Poll(ContextBase &ctx, int signo=0)
Definition: poll.hpp:45
poll.h
io_poll_get_poll
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
lely::io::ContextBase
A refence to an I/O context. This class is a wrapper around #io_ctx_t*.
Definition: ctx.hpp:49
lely::io::Poll::~Poll
~Poll()
Definition: poll.hpp:62
lely::io::Poll::get_poll
ev::Poll get_poll() const noexcept
Definition: poll.hpp:74
ctx.hpp
poll.hpp
__io_poll
An I/O polling interface.
Definition: poll.c:48
lely::io::Poll::Poll
Poll(ContextBase &ctx)
Definition: poll.hpp:44
io_poll_get_ctx
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
lely::io::Poll
The system-dependent I/O polling interface.
Definition: poll.hpp:42
io_poll_register_handle
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.
lely::ev::Poll
The abstract polling interface.
Definition: poll.hpp:36
lely::io::Poll::register_handle
void register_handle(HANDLE handle, ::std::error_code &ec) noexcept
Definition: poll.hpp:80
io_poll_create
io_poll_t * io_poll_create(void)
Creates a new I/O polling interface.
Definition: poll.c:215
lely::canopen::make_error_code
::std::error_code make_error_code(SdoErrc e) noexcept
Creates an error code corresponding to an SDO abort code.
Definition: sdo_error.cpp:170
lely::io::Poll::register_handle
void register_handle(HANDLE handle)
Definition: poll.hpp:92
error.hpp