chenBright commented on code in PR #2560:
URL: https://github.com/apache/brpc/pull/2560#discussion_r1555158106


##########
src/brpc/event_dispatcher.h:
##########
@@ -21,11 +21,74 @@
 
 #include "butil/macros.h"                     // DISALLOW_COPY_AND_ASSIGN
 #include "bthread/types.h"                   // bthread_t, bthread_attr_t
-#include "brpc/socket.h"                     // Socket, SocketId
+#include "brpc/versioned_ref_with_id.h"
 
 
 namespace brpc {
 
+// Unique identifier of a EventData.
+// Users shall store EventDataId instead of EventData and call 
EventData::Address()
+// to convert the identifier to an unique_ptr at each access. Whenever a
+// unique_ptr is not destructed, the enclosed EventData will not be recycled.
+typedef VRefId EventDataId;
+
+const VRefId INVALID_EVENT_DATA_ID = INVALID_VREF_ID;
+
+class EventData;
+
+typedef VersionedRefWithIdUniquePtr<EventData> EventDataUniquePtr;
+
+// User callback type of input event and output event.
+typedef int (*InputEventCallback) (VRefId id, uint32_t events,
+                                   const bthread_attr_t& thread_attr);
+typedef InputEventCallback OutputEventCallback;
+
+struct EventDataOptions {
+    // Find user object to handle event by `user_id'.
+    uint64_t user_id;
+    // Callback for input event.
+    InputEventCallback input_cb;
+    // Callback for output event.
+    OutputEventCallback output_cb;
+};
+
+// EventDispatcher finds EventData by EventDataId which is
+// stored in epoll/kqueue data, and calls its callback, so
+// EventDispatcher supports various IO types, such as socket,
+// pipe, eventfd, timerfd, etc.
+class EventData : public VersionedRefWithId<EventData> {
+public:
+    explicit EventData(Forbidden f)
+        : VersionedRefWithId<EventData>(f)
+        , _options{INVALID_EVENT_DATA_ID, NULL, NULL} {}
+
+    DISALLOW_COPY_AND_ASSIGN(EventData);
+
+    int CallInputEventCallback(uint32_t events,

Review Comment:
   实现`template <typename T> class 
IOEvent`对象,封装了对`EventData`的操作逻辑,并利用模版,强制Socket或者其他IO类型对象实现`OnInputEvent`和`OnOutputEvent`函数。尽量降低使用成本。



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org
For additional commands, e-mail: dev-h...@brpc.apache.org

Reply via email to