diff --git a/Sources/CSystem/include/io_uring.h b/Sources/CSystem/include/io_uring.h index 3010bbc..defc284 100644 --- a/Sources/CSystem/include/io_uring.h +++ b/Sources/CSystem/include/io_uring.h @@ -113,7 +113,8 @@ typedef struct __SWIFT_IORING_SQE_FALLBACK_STRUCT swift_io_uring_sqe; #define IORING_OFF_CQ_RING 0x8000000ULL #define IORING_OFF_SQES 0x10000000ULL -#define IORING_ENTER_GETEVENTS (1U << 0) +#define IORING_ENTER_GETEVENTS (1U << 0) +#define IORING_ENTER_EXT_ARG (1U << 3) #define IORING_FEAT_SINGLE_MMAP (1U << 0) #define IORING_FEAT_NODROP (1U << 1) diff --git a/Sources/System/IORing/IORing.swift b/Sources/System/IORing/IORing.swift index dcb71e4..0da0dea 100644 --- a/Sources/System/IORing/IORing.swift +++ b/Sources/System/IORing/IORing.swift @@ -517,14 +517,16 @@ public struct IORing: ~Copyable { if count < minimumCount { while count < minimumCount { var sz = 0 + var flags = IORING_ENTER_GETEVENTS if extraArgs != nil { sz = MemoryLayout.size + flags |= IORING_ENTER_EXT_ARG } let res = io_uring_enter2( ringDescriptor, 0, minimumCount, - IORING_ENTER_GETEVENTS, + flags, extraArgs, sz ) @@ -536,14 +538,30 @@ public struct IORing: ~Copyable { // EFAULT (bad address for argument from library, fatal) // EBUSY (not enough space for events; implies events filled // by kernel between kernelTail load and now) - if res >= 0 || res == -EBUSY { + // ETIME (timeout from extraArgs.ts elapsed before + // minimumCount completions arrived) + if res >= 0 { break - } else if res == -EAGAIN || res == -EINTR { + } + let err: Errno + #if canImport(Glibc) + err = Errno(rawValue: Glibc.errno) + #elseif canImport(Musl) + err = Errno(rawValue: Musl.errno) + #endif + if err == .resourceBusy { + break + } + if err == .resourceTemporarilyUnavailable || err == .interrupted { continue } + if err == .timeout { + try consumer(nil, err, true) + return + } fatalError( "fatal error in receiving requests: " - + Errno(rawValue: -res).debugDescription + + err.debugDescription ) } var count = 0