Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Sources/NIOCore/SystemCallHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ private let sysRead: @convention(c) (CInt, UnsafeMutableRawPointer?, size_t) ->

#if os(Android)
private let sysIfNameToIndex: @convention(c) (UnsafePointer<CChar>) -> CUnsignedInt = if_nametoindex
#if compiler(>=6.3)
@available(Android 24, *)
#endif
private let sysGetifaddrs: @convention(c) (UnsafeMutablePointer<UnsafeMutablePointer<ifaddrs>?>) -> CInt = getifaddrs
#elseif !os(WASI)
private let sysIfNameToIndex: @convention(c) (UnsafePointer<CChar>?) -> CUnsignedInt = if_nametoindex
Expand Down Expand Up @@ -228,8 +231,12 @@ enum SystemCalls {
}

#if !os(Windows)

@inline(never)
@usableFromInline
#if compiler(>=6.3)
@available(Android 24, *)
#endif
internal static func getifaddrs(_ addrs: UnsafeMutablePointer<UnsafeMutablePointer<ifaddrs>?>) throws {
_ = try syscall(blocking: false) {
sysGetifaddrs(addrs)
Expand Down
6 changes: 6 additions & 0 deletions Sources/NIOCore/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ public enum System: Sendable {
/// - Returns: An array of network interfaces available on this machine.
/// - Throws: If an error is encountered while enumerating interfaces.
@available(*, deprecated, renamed: "enumerateDevices")
#if compiler(>=6.3)
@available(Android 24, *)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sufficiently Android-aware to know this impact here. Did this compile for Android API 23 prior to Swift 6.3, and now does not?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but we added @available support for Android in 6.3, that's why the compiler condition

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what happened to this code in the 6.2 compiler?

Copy link
Copy Markdown
Author

@madsodgaard madsodgaard Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not compile for Android 23, because the getifaddrs symbol is missing from the NDK in API 23 and below.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing I'm trying to figure out is whether this change produces a break for anyone, where code that previously compiled now will not.

Copy link
Copy Markdown
Author

@madsodgaard madsodgaard Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it would break anything. If you tried to compile swift-nio API 23 before, it would fail. The only place I could theoretically see it breaking was if someone was building swift-nio using a custom Android SDK and their own shim for getifaddrs and using one of the enumerate functions. Then they would get a error that it is only available on API 24.

But that's quite a stretch imo 😄

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I believe we have (limited) Android CI. Is there a reason this isn't triggering compile failures there? https://github.com/apple/swift-nio/actions/runs/21817139179/job/62941167486

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, currently the Android SDK is only compiled for API 28+. That should soon be brought down to 24, and I am working on API 23 support as well. So that's why its not appearing in CI.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, thanks.

#endif
public static func enumerateInterfaces() throws -> [NIONetworkInterface] {
var interfaces: [NIONetworkInterface] = []
interfaces.reserveCapacity(12) // Arbitrary choice.
Expand Down Expand Up @@ -190,6 +193,9 @@ public enum System: Sendable {
///
/// - Returns: An array of network devices available on this machine.
/// - Throws: If an error is encountered while enumerating interfaces.
#if compiler(>=6.3)
@available(Android 24, *)
#endif
public static func enumerateDevices() throws -> [NIONetworkDevice] {
var devices: [NIONetworkDevice] = []
devices.reserveCapacity(12) // Arbitrary choice.
Expand Down
14 changes: 13 additions & 1 deletion Sources/NIOMulticastChat/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,19 @@ let targetDevice: NIONetworkDevice? = {
if let interfaceAddress = CommandLine.arguments.dropFirst().first,
let targetAddress = try? SocketAddress(ipAddress: interfaceAddress, port: 0)
{
for device in try! System.enumerateDevices() {
let devices: [NIONetworkDevice]

#if compiler(>=6.3)
if #available(Android 24, *) {
devices = try! System.enumerateDevices()
} else {
fatalError("This demo only works on Android API 24+")
}
#else
devices = try! System.enumerateDevices()
#endif

for device in devices {
if device.address == targetAddress {
return device
}
Expand Down
Loading