Skip to content
Merged
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
29 changes: 15 additions & 14 deletions tests/net/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ use rustix::io;
target_env = "newlib"
))]
use rustix::net::ipproto;
#[cfg(target_os = "linux")]
#[cfg(all(target_os = "linux", feature = "time"))]
use rustix::net::TxTimeFlags;
use rustix::net::{sockopt, AddressFamily, SocketType};
#[cfg(target_os = "linux")]
#[cfg(all(target_os = "linux", feature = "time"))]
use rustix::time::ClockId;
use std::net::Ipv4Addr;
use std::time::Duration;
Expand Down Expand Up @@ -40,8 +40,6 @@ fn test_sockopts_socket(s: &OwnedFd) {
assert!(!sockopt::socket_broadcast(s).unwrap());
// On a new socket we shouldn't have a linger yet.
assert!(sockopt::socket_linger(s).unwrap().is_none());
#[cfg(linux_kernel)]
assert!(!sockopt::socket_passcred(s).unwrap());

// On a new socket we shouldn't have an error yet.
assert_eq!(sockopt::socket_error(s).unwrap(), Ok(()));
Expand Down Expand Up @@ -119,15 +117,6 @@ fn test_sockopts_socket(s: &OwnedFd) {
// Check that we have a linger of at least the time we set.
assert!(sockopt::socket_linger(s).unwrap().unwrap() >= Duration::new(1, 1));

#[cfg(linux_kernel)]
{
// Set the passcred flag;
sockopt::set_socket_passcred(s, true).unwrap();

// Check that the passcred flag is set.
assert!(sockopt::socket_passcred(s).unwrap());
}

// Set the receive buffer size.
let size = sockopt::socket_recv_buffer_size(s).unwrap();
sockopt::set_socket_recv_buffer_size(s, size * 2).unwrap();
Expand Down Expand Up @@ -527,6 +516,18 @@ fn test_sockopts_ipv6() {
test_sockopts_tcp(&s);
}

#[cfg(linux_kernel)]
#[test]
fn test_socket_passcred() {
crate::init();

let s = rustix::net::socket(AddressFamily::UNIX, SocketType::STREAM, None).unwrap();

assert_eq!(sockopt::socket_passcred(&s), Ok(false));
sockopt::set_socket_passcred(&s, true).unwrap();
assert_eq!(sockopt::socket_passcred(&s), Ok(true));
}

#[cfg(any(linux_kernel, target_os = "cygwin"))]
#[test]
fn test_socketopts_ip_mtu() {
Expand Down Expand Up @@ -668,7 +669,7 @@ fn test_sockopts_multicast_ifv6() {
}

#[test]
#[cfg(target_os = "linux")]
#[cfg(all(target_os = "linux", feature = "time"))]
fn test_sockopts_txtime() {
crate::init();

Expand Down
Loading