aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/neh/multiclient.h
diff options
context:
space:
mode:
authormonster <monster@ydb.tech>2022-07-07 14:41:37 +0300
committermonster <monster@ydb.tech>2022-07-07 14:41:37 +0300
commit06e5c21a835c0e923506c4ff27929f34e00761c2 (patch)
tree75efcbc6854ef9bd476eb8bf00cc5c900da436a2 /library/cpp/neh/multiclient.h
parent03f024c4412e3aa613bb543cf1660176320ba8f4 (diff)
downloadydb-06e5c21a835c0e923506c4ff27929f34e00761c2.tar.gz
fix ya.make
Diffstat (limited to 'library/cpp/neh/multiclient.h')
-rw-r--r--library/cpp/neh/multiclient.h72
1 files changed, 72 insertions, 0 deletions
diff --git a/library/cpp/neh/multiclient.h b/library/cpp/neh/multiclient.h
new file mode 100644
index 0000000000..e12b73dcd9
--- /dev/null
+++ b/library/cpp/neh/multiclient.h
@@ -0,0 +1,72 @@
+#pragma once
+
+#include "neh.h"
+
+namespace NNeh {
+ /// thread-safe dispacher for processing multiple neh requests
+ /// (method Wait() MUST be called from single thread, methods Request and Interrupt are thread-safe)
+ class IMultiClient {
+ public:
+ virtual ~IMultiClient() {
+ }
+
+ struct TRequest {
+ TRequest()
+ : Deadline(TInstant::Max())
+ , UserData(nullptr)
+ {
+ }
+
+ TRequest(const TMessage& msg, TInstant deadline = TInstant::Max(), void* userData = nullptr)
+ : Msg(msg)
+ , Deadline(deadline)
+ , UserData(userData)
+ {
+ }
+
+ TMessage Msg;
+ TInstant Deadline;
+ void* UserData;
+ };
+
+ /// WARNING:
+ /// Wait(event) called from another thread can return Event
+ /// for this request before this call return control
+ virtual THandleRef Request(const TRequest& req) = 0;
+
+ virtual size_t QueueSize() = 0;
+
+ struct TEvent {
+ enum TType {
+ Timeout,
+ Response,
+ SizeEventType
+ };
+
+ TEvent()
+ : Type(SizeEventType)
+ , UserData(nullptr)
+ {
+ }
+
+ TEvent(TType t, void* userData)
+ : Type(t)
+ , UserData(userData)
+ {
+ }
+
+ TType Type;
+ THandleRef Hndl;
+ void* UserData;
+ };
+
+ /// return false if interrupted
+ virtual bool Wait(TEvent&, TInstant = TInstant::Max()) = 0;
+ /// interrupt guaranteed breaking execution Wait(), but few interrupts can be handled as one
+ virtual void Interrupt() = 0;
+ };
+
+ typedef TAutoPtr<IMultiClient> TMultiClientPtr;
+
+ TMultiClientPtr CreateMultiClient();
+}