-
Notifications
You must be signed in to change notification settings - Fork 50
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
feat(server): allow custom implementations of listener #1217
Conversation
Passing this as ready for review, i can confirm that this is enough for a first implementation of having its custom listener. With this i'm able to retain listener after server stop and forward them to another process #1218 is also required to do that on quic socket |
I don't think we need both Also Also if |
If we keep only ListenDyn instead of both it means that we will have to write something like this : impl Listen for Listener {
fn accept(&self) -> Pin<Box<dyn Future<Output = io::Result<Stream>> + Send + '_>> {
Box::pin(async move { instead of impl Listen for Listener {
async fn accept(&self) -> io::Result<Stream> { Or maybe i'm missing something ? (just find it clearer and consistent to be able to write async trait directly like other trait in xitca) Will add the changes about |
The main problem here is we don't want to expose these types to users and cause possible confusion. Take I imagine we can do the following to hide pub trait IntoListener {
// add an associate type for listener
type Listener: Listen
fn into_lisenter(self) -> io::Result<Self::Listener>;
}
pub trait Listen: Send + Sync {
...
}
// hide ListenDyn trait from public
#[doc(hidden)]
pub trait ListenDyn {
...
}
type ListenerFn = Box<dyn FnOnce() -> io::Result<Arc<dyn ListenerDyn>> + Send>;
// cast listener object inside crate so neither Arc nor ListenDyn is visiable from public api
Box::new(|| listener.into_listener().map(Arc::new)) |
e97cb51
to
e1b73f6
Compare
e1b73f6
to
a6bb641
Compare
Should be better with last commit then |
I believe we can remove the |
Done |
Thanks the PR is good. I'll resolve the CI issue separately. |
Ref #1190
See this comment : #1190 (comment)
This allow end user to create its own listener as long as it returns a
xitca_io::net::stream
I did not make stream generic (could be in the future) neither.
Compared to the comment i choose to not make the Listen type generic, it could be in the future with another PR
In draft for the moment as i want to test this change on my project to be sure that i achieve what i want (getting back listener after shutdown)