-
Notifications
You must be signed in to change notification settings - Fork 733
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 TcpSocket
, a basic TCP socket builder
#1358
Conversation
This provides `TcpSocket`, a basic API for building a TCP socket. The goal is not to provide comprehensive coverage of all system options, but to provide an API for the most common cases. This is added now as a replacement for the removal of `TcpStream::connect_std`. The `connect_std` function from v0.6 was used until now as the strategy to set socket option before obtaining a mio TcpStream. Providing some strategy for customizing a `TcpStream` is required for Hyper to be able to upgrade.
@Thomasdezeeuw This is ready to go! |
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.
Overall I still think something like this is better in a crate like socket2. However since that is still a way away I'm OK approving this.
For the review, I just have two small things.
}) | ||
} | ||
|
||
pub(crate) fn new_for_addr(addr: SocketAddr) -> io::Result<TcpSocket> { |
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.
Why not public? Perhaps with a new name: TcpSocket::for_address
.
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.
Mostly to minimize the API surface initially, but I can make it public.
@Thomasdezeeuw I'm posting this now for early feedback. The work is not done.
This provides
TcpSocket
, a basic API for building a TCP socket. The goal is not to provide comprehensive coverage of all system options, but to provide an API for the most common cases.This is added now as a replacement for the removal of
TcpStream::connect_std
. Theconnect_std
function from v0.6 was used until now as the strategy to set socket option before obtaining a mio TcpStream.Providing some strategy for customizing a
TcpStream
is required for Hyper to be able to upgrade.The
TcpSocket
API for Tokio is provided here. There has been some discussion in Discord related to how to handle configuring a TCP socket.I know there is some discussion about using
socket2
for advanced socket configuration. I don't believeTcpSocket
andsocket2
are mutually exclusive.TcpSocket
provides the ability to configure a socket while maintaining mio invariants (non-blocking).