Skip to content

Commit db16c3a

Browse files
albertaleksieievweissi
authored andcommitted
fix Android support (#45)
### Android support **Motivation:** * fix `swift-nio-ssl` compatible with Android. This is a continuation(apple/swift-nio#609) of porting `Vapor/WebSocket` and all related packages to Android. * remove unused #if macros for Android * fix `stat` func with convention(c) attribute for Android **Modifications:** fix `FileSystemObject::pathType` and `sysStat` Android API inconsistency **Result:** now `swift-nio-ssl` compatible with Android!
1 parent 5c52211 commit db16c3a

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

Sources/NIOOpenSSL/PosixPort.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ private let sysMlock: @convention(c) (UnsafeRawPointer?, size_t) -> CInt = mlock
2727
private let sysMunlock: @convention(c) (UnsafeRawPointer?, size_t) -> CInt = munlock
2828

2929
// Sadly, stat has different signatures with glibc and macOS libc.
30-
#if os(Linux) || os(FreeBSD) || os(Android)
31-
private let sysStat: @convention(c) (UnsafePointer<CChar>, UnsafeMutablePointer<stat>) -> CInt = stat(_:_:)
32-
#elseif os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
30+
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(Android)
3331
private let sysStat: @convention(c) (UnsafePointer<CChar>?, UnsafeMutablePointer<stat>?) -> CInt = stat(_:_:)
32+
#elseif os(Linux) || os(FreeBSD)
33+
private let sysStat: @convention(c) (UnsafePointer<CChar>, UnsafeMutablePointer<stat>) -> CInt = stat(_:_:)
3434
#endif
3535

3636

Sources/NIOOpenSSL/SSLContext.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ private enum FileSystemObject {
3232
return nil
3333
}
3434

35+
#if os(Android)
36+
return (statObj.st_mode & UInt32(Glibc.S_IFDIR)) != 0 ? .directory : .file
37+
#else
3538
return (statObj.st_mode & S_IFDIR) != 0 ? .directory : .file
39+
#endif
3640
}
3741
}
3842

0 commit comments

Comments
 (0)