wwbmmm commented on code in PR #2560: URL: https://github.com/apache/brpc/pull/2560#discussion_r1547103008
########## 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: > 2\. 要解决这个问题,Socket需要实现自己的Address函数,并在内部Address到EventDataUniquePtr后再转成SocketUniquePtr。 这种是不是还好,就是加一个类型转换的逻辑吧? -- 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