Skip to content

Commit

Permalink
Add the ListenQLimit sockopt (SO_LISTENQLIMIT) (#2263)
Browse files Browse the repository at this point in the history
  • Loading branch information
asomers committed Dec 16, 2023
1 parent 7c3d84b commit 5102376
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
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

0 comments on commit 5102376

Please sign in to comment.