Skip to content

Commit be8404f

Browse files
committed
Revert "Experimental non-overlapped handling for Windows AsyncIO via AsyncBufferSequence"
This reverts commit 1a3de70.
1 parent 9208e41 commit be8404f

File tree

1 file changed

+14
-33
lines changed

1 file changed

+14
-33
lines changed

Sources/Subprocess/IO/AsyncIO+Windows.swift

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -214,25 +214,17 @@ final class AsyncIO: @unchecked Sendable {
214214

215215
// Windows Documentation: The function returns the handle
216216
// 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
236228
}
237229
// Now save the continuation
238230
_registration.withLock { storage in
@@ -279,7 +271,6 @@ final class AsyncIO: @unchecked Sendable {
279271
// We use an empty `_OVERLAPPED()` here because `ReadFile` below
280272
// only reads non-seekable files, aka pipes.
281273
var overlapped = _OVERLAPPED()
282-
var bytesReadIfSynchronous = UInt32(0)
283274
let succeed = try resultBuffer.withUnsafeMutableBufferPointer { bufferPointer in
284275
// Get a pointer to the memory at the specified offset
285276
// Windows ReadFile uses DWORD for target count, which means we can only
@@ -295,7 +286,7 @@ final class AsyncIO: @unchecked Sendable {
295286
handle,
296287
offsetAddress,
297288
targetCount,
298-
&bytesReadIfSynchronous,
289+
nil,
299290
&overlapped
300291
)
301292
}
@@ -321,18 +312,8 @@ final class AsyncIO: @unchecked Sendable {
321312
}
322313

323314
}
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
336317

337318
if bytesRead == 0 {
338319
// We reached EOF. Return whatever's left

0 commit comments

Comments
 (0)