WinSocks context
This commit is contained in:
parent
5dc2ba2dca
commit
d61ceb5d79
@ -6,7 +6,7 @@ pub trait Address: Sized {
|
|||||||
pub trait NetworkContext {
|
pub trait NetworkContext {
|
||||||
type Address: Address;
|
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> {
|
pub trait ServersContext<A: Address> {
|
||||||
@ -20,5 +20,5 @@ pub trait ServersContext<A: Address> {
|
|||||||
pub trait NetworkScope {
|
pub trait NetworkScope {
|
||||||
type R;
|
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 super::errors::throw_from_windows_err_code;
|
||||||
|
use crate::network_context::WinSocksContext;
|
||||||
|
use bgtu_networks_2_network_abstract::NetworkScope;
|
||||||
use std::mem::uninitialized;
|
use std::mem::uninitialized;
|
||||||
|
use windows::core::w;
|
||||||
use windows::Win32::Networking::WinSock::{
|
use windows::Win32::Networking::WinSock::{
|
||||||
SOCKET_ERROR, WSACleanup, WSADATA, WSAGetLastError, WSAStartup,
|
SOCKET_ERROR, WSACleanup, WSADATA, WSAGetLastError, WSAStartup,
|
||||||
};
|
};
|
||||||
use bgtu_networks_2_network_abstract::NetworkScope;
|
|
||||||
|
|
||||||
struct WinSocksDefer {}
|
struct WinSocksDefer {}
|
||||||
|
|
||||||
@ -47,10 +49,9 @@ impl Drop for WinSocksDefer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn winsocks_scope_2_2<S: NetworkScope>(scope: S) -> S::R {
|
||||||
|
|
||||||
pub fn winsocks_scope_2_2<R>(scope: impl NetworkScope) -> R {
|
|
||||||
let ws = WinSocksDefer::startup((2, 2));
|
let ws = WinSocksDefer::startup((2, 2));
|
||||||
scope.run(todo!());
|
let r = scope.run(&mut WinSocksContext {});
|
||||||
let _ = ws;
|
drop(ws);
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,5 +4,6 @@ mod task;
|
|||||||
mod eventloop;
|
mod eventloop;
|
||||||
mod allocator;
|
mod allocator;
|
||||||
mod entry_point;
|
mod entry_point;
|
||||||
|
mod network_context;
|
||||||
|
|
||||||
pub use entry_point::winsocks_scope_2_2;
|
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