Skip to content
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 the ListenQLimit sockopt (SO_LISTENQLIMIT) #2263

Merged
merged 1 commit into from
Dec 16, 2023
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/2263.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added the `SO_LISTENQLIMIT` sockopt.
11 changes: 11 additions & 0 deletions src/sys/socket/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,17 @@ sockopt_impl!(
libc::SO_PEERCRED,
super::UnixCredentials
);
#[cfg(target_os = "freebsd")]
#[cfg(feature = "net")]
sockopt_impl!(
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Get backlog limit of the socket
ListenQLimit,
GetOnly,
libc::SOL_SOCKET,
libc::SO_LISTENQLIMIT,
u32
);
#[cfg(apple_targets)]
#[cfg(feature = "net")]
sockopt_impl!(
Expand Down
25 changes: 25 additions & 0 deletions test/sys/test_sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,31 @@ fn test_so_buf() {
assert!(actual >= bufsize);
}

#[cfg(target_os = "freebsd")]
#[test]
fn test_so_listen_q_limit() {
use nix::sys::socket::{bind, listen, SockaddrIn};
use std::net::SocketAddrV4;
use std::str::FromStr;

let std_sa = SocketAddrV4::from_str("127.0.0.1:4004").unwrap();
let sock_addr = SockaddrIn::from(std_sa);

let rsock = socket(
AddressFamily::Inet,
SockType::Stream,
SockFlag::empty(),
SockProtocol::Tcp,
)
.unwrap();
bind(rsock.as_raw_fd(), &sock_addr).unwrap();
let pre_limit = getsockopt(&rsock, sockopt::ListenQLimit).unwrap();
assert_eq!(pre_limit, 0);
listen(&rsock, 42).unwrap();
let post_limit = getsockopt(&rsock, sockopt::ListenQLimit).unwrap();
assert_eq!(post_limit, 42);
}

#[test]
fn test_so_tcp_maxseg() {
use nix::sys::socket::{accept, bind, connect, listen, SockaddrIn};
Expand Down