Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EventDispatcher支持不同类型fd #2381

Closed
yanglimingcn opened this issue Sep 14, 2023 · 6 comments · Fixed by #2560
Closed

EventDispatcher支持不同类型fd #2381

yanglimingcn opened this issue Sep 14, 2023 · 6 comments · Fixed by #2560
Labels
feature new feature

Comments

@yanglimingcn
Copy link
Contributor

yanglimingcn commented Sep 14, 2023

Is your feature request related to a problem? (你需要的功能是否与某个问题有关?)

Describe the solution you'd like (描述你期望的解决方法)

现在brpc监听的都是socket fd,对于socket fd的处理都是OnNewMessages。有时候我们的服务需要监听一些其它类型的文件描述符,比如eventfd,然后通过eventfd来做一些逻辑,OnNewEvents。这块能否做一些扩展呢?让用户能向EventDispatcher注册这些fd并且实现自己的事件处理CallBack。
实现上,可能可以加一个Socket::DummyCreate(const SocketOptions& options, SocketId* id),SocketOptions里面填入自己的on_edge_triggered_events CallBack和对应的eventfd

Describe alternatives you've considered (描述你想到的折衷方案)

Additional context/screenshots (更多上下文/截图)

@chenBright
Copy link
Contributor

chenBright commented Sep 14, 2023

用bthread_fd_wait、bthread_fd_timedwait应该就能满足需求了吧

@yanglimingcn
Copy link
Contributor Author

看这个函数的注释,每次都要EPOLL_CTL_ADD and EPOLL_CTL_DEL,对性能有影响?我这个需求是注册上去了,后边就一直监听就可以了。

@chenBright
Copy link
Contributor

chenBright commented Sep 19, 2023

这样看起来不太适用

@chenBright
Copy link
Contributor

chenBright commented Sep 19, 2023

是不是可以将Socket中id、on_edge_triggered_events抽象到一个基类?Socket继承这个基类并实现对应的方法。有其他需求的话,就继承这个基类就好。

@yanglimingcn
Copy link
Contributor Author

嗯,我觉得这样是可以的

@chenBright
Copy link
Contributor

chenBright commented Mar 4, 2024

@yanglimingcn 有空看看,提了个PR支持这个feature #2560

@chenBright chenBright added the feature new feature label Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants