Skip to content

Commit 2d571ae

Browse files
committed
allow configurable datagram buffer count in io_uring backend
1 parent 3babee1 commit 2d571ae

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

Sources/SwiftOCADevice/OCP.1/Backend/IORing/Ocp1IORingDeviceEndpoint.swift

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,68 @@ public class Ocp1IORingDatagramDeviceEndpoint: Ocp1IORingDeviceEndpoint,
254254
{
255255
typealias ControllerType = Ocp1IORingDatagramController
256256

257+
private let _bufferCount: Int?
257258
var _controllers = [AnySocketAddress: ControllerType]()
258259

259260
override public var controllers: [OcaController] {
260261
_controllers.map(\.1)
261262
}
262263

264+
public init(
265+
address: any SocketAddress,
266+
timeout: Duration = OcaDevice.DefaultTimeout,
267+
device: OcaDevice = OcaDevice.shared,
268+
logger: Logger = Logger(label: "com.padl.SwiftOCADevice.Ocp1IORingDeviceEndpoint"),
269+
bufferCount: Int? = nil,
270+
ring: IORing = .shared
271+
) async throws {
272+
_bufferCount = bufferCount
273+
try await super.init(
274+
address: address,
275+
timeout: timeout,
276+
device: device,
277+
logger: logger,
278+
ring: ring
279+
)
280+
}
281+
282+
public convenience init(
283+
address: Data,
284+
timeout: Duration = OcaDevice.DefaultTimeout,
285+
device: OcaDevice = OcaDevice.shared,
286+
logger: Logger = Logger(label: "com.padl.SwiftOCADevice.Ocp1IORingDeviceEndpoint"),
287+
bufferCount: Int? = nil
288+
) async throws {
289+
let storage = try sockaddr_storage(bytes: Array(address))
290+
try await self.init(
291+
address: storage,
292+
timeout: timeout,
293+
device: device,
294+
logger: logger,
295+
bufferCount: bufferCount
296+
)
297+
}
298+
299+
public convenience init(
300+
path: String,
301+
timeout: Duration = OcaDevice.DefaultTimeout,
302+
device: OcaDevice = OcaDevice.shared,
303+
logger: Logger = Logger(label: "com.padl.SwiftOCADevice.Ocp1IORingDeviceEndpoint"),
304+
bufferCount: Int? = nil
305+
) async throws {
306+
let storage = try sockaddr_un(
307+
family: sa_family_t(AF_LOCAL),
308+
presentationAddress: path
309+
)
310+
try await self.init(
311+
address: storage,
312+
timeout: timeout,
313+
device: device,
314+
logger: logger,
315+
bufferCount: bufferCount
316+
)
317+
}
318+
263319
func controller(for controllerAddress: AnySocketAddress) -> ControllerType {
264320
var controller: ControllerType!
265321

@@ -295,7 +351,10 @@ public class Ocp1IORingDatagramDeviceEndpoint: Ocp1IORingDeviceEndpoint,
295351

296352
repeat {
297353
do {
298-
let messagePdus = try await socket.receiveMessages(count: receiveBufferSize)
354+
let messagePdus = try await socket.receiveMessages(
355+
count: receiveBufferSize,
356+
capacity: _bufferCount
357+
)
299358

300359
for try await messagePdu in messagePdus {
301360
var controller: ControllerType!

0 commit comments

Comments
 (0)