Skip to content

Follow-up for defer_accept before stabilization - #164461

Open
JohnTitor wants to merge 1 commit into
rust-lang:mainfrom
JohnTitor:tcp-defer-accept-review-fixes
Open

JohnTitor wants to merge 1 commit into
rust-lang:mainfrom
JohnTitor:tcp-defer-accept-review-fixes

Conversation

@JohnTitor

Copy link
Copy Markdown
Member

Address review points in #154834
I've chosen Result<Option<Duration>> as noted in #154834 (comment), but we may want to discuss further and I'd like to hear opinions.
r? @Mark-Simulacrum @the8472

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Oct 17, 2026
/// 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.

@asquared31415 asquared31415 Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// The `accept` argument specifies an approximate delay.
/// The `accept` argument specifies a lower bound on the timeout. The actual timeout may be significantly larger.

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

@asquared31415 asquared31415 Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

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

#[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<()>;

@asquared31415 asquared31415 Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fn set_defer_accept(&self, accept: Duration) -> io::Result<()>;
fn set_defer_accept(&self, timeout: Duration) -> io::Result<()>;

accept is a weird name for this argument IMO. It's fine if there's precedence, but I think that something like timeout or delay or something would be more clear.

View changes since the review

Comment on lines +84 to +85
/// 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.

@asquared31415 asquared31415 Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// 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.
/// This option is useful to limit the number of attempts TCP makes to complete a
/// connection, so connections may be dropped if more retransmissions are needed.

View changes since the review

@Mark-Simulacrum Mark-Simulacrum left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like there are also a few pre-existing suggestions.

View changes since this review

/// 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");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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?

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 25, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants