winsocks scope

This commit is contained in:
Andrew Golovashevich 2026-03-02 16:09:20 +03:00
parent 049b2b1a49
commit ffe2cc2f51
4 changed files with 35 additions and 3 deletions

View File

@ -4,4 +4,9 @@ mod windows;
mod servers_context;
pub type Address = windows::WindowsAddressKnown;
use allocator::Allocator;
use allocator::Allocator;
use crate::io::windows::winsocks_scope;
pub(crate) fn network_scope<R>(scope: impl FnOnce() -> R) -> R {
return winsocks_scope(scope);
}

View File

@ -2,5 +2,7 @@ mod address;
mod errors;
mod eventloop;
mod task;
mod winsocks_scope;
pub use address::{WindowsAddressAny, WindowsAddressKnown};
pub use address::{WindowsAddressAny, WindowsAddressKnown};
pub(super) use winsocks_scope::winsocks_scope;

View File

@ -0,0 +1,21 @@
use super::errors::throw_from_windows_err_code;
use std::mem::uninitialized;
use windows::Win32::Networking::WinSock::{WSACleanup, WSAStartup};
pub(in super::super) fn winsocks_scope<R>(scope: impl FnOnce() -> R) -> R {
unsafe {
match WSAStartup(0x0202, &mut uninitialized()) {
0 => {}
errcode => throw_from_windows_err_code(errcode),
}
let result = scope();
match WSACleanup() {
0 => {}
errcode => throw_from_windows_err_code(errcode),
}
return result;
}
}

View File

@ -1,6 +1,10 @@
use crate::io::network_scope;
mod data;
mod io;
fn main() {
println!("Hello, world!");
network_scope(|| {
println!("Hello, world!");
});
}