libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
srtepoll.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_SRT
13#include <promeki/atomic.h>
14#include <promeki/function.h>
15#include <promeki/namespace.h>
16#include <promeki/error.h>
17#include <promeki/list.h>
18#include <promeki/map.h>
19#include <promeki/uniqueptr.h>
20
21#include <functional>
22
23PROMEKI_NAMESPACE_BEGIN
24
25class SrtSocket;
26class SrtServer;
27
88class SrtEpoll {
89 public:
91 using UPtr = UniquePtr<SrtEpoll>;
92
94 static constexpr int InvalidId = -1;
95
97 enum Event {
98 ReadReady = 0x01,
99 WriteReady = 0x02,
100 ErrorEvent = 0x04
101 };
102
104 struct Ready {
106 int handle = 0;
108 int events = 0;
109 };
110
112 using ReadyList = ::promeki::List<Ready>;
113
123 using ReadyCallback = Function<void(int events)>;
124
126 SrtEpoll();
127
129 ~SrtEpoll();
130
131 SrtEpoll(const SrtEpoll &) = delete;
132 SrtEpoll &operator=(const SrtEpoll &) = delete;
133
144 Error open();
145
147 void close();
148
150 bool isOpen() const { return _eid != InvalidId; }
151
159 Error add(SrtSocket &sock, int events);
160
172 Error add(SrtServer &server, int events);
173
180 Error modify(SrtSocket &sock, int events);
181
187 Error remove(SrtSocket &sock);
188
190 Error remove(SrtServer &server);
191
203 int wait(ReadyList &ready, int timeoutMs);
204
211 int handle() const { return _eid; }
212
227 Error setCallback(SrtSocket &sock, ReadyCallback cb);
228
230 Error setCallback(SrtServer &server, ReadyCallback cb);
231
248 int dispatchOnce(int timeoutMs);
249
260 int run();
261
269 void stop();
270
271 private:
272 int _eid = InvalidId;
273 Map<int, ReadyCallback> _callbacks;
274 Atomic<bool> _stopRequested{false};
275};
276
277PROMEKI_NAMESPACE_END
278
279#endif // PROMEKI_ENABLE_SRT