Repository: apple/swift-nio
File: Sources/NIOPosix/Linux.swift (Swift)

Code before:
    internal static func eventfd(initval: CUnsignedInt, flags: CInt) throws -> CInt {
        return try syscall(blocking: false) {
            // Note: Please do _not_ remove the `numericCast`, this is to allow compilation in Ubuntu 14.04 and
            // other Linux distros which ship a glibc from before this commit:
            // https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=69eb9a183c19e8739065e430758e4d3a2c5e4f1a
            // which changes the first argument from `CInt` to `CUnsignedInt` (from Sat, 20 Sep 2014).
            CNIOLinux.eventfd(numericCast(initval), flags)
        }.result
    }
}

internal enum Epoll {
    internal typealias epoll_event = CNIOLinux.epoll_event

    internal static let EPOLL_CTL_ADD: CInt = numericCast(CNIOLinux.EPOLL_CTL_ADD)
    internal static let EPOLL_CTL_MOD: CInt = numericCast(CNIOLinux.EPOLL_CTL_MOD)
    internal static let EPOLL_CTL_DEL: CInt = numericCast(CNIOLinux.EPOLL_CTL_DEL)

    #if canImport(Android) || canImport(Musl)
    internal static let EPOLLIN: CUnsignedInt = numericCast(CNIOLinux.EPOLLIN)
    internal static let EPOLLOUT: CUnsignedInt = numericCast(CNIOLinux.EPOLLOUT)
    internal static let EPOLLERR: CUnsignedInt = numericCast(CNIOLinux.EPOLLERR)
    internal static let EPOLLRDHUP: CUnsignedInt = numericCast(CNIOLinux.EPOLLRDHUP)
    internal static let EPOLLHUP: CUnsignedInt = numericCast(CNIOLinux.EPOLLHUP)
    #if canImport(Android)
    internal static let EPOLLET: CUnsignedInt = 2147483648
    #else
    internal static let EPOLLET: CUnsignedInt = numericCast(CNIOLinux.EPOLLET)
    #endif
    #elseif os(Android)
    internal static let EPOLLIN: CUnsignedInt = 1 //numericCast(CNIOLinux.EPOLLIN)
    internal static let EPOLLOUT: CUnsignedInt = 4 //numericCast(CNIOLinux.EPOLLOUT)
    internal static let EPOLLERR: CUnsignedInt = 8 // numericCast(CNIOLinux.EPOLLERR)
    internal static let EPOLLRDHUP: CUnsignedInt = 8192 //numericCast(CNIOLinux.EPOLLRDHUP)
    internal static let EPOLLHUP: CUnsignedInt = 16 //numericCast(CNIOLinux.EPOLLHUP)
    internal static let EPOLLET: CUnsignedInt = 2147483648 //numericCast(CNIOLinux.EPOLLET)
    #else
    internal static let EPOLLIN: CUnsignedInt = numericCast(CNIOLinux.EPOLLIN.rawValue)
    internal static let EPOLLOUT: CUnsignedInt = numericCast(CNIOLinux.EPOLLOUT.rawValue)
    internal static let EPOLLERR: CUnsignedInt = numericCast(CNIOLinux.EPOLLERR.rawValue)
    internal static let EPOLLRDHUP: CUnsignedInt = numericCast(CNIOLinux.EPOLLRDHUP.rawValue)
    internal static let EPOLLHUP: CUnsignedInt = numericCast(CNIOLinux.EPOLLHUP.rawValue)
    internal static let EPOLLET: CUnsignedInt = numericCast(CNIOLinux.EPOLLET.rawValue)
    #endif

    internal static let ENOENT: CUnsignedInt = numericCast(CNIOLinux.ENOENT)


