-
Notifications
You must be signed in to change notification settings - Fork 271
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
Add unix socket #158
Add unix socket #158
Conversation
This looks super cool! is there any issue / context this pr refers to ? EDIT: my bad, i didn't notice #154 below |
I added it after I requested your review lol |
Actually it's terrible xD There should be a way to get a listener that is either a unix socket or a tcp listener. I made a PR to add that to tokio-util 🤞 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow this is great work! 🎉 the pull request reads incredibly well!
+1 for me, with only one question / comment.
Pre-approving this, although we might want to wait a bit and see if the tokio team wants to accept the listener trait.
Yes I would too but I expect this to take some time. The current implementation is quite easily replaceable so I wouldn't mind merging this for now. |
pub(crate) type BoxAsyncReadWrite = Box<dyn AsyncReadWrite + Send + Unpin + 'static>; | ||
|
||
impl AsyncReadWrite for TcpStream { | ||
fn set_nodelay(&self, nodelay: bool) -> io::Result<()> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be done right at socket creation, there's no need to add an empty method for UnixStream
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Outdated, I do not touch that part anymore
fn set_nodelay(&self, nodelay: bool) -> io::Result<()>; | ||
} | ||
|
||
pub(crate) type BoxAsyncReadWrite = Box<dyn AsyncReadWrite + Send + Unpin + 'static>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not a good idea to have a Box<dyn>
to hold either a TcpStream
or UnixStream
. It is useful when we're handling both kinds of objects at runtime, but here we're always creating one kind of object (we won't run in TCP and Unix socket modes at the same time), so we should not bear the cost of adding an allocation in the hot path for that.
AsyncRead
has one method, AsyncWrite
has 5 methods, so it's still reasonable to make an enum here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with new impl
This PR is ready for review again |
Co-authored-by: Gary Pennington <[email protected]>
Co-authored-by: Coenen Benjamin <[email protected]>
Linking this issue here as these traits could be moved to tokio-util:
tokio-rs/tokio#4244tokio-rs/tokio#4385It's working!
Fixes #154