Skip to content

Commit

Permalink
Add conditional compilation to SO_ACCEPTCONN
Browse files Browse the repository at this point in the history
Apple platforms declare the constant, but do not actually implement it.
  • Loading branch information
badeend committed Sep 18, 2023
1 parent 19fb806 commit 687918b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/backend/libc/net/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,7 @@ pub(crate) mod sockopt {
}

#[inline]
#[cfg(not(apple))] // Apple platforms declare the constant, but do not actually implement it.
pub(crate) fn get_socket_acceptconn(fd: BorrowedFd<'_>) -> io::Result<bool> {
getsockopt(fd, c::SOL_SOCKET as _, c::SO_ACCEPTCONN).map(to_bool)
}
Expand Down
3 changes: 1 addition & 2 deletions src/net/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,6 @@ pub fn get_socket_domain<Fd: AsFd>(fd: Fd) -> io::Result<AddressFamily> {
/// - [Linux `socket`]
/// - [Winsock2 `getsockopt`]
/// - [Winsock2 `SOL_SOCKET` options]
/// - [Apple]
/// - [FreeBSD]
/// - [NetBSD]
/// - [OpenBSD]
Expand All @@ -839,14 +838,14 @@ pub fn get_socket_domain<Fd: AsFd>(fd: Fd) -> io::Result<AddressFamily> {
/// [Linux `socket`]: https://man7.org/linux/man-pages/man7/socket.7.html
/// [Winsock2 `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt
/// [Winsock2 `SOL_SOCKET` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/sol-socket-socket-options
/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/getsockopt.2.html
/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=getsockopt&sektion=2
/// [NetBSD]: https://man.netbsd.org/getsockopt.2
/// [OpenBSD]: https://man.openbsd.org/getsockopt.2
/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=getsockopt&section=2
/// [illumos]: https://illumos.org/man/3SOCKET/getsockopt
/// [glibc `getsockopt`]: https://www.gnu.org/software/libc/manual/html_node/Socket-Option-Functions.html
/// [glibc `SOL_SOCKET` options]: https://www.gnu.org/software/libc/manual/html_node/Socket_002dLevel-Options.html
#[cfg(not(apple))] // Apple platforms declare the constant, but do not actually implement it.
#[inline]
#[doc(alias = "SO_ACCEPTCONN")]
pub fn get_socket_acceptconn<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
Expand Down
2 changes: 2 additions & 0 deletions tests/net/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ fn test_sockopts_ipv4() {
rustix::net::sockopt::get_socket_domain(&s).unwrap(),
AddressFamily::INET
);

#[cfg(not(apple))]
assert!(!rustix::net::sockopt::get_socket_acceptconn(&s).unwrap());

// Set a timeout.
Expand Down

0 comments on commit 687918b

Please sign in to comment.