Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/2539.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add the `TCP_FUNCTION_BLK` sockopt, on FreeBSD.
11 changes: 11 additions & 0 deletions src/sys/socket/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,18 @@ sockopt_impl!(
libc::SO_REUSEPORT_LB,
bool
);
#[cfg(target_os = "freebsd")]
#[cfg(feature = "net")]
sockopt_impl!(
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Select or query the set of functions that TCP will use for this connection. This allows a
/// user to select an alternate TCP stack.
TcpFunctionBlk,
Both,
libc::IPPROTO_TCP,
libc::TCP_FUNCTION_BLK,
libc::tcp_function_set
);
sockopt_impl!(
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Used to disable Nagle's algorithm.
Expand Down
22 changes: 22 additions & 0 deletions test/sys/test_sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,28 @@ fn test_tcp_congestion() {
assert_eq!(getsockopt(&fd, sockopt::TcpCongestion).unwrap(), val);
}

#[test]
#[cfg(target_os = "freebsd")]
fn test_tcp_function_blk() {
use std::ffi::CStr;

let fd = socket(
AddressFamily::Inet,
SockType::Stream,
SockFlag::empty(),
None,
)
.unwrap();

let tfs = getsockopt(&fd, sockopt::TcpFunctionBlk).unwrap();
let name = unsafe { CStr::from_ptr(tfs.function_set_name.as_ptr()) };
assert!(!name.to_bytes().is_empty());

// We can't know at compile time what options are available. So just test the setter by a
// no-op set.
setsockopt(&fd, sockopt::TcpFunctionBlk, &tfs).unwrap();
}

#[test]
#[cfg(linux_android)]
fn test_bindtodevice() {
Expand Down