WinSocks context
This commit is contained in:
parent
5dc2ba2dca
commit
d61ceb5d79
@ -6,7 +6,7 @@ pub trait Address: Sized {
|
||||
pub trait NetworkContext {
|
||||
type Address: Address;
|
||||
|
||||
fn run_ping_eventloop(ctx: impl ServersContext<Self::Address>);
|
||||
fn run_ping_eventloop(ctx: &mut impl ServersContext<Self::Address>);
|
||||
}
|
||||
|
||||
pub trait ServersContext<A: Address> {
|
||||
@ -20,5 +20,5 @@ pub trait ServersContext<A: Address> {
|
||||
pub trait NetworkScope {
|
||||
type R;
|
||||
|
||||
fn run(self, network: impl NetworkContext) -> Self::R;
|
||||
fn run(self, network: &mut impl NetworkContext) -> Self::R;
|
||||
}
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
use super::errors::throw_from_windows_err_code;
|
||||
use crate::network_context::WinSocksContext;
|
||||
use bgtu_networks_2_network_abstract::NetworkScope;
|
||||
use std::mem::uninitialized;
|
||||
use windows::core::w;
|
||||
use windows::Win32::Networking::WinSock::{
|
||||
SOCKET_ERROR, WSACleanup, WSADATA, WSAGetLastError, WSAStartup,
|
||||
};
|
||||
use bgtu_networks_2_network_abstract::NetworkScope;
|
||||
|
||||
struct WinSocksDefer {}
|
||||
|
||||
@ -47,10 +49,9 @@ impl Drop for WinSocksDefer {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
pub fn winsocks_scope_2_2<R>(scope: impl NetworkScope) -> R {
|
||||
let ws = WinSocksDefer::startup((2,2));
|
||||
scope.run(todo!());
|
||||
let _ = ws;
|
||||
pub fn winsocks_scope_2_2<S: NetworkScope>(scope: S) -> S::R {
|
||||
let ws = WinSocksDefer::startup((2, 2));
|
||||
let r = scope.run(&mut WinSocksContext {});
|
||||
drop(ws);
|
||||
return r;
|
||||
}
|
||||
|
||||
@ -4,5 +4,6 @@ mod task;
|
||||
mod eventloop;
|
||||
mod allocator;
|
||||
mod entry_point;
|
||||
mod network_context;
|
||||
|
||||
pub use entry_point::winsocks_scope_2_2;
|
||||
15
network/windows/src/network_context.rs
Normal file
15
network/windows/src/network_context.rs
Normal file
@ -0,0 +1,15 @@
|
||||
use bgtu_networks_2_network_abstract::{NetworkContext, ServersContext};
|
||||
use crate::address::WindowsAddressKnown;
|
||||
use crate::eventloop::run_eventloop;
|
||||
|
||||
pub(crate) struct WinSocksContext {}
|
||||
|
||||
impl NetworkContext for WinSocksContext {
|
||||
type Address = WindowsAddressKnown;
|
||||
|
||||
fn run_ping_eventloop(ctx: &mut impl ServersContext<Self::Address>) {
|
||||
unsafe {
|
||||
run_eventloop(ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user