@@ -86,9 +86,12 @@ impl CompletionPort {
8686 Ok ( ( ) )
8787 }
8888
89+ // If current_driver is specified, any entry that doesn't belong the driver will
90+ // be reposted. The driver id will be used as IOCP handle.
8991 pub fn poll (
9092 & self ,
9193 timeout : Option < Duration > ,
94+ current_driver : Option < usize > ,
9295 ) -> io:: Result < impl Iterator < Item = ( usize , Entry ) > > {
9396 const DEFAULT_CAPACITY : usize = 1024 ;
9497
@@ -112,12 +115,26 @@ impl CompletionPort {
112115 trace ! ( "recv_count: {recv_count}" ) ;
113116 unsafe { entries. set_len ( recv_count as _ ) } ;
114117
115- Ok ( entries. into_iter ( ) . map ( |entry| {
118+ Ok ( entries. into_iter ( ) . map ( move |entry| {
116119 let transferred = entry. dwNumberOfBytesTransferred ;
117120 trace ! ( "entry transferred: {transferred}" ) ;
118121 // Any thin pointer is OK because we don't use the type of opcode.
119122 let overlapped_ptr: * mut Overlapped < ( ) > = entry. lpOverlapped . cast ( ) ;
120123 let overlapped = unsafe { & * overlapped_ptr } ;
124+ if let Some ( current_driver) = current_driver {
125+ if overlapped. driver != current_driver {
126+ syscall ! (
127+ BOOL ,
128+ PostQueuedCompletionStatus (
129+ overlapped. driver as _,
130+ entry. dwNumberOfBytesTransferred,
131+ entry. lpCompletionKey,
132+ entry. lpOverlapped
133+ )
134+ )
135+ . ok ( ) ;
136+ }
137+ }
121138 let res = if matches ! (
122139 overlapped. base. Internal as NTSTATUS ,
123140 STATUS_SUCCESS | STATUS_PENDING
0 commit comments