Skip to content

Commit

Permalink
fix Android support (#45)
Browse files Browse the repository at this point in the history
### 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!
  • Loading branch information
albertaleksieiev authored and weissi committed Oct 5, 2018
1 parent 5c52211 commit db16c3a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Sources/NIOOpenSSL/PosixPort.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ private let sysMlock: @convention(c) (UnsafeRawPointer?, size_t) -> CInt = mlock
private let sysMunlock: @convention(c) (UnsafeRawPointer?, size_t) -> CInt = munlock

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


Expand Down
4 changes: 4 additions & 0 deletions Sources/NIOOpenSSL/SSLContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ private enum FileSystemObject {
return nil
}

#if os(Android)
return (statObj.st_mode & UInt32(Glibc.S_IFDIR)) != 0 ? .directory : .file
#else
return (statObj.st_mode & S_IFDIR) != 0 ? .directory : .file
#endif
}
}

Expand Down

0 comments on commit db16c3a

Please sign in to comment.