chenBright commented on code in PR #2560: URL: https://github.com/apache/brpc/pull/2560#discussion_r1547108184
########## 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: 应该可以实现,就是得每个IO类型实现Address覆盖EventData的Address,并在自己的Address内部实现EventDataUniquePtr转换。 可以试试。 -- 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