@@ -82,20 +82,25 @@ impl CompletionPort {
8282 res : io:: Result < usize > ,
8383 optr : * mut Overlapped < T > ,
8484 ) -> io:: Result < ( ) > {
85- if let Err ( e) = & res {
86- let code = e. raw_os_error ( ) . unwrap_or ( ERROR_BAD_COMMAND as _ ) ;
87- unsafe { & mut * optr } . base . Internal = ntstatus_from_win32 ( code) as _ ;
85+ if let Some ( overlapped) = unsafe { optr. as_mut ( ) } {
86+ match & res {
87+ Ok ( transferred) => {
88+ overlapped. base . Internal = STATUS_SUCCESS as _ ;
89+ overlapped. base . InternalHigh = * transferred;
90+ }
91+ Err ( e) => {
92+ let code = e. raw_os_error ( ) . unwrap_or ( ERROR_BAD_COMMAND as _ ) ;
93+ overlapped. base . Internal = ntstatus_from_win32 ( code) as _ ;
94+ }
95+ }
8896 }
89- // We have to use CompletionKey to transfer the result because it is large
90- // enough. It is OK because we set it to zero when attaching handles to IOCP.
97+ self . post_raw ( optr)
98+ }
99+
100+ pub fn post_raw < T : ?Sized > ( & self , optr : * const Overlapped < T > ) -> io:: Result < ( ) > {
91101 syscall ! (
92102 BOOL ,
93- PostQueuedCompletionStatus (
94- self . port. as_raw_handle( ) as _,
95- 0 ,
96- res. unwrap_or_default( ) ,
97- optr. cast( )
98- )
103+ PostQueuedCompletionStatus ( self . port. as_raw_handle( ) as _, 0 , 0 , optr. cast( ) )
99104 ) ?;
100105 Ok ( ( ) )
101106 }
@@ -143,7 +148,7 @@ impl CompletionPort {
143148 if let Some ( current_driver) = current_driver {
144149 if overlapped. driver != current_driver {
145150 // Repose the entry to correct port.
146- if let Err ( e ) = syscall ! (
151+ if let Err ( _e ) = syscall ! (
147152 BOOL ,
148153 PostQueuedCompletionStatus (
149154 overlapped. driver as _,
@@ -158,7 +163,7 @@ impl CompletionPort {
158163 entry. lpCompletionKey,
159164 entry. lpOverlapped,
160165 overlapped. driver,
161- e
166+ _e
162167 ) ;
163168 }
164169 }
@@ -167,11 +172,7 @@ impl CompletionPort {
167172 overlapped. base. Internal as NTSTATUS ,
168173 STATUS_SUCCESS | STATUS_PENDING
169174 ) {
170- if entry. lpCompletionKey != 0 {
171- Ok ( entry. lpCompletionKey )
172- } else {
173- Ok ( entry. dwNumberOfBytesTransferred as _ )
174- }
175+ Ok ( overlapped. base . InternalHigh )
175176 } else {
176177 let error = unsafe { RtlNtStatusToDosError ( overlapped. base . Internal as _ ) } ;
177178 match error {
0 commit comments