From 0b3a8e4e3430fd509f17d2fc0f467cebd00cd1a2 Mon Sep 17 00:00:00 2001 From: Cory Benfield Date: Wed, 2 Jun 2021 11:15:58 +0100 Subject: [PATCH] Work around awkward SO_TIMESTAMP definition. (#1866) Motivation: On some Linux platforms the definition of SO_TIMESTAMP is too complex for the clang importer to handle. Delegate to C to find out what it should be. The same problem applies to SO_RCVTIMEO. Modifications: - Define SO_TIMESTAMP in CNIOLinux instead. - Define SO_RCVTIMEO in CNIOLinux instead. Result: Should build on the awkward Linux platforms. --- Sources/CNIOLinux/include/CNIOLinux.h | 4 ++++ Sources/CNIOLinux/shim.c | 3 +++ Sources/NIO/System.swift | 6 ++++++ 3 files changed, 13 insertions(+) diff --git a/Sources/CNIOLinux/include/CNIOLinux.h b/Sources/CNIOLinux/include/CNIOLinux.h index f3c8b09f2..0036a494b 100644 --- a/Sources/CNIOLinux/include/CNIOLinux.h +++ b/Sources/CNIOLinux/include/CNIOLinux.h @@ -72,5 +72,9 @@ const void *CNIOLinux_CMSG_DATA(const struct cmsghdr *); void *CNIOLinux_CMSG_DATA_MUTABLE(struct cmsghdr *); size_t CNIOLinux_CMSG_LEN(size_t); size_t CNIOLinux_CMSG_SPACE(size_t); + +// awkward time_T pain +extern int CNIOLinux_SO_TIMESTAMP; +extern int CNIOLinux_SO_RCVTIMEO; #endif #endif diff --git a/Sources/CNIOLinux/shim.c b/Sources/CNIOLinux/shim.c index cf5c32a19..053eb0470 100644 --- a/Sources/CNIOLinux/shim.c +++ b/Sources/CNIOLinux/shim.c @@ -143,4 +143,7 @@ size_t CNIOLinux_CMSG_LEN(size_t payloadSizeBytes) { size_t CNIOLinux_CMSG_SPACE(size_t payloadSizeBytes) { return CMSG_SPACE(payloadSizeBytes); } + +int CNIOLinux_SO_TIMESTAMP = SO_TIMESTAMP; +int CNIOLinux_SO_RCVTIMEO = SO_RCVTIMEO; #endif diff --git a/Sources/NIO/System.swift b/Sources/NIO/System.swift index 2d4e0313e..b031afb0c 100644 --- a/Sources/NIO/System.swift +++ b/Sources/NIO/System.swift @@ -58,6 +58,12 @@ let S_IFBLK = UInt32(SwiftGlibc.S_IFBLK) #endif #endif +// Work around SO_TIMESTAMP/SO_RCVTIMEO being awkwardly defined in glibc. +#if os(Linux) +let SO_TIMESTAMP = CNIOLinux_SO_TIMESTAMP +let SO_RCVTIMEO = CNIOLinux_SO_RCVTIMEO +#endif + // Declare aliases to share more code and not need to repeat #if #else blocks #if !os(Windows) private let sysClose = close