Skip to content

Commit

Permalink
Fix windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfishcode committed Sep 24, 2024
1 parent 57e4ad3 commit 9907250
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/event/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,32 @@ mod eventfd;
mod poll;
#[cfg(any(bsd, linux_kernel, windows, target_os = "wasi"))]
mod select;

#[cfg(windows)]
mod windows {
use std::sync::OnceLock;

pub struct Thing;

impl Thing {
pub fn new() -> Self {
let _ = rustix::net::wsa_startup().unwrap();
Self
}
}

impl Drop for Thing {
fn drop(&mut self) {
rustix::net::wsa_cleanup().unwrap();
}
}

pub static CLEANUP: OnceLock<Thing> = OnceLock::new();
}

/// Checks whether the Windows socket interface has been started already, and
/// if not, starts it.
pub fn init() {
#[cfg(windows)]
let _ = windows::CLEANUP.get_or_init(|| windows::Thing::new());
}
4 changes: 4 additions & 0 deletions tests/event/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ fn test_select_with_sockets() {
use rustix::net::{recv, send, AddressFamily, RecvFlags, SendFlags, SocketType};
use std::net::{IpAddr, Ipv4Addr, SocketAddr};

crate::init();

// Create a socket pair (but don't use `socketpair` because we want this
// to work on Windows too).

Expand Down Expand Up @@ -277,6 +279,8 @@ fn test_select_with_maxfd_sockets() {
use rustix::process::{getrlimit, setrlimit, Resource};
use std::net::{IpAddr, Ipv4Addr, SocketAddr};

crate::init();

let localhost = IpAddr::V4(Ipv4Addr::LOCALHOST);
let addr = SocketAddr::new(localhost, 0);
let listener = rustix::net::socket(AddressFamily::INET, SocketType::STREAM, None).unwrap();
Expand Down

0 comments on commit 9907250

Please sign in to comment.