@@ -11,10 +11,13 @@ use crossbeam_channel::{unbounded, Receiver, RecvTimeoutError, Sender, TryRecvEr
1111use crossbeam_skiplist:: SkipMap ;
1212#[ cfg( not( feature = "once_cell_try" ) ) ]
1313use once_cell:: sync:: OnceCell as OnceLock ;
14- use windows_sys:: Win32 :: Foundation :: ERROR_TIMEOUT ;
14+ use windows_sys:: Win32 :: {
15+ Foundation :: ERROR_TIMEOUT ,
16+ System :: IO :: { PostQueuedCompletionStatus , OVERLAPPED } ,
17+ } ;
1518
1619use super :: CompletionPort ;
17- use crate :: { Entry , Overlapped , RawFd } ;
20+ use crate :: { syscall , Entry , Overlapped , RawFd } ;
1821
1922struct GlobalPort {
2023 port : CompletionPort ,
@@ -75,7 +78,7 @@ fn iocp_start() -> io::Result<()> {
7578 std:: thread:: spawn ( move || {
7679 loop {
7780 for ( driver, entry) in port. port . poll ( None , None ) ? {
78- port. push ( driver, entry) ;
81+ port. push ( driver. 0 , entry) ;
7982 }
8083 }
8184 #[ allow( unreachable_code) ]
@@ -103,8 +106,8 @@ impl Port {
103106 Ok ( Self { id, port, receiver } )
104107 }
105108
106- pub fn id ( & self ) -> usize {
107- self . id
109+ pub fn id ( & self ) -> PortId {
110+ PortId ( self . id )
108111 }
109112
110113 pub fn attach ( & mut self , fd : RawFd ) -> io:: Result < ( ) > {
@@ -160,3 +163,18 @@ impl PortHandle {
160163 self . port . post ( res, optr)
161164 }
162165}
166+
167+ /// The unique ID of IOCP driver.
168+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
169+ pub struct PortId ( usize ) ;
170+
171+ impl PortId {
172+ /// Post raw entry to IOCP.
173+ pub fn post_raw ( & self , transferred : u32 , key : usize , optr : * mut OVERLAPPED ) -> io:: Result < ( ) > {
174+ syscall ! (
175+ BOOL ,
176+ PostQueuedCompletionStatus ( iocp_port( ) ?. as_raw_handle( ) as _, transferred, key, optr)
177+ ) ?;
178+ Ok ( ( ) )
179+ }
180+ }
0 commit comments