Skip to content

Commit b140828

Browse files
committed
fix(driver): use InternalHigh as op result
1 parent fd5510e commit b140828

File tree

4 files changed

+34
-24
lines changed

4 files changed

+34
-24
lines changed

compio-driver/src/iocp/cp/global.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ impl GlobalPort {
3636
) -> io::Result<()> {
3737
self.port.post(res, optr)
3838
}
39+
40+
pub fn post_raw<T: ?Sized>(&self, optr: *const Overlapped<T>) -> io::Result<()> {
41+
self.port.post_raw(optr)
42+
}
3943
}
4044

4145
impl AsRawHandle for GlobalPort {
@@ -60,7 +64,7 @@ fn iocp_start() -> io::Result<()> {
6064
// Any thin pointer is OK because we don't use the type of opcode.
6165
let overlapped_ptr: *mut Overlapped<()> = entry.lpOverlapped.cast();
6266
let overlapped = unsafe { &*overlapped_ptr };
63-
if let Err(e) = syscall!(
67+
if let Err(_e) = syscall!(
6468
BOOL,
6569
PostQueuedCompletionStatus(
6670
overlapped.driver as _,
@@ -75,7 +79,7 @@ fn iocp_start() -> io::Result<()> {
7579
entry.lpCompletionKey,
7680
entry.lpOverlapped,
7781
overlapped.driver,
78-
e
82+
_e
7983
);
8084
}
8185
}
@@ -138,4 +142,8 @@ impl PortHandle {
138142
) -> io::Result<()> {
139143
self.port.post(res, optr)
140144
}
145+
146+
pub fn post_raw<T: ?Sized>(&self, optr: *const Overlapped<T>) -> io::Result<()> {
147+
self.port.post_raw(optr)
148+
}
141149
}

compio-driver/src/iocp/cp/mod.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {

compio-driver/src/iocp/cp/multi.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,8 @@ impl PortHandle {
5555
) -> io::Result<()> {
5656
self.port.post(res, optr)
5757
}
58+
59+
pub fn post_raw<T: ?Sized>(&self, optr: *const Overlapped<T>) -> io::Result<()> {
60+
self.port.post_raw(optr)
61+
}
5862
}

compio-driver/src/iocp/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,7 @@ impl NotifyHandle {
281281

282282
/// Notify the inner driver.
283283
pub fn notify(&self) -> io::Result<()> {
284-
self.port.post(
285-
Ok(0),
286-
self.overlapped.as_ref() as *const _ as *mut Overlapped<()> as _,
287-
)
284+
self.port.post_raw(self.overlapped.as_ref())
288285
}
289286
}
290287

0 commit comments

Comments
 (0)