Sha256: 29856e6d0108be6b719f6ef973c5396e48ddd58ecd0c2db9ca3e2e0ba4eccb5b

Contents?: true

Size: 1.66 KB

Versions: 19

Compression:

Stored size: 1.66 KB

Contents

use crate::io;
use core::mem::MaybeUninit;
use windows_sys::Win32::Networking::WinSock::{WSACleanup, WSAGetLastError, WSAStartup, WSADATA};

/// `WSAStartup()`—Initialize process-wide Windows support for sockets.
///
/// On Windows, it's necessary to initialize the sockets subsystem before
/// using sockets APIs. The function performs the necessary initialization.
///
/// # References
///  - [Winsock]
///
/// [Winsock]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsastartup
pub fn wsa_startup() -> io::Result<WSADATA> {
    // Request version 2.2, which has been the latest version since far older
    // versions of Windows than we support here. For more information about
    // the version, see [here].
    //
    // [here]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsastartup#remarks
    let version = 0x202;
    let mut data = MaybeUninit::uninit();
    unsafe {
        let ret = WSAStartup(version, data.as_mut_ptr());
        if ret == 0 {
            Ok(data.assume_init())
        } else {
            Err(io::Errno::from_raw_os_error(WSAGetLastError()))
        }
    }
}

/// `WSACleanup()`—Clean up process-wide Windows support for sockets.
///
/// In a program where `init` is called, if sockets are no longer necessary,
/// this function releases associated resources.
///
/// # References
///  - [Winsock]
///
/// [Winsock]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsacleanup
pub fn wsa_cleanup() -> io::Result<()> {
    unsafe {
        if WSACleanup() == 0 {
            Ok(())
        } else {
            Err(io::Errno::from_raw_os_error(WSAGetLastError()))
        }
    }
}

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/rustix-0.38.44/src/net/wsa.rs
wasmtime-28.0.0 ./ext/cargo-vendor/rustix-0.38.43/src/net/wsa.rs
wasmtime-27.0.0 ./ext/cargo-vendor/rustix-0.38.41/src/net/wsa.rs
wasmtime-26.0.0 ./ext/cargo-vendor/rustix-0.38.37/src/net/wsa.rs
wasmtime-25.0.2 ./ext/cargo-vendor/rustix-0.38.34/src/net/wsa.rs
wasmtime-25.0.1 ./ext/cargo-vendor/rustix-0.38.34/src/net/wsa.rs
wasmtime-25.0.0 ./ext/cargo-vendor/rustix-0.38.34/src/net/wsa.rs
wasmtime-24.0.0 ./ext/cargo-vendor/rustix-0.38.34/src/net/wsa.rs
wasmtime-23.0.2 ./ext/cargo-vendor/rustix-0.38.34/src/net/wsa.rs
wasmtime-22.0.0 ./ext/cargo-vendor/rustix-0.38.34/src/net/wsa.rs
wasmtime-21.0.1 ./ext/cargo-vendor/rustix-0.38.34/src/net/wsa.rs
wasmtime-20.0.2 ./ext/cargo-vendor/rustix-0.38.34/src/net/wsa.rs
wasmtime-20.0.0 ./ext/cargo-vendor/rustix-0.38.34/src/net/wsa.rs
wasmtime-18.0.3 ./ext/cargo-vendor/rustix-0.38.28/src/net/wsa.rs
wasmtime-17.0.1 ./ext/cargo-vendor/rustix-0.38.28/src/net/wsa.rs
wasmtime-17.0.0 ./ext/cargo-vendor/rustix-0.38.28/src/net/wsa.rs
wasmtime-16.0.0 ./ext/cargo-vendor/rustix-0.38.28/src/net/wsa.rs
wasmtime-15.0.1 ./ext/cargo-vendor/rustix-0.38.28/src/net/wsa.rs
wasmtime-15.0.0 ./ext/cargo-vendor/rustix-0.38.28/src/net/wsa.rs