Skip to content

socket: support TCP_CORK option in Linux - #2769

Merged
SteveLauC merged 1 commit into
nix-rust:masterfrom
cgzones:tcp_cork
May 19, 2026
Merged

SteveLauC merged 1 commit into
nix-rust:masterfrom
cgzones:tcp_cork

Conversation

@cgzones

@cgzones cgzones commented Apr 12, 2026

Copy link
Copy Markdown
Contributor

Closes: #2758

What does this PR do

Enable getting and setting the corking state of a tcp connection. See man:tcp(7).

Checklist:

  • I have read CONTRIBUTING.md
  • I have written necessary tests and rustdoc comments
  • A change log has been added if this PR modifies nix's API

@kamalmarhubi kamalmarhubi 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.

Thanks @cgzones! Can you also add a changelog/2769.added.md file for this? 🙏

Comment thread src/sys/socket/sockopt.rs Resolved
@SteveLauC

Copy link
Copy Markdown
Member

I rebased your branch to resolve the CI failures.

@SteveLauC SteveLauC 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.

It would be great if we could have a simple round-trip test for this binding:

#[cfg(target_os = "linux")]
#[test]
fn test_tcp_cork() {
    let fd = socket(
        AddressFamily::Inet,
        SockType::Stream,
        SockFlag::empty(),
        SockProtocol::Tcp,
    )
    .unwrap();

    setsockopt(&fd, sockopt::TcpCork, &true).unwrap();
    assert!(getsockopt(&fd, sockopt::TcpCork).unwrap());

    setsockopt(&fd, sockopt::TcpCork, &false).unwrap();
    assert!(!getsockopt(&fd, sockopt::TcpCork).unwrap());
}

Enable getting and setting the corking state of a tcp connection.
See man:tcp(7).

Closes: nix-rust#2758
@cgzones

cgzones commented May 19, 2026

Copy link
Copy Markdown
Contributor Author

It would be great if we could have a simple round-trip test for this binding:

added

@SteveLauC SteveLauC 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.

Thanks

@SteveLauC
SteveLauC added this pull request to the merge queue May 19, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 19, 2026
@SteveLauC
SteveLauC added this pull request to the merge queue May 19, 2026
Merged via the queue into nix-rust:master with commit 5ccca41 May 19, 2026
45 checks passed
@cgzones
cgzones deleted the tcp_cork branch May 19, 2026 11:50
cgzones added a commit to cgzones/apt-cacher-rs that referenced this pull request Nov 23, 2026
nix 0.32 adds sockopt::TcpCork (nix-rust/nix#2769), so the raw
libc::setsockopt call and its unsafe block go away. The one-line
wrapper is inlined into CorkGuard::new and Drop; the Errno converts to
io::Error as last_os_error() did, so the Unsupported demotion and the
log text are unchanged.

Also note in fs_open that nix 0.32 still wraps no statx.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support setsockopt(2) option TCP_CORK

3 participants