summaryrefslogtreecommitdiffstats
path: root/util/network/poller.h
diff options
context:
space:
mode:
authorDevtools Arcadia <[email protected]>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <[email protected]>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /util/network/poller.h
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'util/network/poller.h')
-rw-r--r--util/network/poller.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/util/network/poller.h b/util/network/poller.h
new file mode 100644
index 00000000000..8dccd731407
--- /dev/null
+++ b/util/network/poller.h
@@ -0,0 +1,58 @@
+#pragma once
+
+#include "socket.h"
+
+#include <util/generic/ptr.h>
+#include <util/datetime/base.h>
+
+class TSocketPoller {
+public:
+ TSocketPoller();
+ ~TSocketPoller();
+
+ void WaitRead(SOCKET sock, void* cookie);
+ void WaitWrite(SOCKET sock, void* cookie);
+ void WaitReadWrite(SOCKET sock, void* cookie);
+ void WaitRdhup(SOCKET sock, void* cookie);
+
+ void WaitReadOneShot(SOCKET sock, void* cookie);
+ void WaitWriteOneShot(SOCKET sock, void* cookie);
+ void WaitReadWriteOneShot(SOCKET sock, void* cookie);
+
+ void WaitReadWriteEdgeTriggered(SOCKET sock, void* cookie);
+ void RestartReadWriteEdgeTriggered(SOCKET sock, void* cookie, bool empty = true);
+
+ void Unwait(SOCKET sock);
+
+ size_t WaitD(void** events, size_t len, const TInstant& deadLine);
+
+ inline size_t WaitT(void** events, size_t len, const TDuration& timeOut) {
+ return WaitD(events, len, timeOut.ToDeadLine());
+ }
+
+ inline size_t WaitI(void** events, size_t len) {
+ return WaitD(events, len, TInstant::Max());
+ }
+
+ inline void* WaitD(const TInstant& deadLine) {
+ void* ret;
+
+ if (WaitD(&ret, 1, deadLine)) {
+ return ret;
+ }
+
+ return nullptr;
+ }
+
+ inline void* WaitT(const TDuration& timeOut) {
+ return WaitD(timeOut.ToDeadLine());
+ }
+
+ inline void* WaitI() {
+ return WaitD(TInstant::Max());
+ }
+
+private:
+ class TImpl;
+ THolder<TImpl> Impl_;
+};