mirror of
https://github.com/apple/swift-system
synced 2026-11-22 04:30:46 +00:00
Address review comments
This commit is contained in:
1 parent
cbf57d4575
commit
95ed6aa2a4
3 files changed
+32
No files matched your search
@@ -274,6 +274,10 @@ extension IORing.Request {
|
||||
/// continue
|
||||
/// }
|
||||
/// armed = completion.flags.contains(.moreCompletions)
|
||||
/// if let error = completion.error {
|
||||
/// // The poll ended with an error, such as `.canceled`.
|
||||
/// throw error
|
||||
/// }
|
||||
/// // Handle incoming connection
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@@ -818,6 +818,14 @@ public struct IORing: ~Copyable {
|
||||
}
|
||||
|
||||
/// Sends all prepared requests to the kernel for processing, and then dequeues at least `minimumCount` completions, waiting up to `timeout` for them to become available. `consumer` is called to process each completed IO operation as it becomes available.
|
||||
///
|
||||
/// `consumer` receives a completion, an error, and whether consuming is done:
|
||||
/// - For each completed operation, it receives the completion. If the
|
||||
/// operation failed, it receives the operation's error alongside the
|
||||
/// completion.
|
||||
/// - If submitting the requests or waiting for completions fails, such as
|
||||
/// with ``Errno/timeout``, it receives the error without a completion.
|
||||
/// - Once consuming is done, it is called a final time with `done` set to `true`.
|
||||
@inlinable
|
||||
public func submitPreparedRequestsAndConsumeCompletions<Err: Error>(
|
||||
minimumCount: UInt32 = 1,
|
||||
|
||||
@@ -331,6 +331,26 @@ final class IORingTests: XCTestCase {
|
||||
XCTAssertEqual(completion.result, -Errno.badFileDescriptor.rawValue)
|
||||
}
|
||||
|
||||
func testSubmitAndConsumeCompletionsKeepsContextOfFailedCompletion() throws {
|
||||
try XCTSkipIf(!uringEnabled, failureMessage)
|
||||
var ring = try IORing(queueDepth: 4)
|
||||
XCTAssertTrue(ring.prepare(request: .close(FileDescriptor(rawValue: -1), context: 44)))
|
||||
|
||||
var received: [(context: UInt64?, error: Errno?, done: Bool)] = []
|
||||
ring.submitPreparedRequestsAndConsumeCompletions {
|
||||
(completion: consuming IORing.Completion?, error, done) in
|
||||
received.append((completion?.context, error, done))
|
||||
}
|
||||
|
||||
XCTAssertEqual(received.count, 2)
|
||||
XCTAssertEqual(received.first?.context, 44)
|
||||
XCTAssertEqual(received.first?.error, .badFileDescriptor)
|
||||
XCTAssertEqual(received.first?.done, false)
|
||||
XCTAssertEqual(received.last?.context, nil)
|
||||
XCTAssertEqual(received.last?.error, nil)
|
||||
XCTAssertEqual(received.last?.done, true)
|
||||
}
|
||||
|
||||
func testCompletionOfSuccessfulOperationHasNoError() throws {
|
||||
try XCTSkipIf(!uringEnabled, failureMessage)
|
||||
var ring = try IORing(queueDepth: 4)
|
||||
|
||||
Reference in new issue
Block a user