Repository navigation
Follow-up for defer_accept before stabilization #164461
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -72,37 +72,46 @@ pub impl(self) trait TcpStreamExt { | |||||||||
| #[stable(feature = "tcp_quickack", since = "1.89.0")] | ||||||||||
| fn quickack(&self) -> io::Result<bool>; | ||||||||||
|
|
||||||||||
| /// A socket listener will be awakened solely when data arrives. | ||||||||||
| /// Configures the `TCP_DEFER_ACCEPT` option on the socket. | ||||||||||
| /// | ||||||||||
| /// The `accept` argument set the maximum delay until the | ||||||||||
| /// data is available to read, reducing the number of short lived | ||||||||||
| /// connections without data to process. | ||||||||||
| /// Contrary to other platforms `SO_ACCEPTFILTER` feature equivalent, there is | ||||||||||
| /// no necessity to set it after the `listen` call. | ||||||||||
| /// Note that the delay is expressed as Duration from user's perspective | ||||||||||
| /// the call rounds it down to the nearest second expressible as a `c_int`. | ||||||||||
| /// This defers accepting an incoming connection that has not yet received data. | ||||||||||
| /// The `accept` argument specifies an approximate delay. | ||||||||||
| /// | ||||||||||
| /// See [`man 7 tcp`](https://man7.org/linux/man-pages/man7/tcp.7.html) | ||||||||||
| /// Currently, the standard library rounds the duration down to whole seconds, | ||||||||||
| /// capped at `c_int::MAX` seconds. This may change if the underlying API becomes | ||||||||||
| /// more expressive. Passing [`Duration::ZERO`] disables this option. | ||||||||||
| /// | ||||||||||
| /// This option can also limit the number of attempts TCP makes to complete a | ||||||||||
| /// connection, so connections may be dropped if more retransmissions are needed. | ||||||||||
|
Comment on lines
+84
to
+85
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| /// | ||||||||||
| /// Unlike the equivalent `SO_ACCEPTFILTER` option on other platforms, this option | ||||||||||
| /// can be set before calling `listen`. | ||||||||||
| /// | ||||||||||
| /// See [`man 7 tcp`](https://man7.org/linux/man-pages/man7/tcp.7.html) for more information. | ||||||||||
| /// | ||||||||||
| /// # Examples | ||||||||||
| /// | ||||||||||
| /// ```no run | ||||||||||
| /// ```no_run | ||||||||||
| /// #![feature(tcp_deferaccept)] | ||||||||||
| /// use std::net::TcpStream; | ||||||||||
| /// use std::os::linux::net::TcpStreamExt; | ||||||||||
| /// use std::time::Duration; | ||||||||||
| /// | ||||||||||
| /// let stream = TcpStream::connect("127.0.0.1:8080") | ||||||||||
| /// .expect("Couldn't connect to the server..."); | ||||||||||
| /// stream.set_deferaccept(Duration::from_secs(1u64)).expect("set_deferaccept call failed"); | ||||||||||
| /// stream.set_defer_accept(Duration::from_secs(1u64)).expect("set_defer_accept call failed"); | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like a weird example -- this is suppose to be set on a socket before bind(...), not on the client socket? |
||||||||||
| /// ``` | ||||||||||
| #[unstable(feature = "tcp_deferaccept", issue = "119639")] | ||||||||||
| #[cfg(target_os = "linux")] | ||||||||||
| fn set_deferaccept(&self, accept: Duration) -> io::Result<()>; | ||||||||||
| fn set_defer_accept(&self, accept: Duration) -> io::Result<()>; | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
|
||||||||||
| /// Gets the accept delay value of the `TCP_DEFER_ACCEPT` option. | ||||||||||
| /// | ||||||||||
| /// For more information about this option, see [`TcpStreamExt::set_deferaccept`]. | ||||||||||
| /// Returns [`None`] if this option is disabled, or [`Some`] containing the delay | ||||||||||
| /// otherwise. The returned duration may differ from the requested duration due | ||||||||||
| /// to rounding. | ||||||||||
| /// | ||||||||||
| /// For more information about this option, see [`TcpStreamExt::set_defer_accept`]. | ||||||||||
| /// | ||||||||||
| /// # Examples | ||||||||||
| /// | ||||||||||
|
|
@@ -121,12 +130,14 @@ pub impl(self) trait TcpStreamExt { | |||||||||
| /// | ||||||||||
| /// let stream = TcpStream::connect("127.0.0.1:8080") | ||||||||||
| /// .expect("Couldn't connect to the server..."); | ||||||||||
| /// stream.set_deferaccept(Duration::from_secs(1u64)).expect("set_deferaccept call failed"); | ||||||||||
| /// assert_eq!(stream.deferaccept().unwrap(), Duration::from_secs(1u64)); | ||||||||||
| /// stream.set_defer_accept(Duration::from_secs(1u64)).expect("set_defer_accept call failed"); | ||||||||||
| /// assert_eq!(stream.defer_accept().unwrap(), Some(Duration::from_secs(1u64))); | ||||||||||
| /// stream.set_defer_accept(Duration::ZERO).expect("set_defer_accept call failed"); | ||||||||||
| /// assert_eq!(stream.defer_accept().unwrap(), None); | ||||||||||
| /// ``` | ||||||||||
| #[unstable(feature = "tcp_deferaccept", issue = "119639")] | ||||||||||
| #[cfg(target_os = "linux")] | ||||||||||
| fn deferaccept(&self) -> io::Result<Duration>; | ||||||||||
| fn defer_accept(&self) -> io::Result<Option<Duration>>; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| #[stable(feature = "tcp_quickack", since = "1.89.0")] | ||||||||||
|
|
@@ -140,12 +151,12 @@ impl TcpStreamExt for net::TcpStream { | |||||||||
| } | ||||||||||
|
|
||||||||||
| #[cfg(target_os = "linux")] | ||||||||||
| fn set_deferaccept(&self, accept: Duration) -> io::Result<()> { | ||||||||||
| self.as_inner().as_inner().set_deferaccept(accept) | ||||||||||
| fn set_defer_accept(&self, accept: Duration) -> io::Result<()> { | ||||||||||
| self.as_inner().as_inner().set_defer_accept(accept) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| #[cfg(target_os = "linux")] | ||||||||||
| fn deferaccept(&self) -> io::Result<Duration> { | ||||||||||
| self.as_inner().as_inner().deferaccept() | ||||||||||
| fn defer_accept(&self) -> io::Result<Option<Duration>> { | ||||||||||
| self.as_inner().as_inner().defer_accept() | ||||||||||
| } | ||||||||||
| } | ||||||||||
Uh oh!
There was an error while loading. Please reload this page.
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.
Edit: see below, this suggestion isn't good alone
The timeout will always be at least what you specified, the "weird" behavior is only that the delay might be significantly larger (up to 120 seconds longer, with the current implementation, but I expect that to be an implementation detail)View changes since the review
Uh oh!
There was an error while loading. Please reload this page.
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.
actually it's also not a minimum, a large duration will be capped at 255 retransmits, so this really is just a hint, the current wording is probably fine, maybe worth adding "may be significantly longer or shorter" because this isn't like "sleep(n) is approximate", this is its own class of approximate