    @inline(never)
    internal static func epoll_create(size: CInt) throws -> CInt {
        return try syscall(blocking: false) {

Review comment (suggestion):
Previously, all these constants couldn't be automatically set by the ClangImporter from the C headers, but now [only this one constant couldn't, because it's the only one that's a C macro](https://android.googlesource.com/platform/bionic/+/7f4c837186fc09821cfebf94388a645ead246142/libc/kernel/uapi/linux/eventpoll.h#32).

Code after:
            CNIOLinux.eventfd_read(fd, value)
        }.result
    }

    @inline(never)
    internal static func eventfd(initval: CUnsignedInt, flags: CInt) throws -> CInt {
        try syscall(blocking: false) {
            // Note: Please do _not_ remove the `numericCast`, this is to allow compilation in Ubuntu 14.04 and
            // other Linux distros which ship a glibc from before this commit:
            // https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=69eb9a183c19e8739065e430758e4d3a2c5e4f1a
            // which changes the first argument from `CInt` to `CUnsignedInt` (from Sat, 20 Sep 2014).
            CNIOLinux.eventfd(numericCast(initval), flags)
        }.result
    }
}

internal enum Epoll {
    internal typealias epoll_event = CNIOLinux.epoll_event

    internal static let EPOLL_CTL_ADD: CInt = numericCast(CNIOLinux.EPOLL_CTL_ADD)
    internal static let EPOLL_CTL_MOD: CInt = numericCast(CNIOLinux.EPOLL_CTL_MOD)
    internal static let EPOLL_CTL_DEL: CInt = numericCast(CNIOLinux.EPOLL_CTL_DEL)

    #if canImport(Android) || canImport(Musl)
    internal static let EPOLLIN: CUnsignedInt = numericCast(CNIOLinux.EPOLLIN)
    internal static let EPOLLOUT: CUnsignedInt = numericCast(CNIOLinux.EPOLLOUT)
    internal static let EPOLLERR: CUnsignedInt = numericCast(CNIOLinux.EPOLLERR)
    internal static let EPOLLRDHUP: CUnsignedInt = numericCast(CNIOLinux.EPOLLRDHUP)
    internal static let EPOLLHUP: CUnsignedInt = numericCast(CNIOLinux.EPOLLHUP)
    #if canImport(Android)
    internal static let EPOLLET: CUnsignedInt = 2_147_483_648  // C macro not imported by ClangImporter
    #else
    internal static let EPOLLET: CUnsignedInt = numericCast(CNIOLinux.EPOLLET)
    #endif
    #elseif os(Android)
    internal static let EPOLLIN: CUnsignedInt = 1  //numericCast(CNIOLinux.EPOLLIN)
    internal static let EPOLLOUT: CUnsignedInt = 4  //numericCast(CNIOLinux.EPOLLOUT)
    internal static let EPOLLERR: CUnsignedInt = 8  // numericCast(CNIOLinux.EPOLLERR)
    internal static let EPOLLRDHUP: CUnsignedInt = 8192  //numericCast(CNIOLinux.EPOLLRDHUP)
    internal static let EPOLLHUP: CUnsignedInt = 16  //numericCast(CNIOLinux.EPOLLHUP)
    internal static let EPOLLET: CUnsignedInt = 2_147_483_648  //numericCast(CNIOLinux.EPOLLET)
    #else
    internal static let EPOLLIN: CUnsignedInt = numericCast(CNIOLinux.EPOLLIN.rawValue)
    internal static let EPOLLOUT: CUnsignedInt = numericCast(CNIOLinux.EPOLLOUT.rawValue)
    internal static let EPOLLERR: CUnsignedInt = numericCast(CNIOLinux.EPOLLERR.rawValue)
    internal static let EPOLLRDHUP: CUnsignedInt = numericCast(CNIOLinux.EPOLLRDHUP.rawValue)
    internal static let EPOLLHUP: CUnsignedInt = numericCast(CNIOLinux.EPOLLHUP.rawValue)
    internal static let EPOLLET: CUnsignedInt = numericCast(CNIOLinux.EPOLLET.rawValue)
    #endif

    internal static let ENOENT: CUnsignedInt = numericCast(CNIOLinux.ENOENT)