userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
poller.hpp
Go to the documentation of this file.
1
#pragma once
2
5
6
#include <unordered_map>
7
8
#include <
userver/concurrent/mpsc_queue.hpp
>
9
#include <
userver/engine/deadline.hpp
>
10
#include <
userver/engine/io/common.hpp
>
11
#include <
userver/utils/fast_pimpl.hpp
>
12
#include <
userver/utils/flags.hpp
>
13
14
USERVER_NAMESPACE_BEGIN
15
16
namespace
engine::io
{
17
22
class
Poller final {
23
public
:
25
struct
Event
{
27
enum
Type
{
28
kNone
= 0,
29
kRead
= (1 << 0),
30
kWrite
= (1 << 1),
31
kError
= (1 << 2),
32
};
33
35
int
fd
{
kInvalidFd
};
37
utils::Flags<Type>
type
{
kNone
};
39
size_t
epoch
{0};
40
};
41
43
enum class
[[nodiscard]]
Status
{
44
kSuccess
,
45
kInterrupt
,
46
kNoEvents
,
47
};
48
49
Poller
();
50
~Poller
();
51
52
Poller
(
const
Poller
&) =
delete
;
53
Poller
(
Poller
&&) =
delete
;
54
61
void
Add
(
int
fd,
utils::Flags<Event::Type>
events);
62
66
void
Remove
(
int
fd);
67
69
Status
NextEvent
(
Event
&,
Deadline
);
70
72
Status
NextEventNoblock
(
Event
&);
73
75
void
Interrupt
();
76
78
void
Reset
();
79
80
private
:
81
explicit
Poller(
const
std::shared_ptr<USERVER_NAMESPACE::concurrent::MpscQueue<Event>>&);
82
83
struct
IoWatcher;
84
85
void
RemoveImpl(IoWatcher& watcher);
86
87
template
<
typename
EventSource>
88
Status
EventsFilter(EventSource,
Event
&);
89
90
USERVER_NAMESPACE::concurrent::MpscQueue<Event>::Consumer event_consumer_;
91
USERVER_NAMESPACE::concurrent::MpscQueue<Event>::Producer event_producer_;
92
utils::FastPimpl<std::unordered_map<int, IoWatcher>
, 56,
alignof
(double),
false
> watchers_;
93
};
94
95
}
// namespace engine::io
96
97
USERVER_NAMESPACE_END
userver
engine
io
poller.hpp
Generated on
for userver by
Doxygen
1.17.0