Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 7 additions & 7 deletions Sources/NIOPosix/VsockAddress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import NIOCore
#if canImport(Darwin)
import CNIODarwin
#elseif os(Linux)
#elseif os(Linux) || os(Android)
#if canImport(Glibc)
import Glibc
#elseif canImport(Musl)
Expand Down Expand Up @@ -168,7 +168,7 @@ extension ChannelOptions.Types {
extension NIOBSDSocket.AddressFamily {
/// Address for vsock.
public static var vsock: NIOBSDSocket.AddressFamily {
#if canImport(Darwin) || os(Linux)
#if canImport(Darwin) || os(Linux) || os(Android)
NIOBSDSocket.AddressFamily(rawValue: AF_VSOCK)
#else
fatalError(vsockUnimplemented)
Expand All @@ -179,7 +179,7 @@ extension NIOBSDSocket.AddressFamily {
extension NIOBSDSocket.ProtocolFamily {
/// Address for vsock.
public static var vsock: NIOBSDSocket.ProtocolFamily {
#if canImport(Darwin) || os(Linux)
#if canImport(Darwin) || os(Linux) || os(Android)
NIOBSDSocket.ProtocolFamily(rawValue: PF_VSOCK)
#else
fatalError(vsockUnimplemented)
Expand All @@ -189,7 +189,7 @@ extension NIOBSDSocket.ProtocolFamily {

extension VsockAddress {
public func withSockAddr<T>(_ body: (UnsafePointer<sockaddr>, Int) throws -> T) rethrows -> T {
#if canImport(Darwin) || os(Linux)
#if canImport(Darwin) || os(Linux) || os(Android)
return try self.address.withSockAddr({ try body($0, $1) })
#else
fatalError(vsockUnimplemented)
Expand All @@ -199,7 +199,7 @@ extension VsockAddress {

// MARK: - Internal functions that are only available on supported platforms.

#if canImport(Darwin) || os(Linux)
#if canImport(Darwin) || os(Linux) || os(Android)
extension VsockAddress.ContextID {
/// Get the context ID of the local machine.
///
Expand All @@ -218,7 +218,7 @@ extension VsockAddress.ContextID {
#if canImport(Darwin)
let request = CNIODarwin_IOCTL_VM_SOCKETS_GET_LOCAL_CID
let fd = socketFD
#elseif os(Linux)
#elseif os(Linux) || os(Android)
let request = CNIOLinux_IOCTL_VM_SOCKETS_GET_LOCAL_CID
let fd = try! Posix.open(file: "/dev/vsock", oFlag: O_RDONLY | O_CLOEXEC)
defer { try! Posix.close(descriptor: fd) }
Expand Down Expand Up @@ -277,4 +277,4 @@ extension BaseSocket {
}
}

#endif // canImport(Darwin) || os(Linux)
#endif // canImport(Darwin) || os(Linux) || os(Android)
2 changes: 1 addition & 1 deletion Tests/NIOPosixTests/EchoServerClientTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class EchoServerClientTest : XCTestCase {

#if canImport(Darwin)
let connectAddress = VsockAddress(cid: .any, port: port)
#elseif os(Linux)
#elseif os(Linux) || os(Android)
let connectAddress = VsockAddress(cid: .local, port: port)
#endif
let clientChannel = try assertNoThrowWithValue(ClientBootstrap(group: group).connect(to: connectAddress).wait())
Expand Down
2 changes: 1 addition & 1 deletion Tests/NIOPosixTests/TestUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extension System {
}

static var supportsVsock: Bool {
#if canImport(Darwin) || os(Linux)
#if canImport(Darwin) || os(Linux) || os(Android)
guard let socket = try? Socket(protocolFamily: .vsock, type: .stream) else { return false }
XCTAssertNoThrow(try socket.close())
return true
Expand Down