Skip to content

Commit

Permalink
add receive variant that returns async sequence of [UInt8]
Browse files Browse the repository at this point in the history
  • Loading branch information
lhoward committed Aug 2, 2024
1 parent f708ec3 commit 68c6aa6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
8 changes: 3 additions & 5 deletions Examples/IORingDeviceSpy/IORingDeviceSpy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@ public struct IORingDeviceSpy {
exit(1)
}

let blockSize: Int

if CommandLine.arguments.count > 2 {
blockSize = Int(CommandLine.arguments[2])!
let blockSize = if CommandLine.arguments.count > 2 {
Int(CommandLine.arguments[2])!
} else {
blockSize = 1
1
}

let spy = try await IORingDeviceSpy(blockSize: blockSize)
Expand Down
2 changes: 1 addition & 1 deletion Examples/IORingTCPEcho/IORingTCPEcho.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public struct IORingTCPEcho {
func receiveSendEcho(client: Socket) async {
do {
repeat {
let data = try await client.receive(count: bufferSize)
let data: [UInt8] = try await client.receive(count: bufferSize)
try await client.send(data)
} while true
} catch {
Expand Down
9 changes: 9 additions & 0 deletions Sources/IORingUtils/Socket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,15 @@ public struct Socket: CustomStringConvertible, Equatable, Hashable, Sendable {
)
}

@IORingActor
public func receive(count: Int) async throws -> AnyAsyncSequence<[UInt8]> {
guard let fileHandle else { throw Errno.badFileDescriptor }
return try ring.receive(
count: count,
from: fileHandle
)
}

@IORingActor
public func send(_ data: [UInt8]) async throws {
guard let fileHandle else { throw Errno.badFileDescriptor }
Expand Down

0 comments on commit 68c6aa6

Please sign in to comment.