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


##########
src/brpc/socket.cpp:
##########
@@ -1553,7 +1512,6 @@ inline int SetError(bthread_id_t id_wait, int ec) {
 }
 
 int Socket::ConductError(bthread_id_t id_wait) {
-    pthread_mutex_lock(&_id_wait_list_mutex);
     if (Failed()) {

Review Comment:
   pthread_mutex_lock怎么删了?



##########
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:
   
可不可以让Socket直接继承EventData,实现CallInputEventCallback和CallOutputEventCallback两个虚函数,这样就不需要EventDataOptions,event_data_id直接用socket的id



-- 
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