@@ -214,25 +214,17 @@ final class AsyncIO: @unchecked Sendable {
214
214
215
215
// Windows Documentation: The function returns the handle
216
216
// of the existing I/O completion port if successful
217
- if CreateIoCompletionPort (
218
- handle, ioPort, completionKey, 0
219
- ) != ioPort {
220
- let lastError = GetLastError ( )
221
- if lastError != ERROR_INVALID_PARAMETER {
222
- let error = SubprocessError (
223
- code: . init( . asyncIOFailed( " CreateIoCompletionPort failed " ) ) ,
224
- underlyingError: . init( rawValue: GetLastError ( ) )
225
- )
226
- continuation. finish ( throwing: error)
227
- return
228
- } else {
229
- // Special Case:
230
- //
231
- // * ERROR_INVALID_PARAMETER - The handle likely doesn't have FILE_FLAG_OVERLAPPED, which might indicate that it isn't a pipe
232
- // so we can just signal that it is ready for reading right away.
233
- //
234
- continuation. yield ( UInt32 . max)
235
- }
217
+ guard
218
+ CreateIoCompletionPort (
219
+ handle, ioPort, completionKey, 0
220
+ ) == ioPort
221
+ else {
222
+ let error = SubprocessError (
223
+ code: . init( . asyncIOFailed( " CreateIoCompletionPort failed " ) ) ,
224
+ underlyingError: . init( rawValue: GetLastError ( ) )
225
+ )
226
+ continuation. finish ( throwing: error)
227
+ return
236
228
}
237
229
// Now save the continuation
238
230
_registration. withLock { storage in
@@ -279,7 +271,6 @@ final class AsyncIO: @unchecked Sendable {
279
271
// We use an empty `_OVERLAPPED()` here because `ReadFile` below
280
272
// only reads non-seekable files, aka pipes.
281
273
var overlapped = _OVERLAPPED ( )
282
- var bytesReadIfSynchronous = UInt32 ( 0 )
283
274
let succeed = try resultBuffer. withUnsafeMutableBufferPointer { bufferPointer in
284
275
// Get a pointer to the memory at the specified offset
285
276
// Windows ReadFile uses DWORD for target count, which means we can only
@@ -295,7 +286,7 @@ final class AsyncIO: @unchecked Sendable {
295
286
handle,
296
287
offsetAddress,
297
288
targetCount,
298
- & bytesReadIfSynchronous ,
289
+ nil ,
299
290
& overlapped
300
291
)
301
292
}
@@ -321,18 +312,8 @@ final class AsyncIO: @unchecked Sendable {
321
312
}
322
313
323
314
}
324
-
325
- let bytesRead =
326
- if bytesReadIfSynchronous == 0 {
327
- try await signalStream. next ( ) ?? 0
328
- } else {
329
- bytesReadIfSynchronous
330
- }
331
-
332
- // This handle doesn't support overlapped (asynchronous) I/O, so we must have read it synchronously above
333
- if bytesRead == UInt32 . max {
334
- bytesRead = bytesReadIfSynchronous
335
- }
315
+ // Now wait for read to finish
316
+ let bytesRead = try await signalStream. next ( ) ?? 0
336
317
337
318
if bytesRead == 0 {
338
319
// We reached EOF. Return whatever's left
0 commit comments