Skip to content

Port: Android build fixes #2470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 14, 2019
Merged
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
15 changes: 12 additions & 3 deletions Foundation/Port.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,22 @@ public protocol PortDelegate : class {
func handle(_ message: PortMessage)
}

#if canImport(Glibc)
#if canImport(Glibc) && !os(Android)
import Glibc
fileprivate let SOCK_STREAM = Int32(Glibc.SOCK_STREAM.rawValue)
fileprivate let SOCK_DGRAM = Int32(Glibc.SOCK_DGRAM.rawValue)
fileprivate let IPPROTO_TCP = Int32(Glibc.IPPROTO_TCP)
#endif

#if canImport(Glibc) && os(Android)
import Glibc
fileprivate let SOCK_STREAM = Int32(Glibc.SOCK_STREAM)
fileprivate let SOCK_DGRAM = Int32(Glibc.SOCK_DGRAM)
fileprivate let IPPROTO_TCP = Int32(Glibc.IPPROTO_TCP)
fileprivate let INADDR_ANY: in_addr_t = 0
#endif


#if canImport(WinSock)
import WinSock
#endif
Expand Down Expand Up @@ -440,7 +449,7 @@ open class SocketPort : Port {
var address = sockaddr_in(settingLength: ())
address.sin_family = sa_family_t(AF_INET)
address.sin_port = in_port_t(port).bigEndian
address.sin_addr.s_addr = INADDR_ANY
address.sin_addr.s_addr = in_addr_t(INADDR_ANY).bigEndian

let data = withUnsafeBytes(of: address) { Data($0) }

Expand Down Expand Up @@ -529,7 +538,7 @@ open class SocketPort : Port {
var sinAddr = sockaddr_in(settingLength: ())
sinAddr.sin_family = sa_family_t(AF_INET)
sinAddr.sin_port = port.bigEndian
sinAddr.sin_addr.s_addr = INADDR_LOOPBACK.bigEndian
sinAddr.sin_addr.s_addr = in_addr_t(INADDR_LOOPBACK).bigEndian

let data = withUnsafeBytes(of: sinAddr) { Data($0) }
self.init(remoteWithProtocolFamily: PF_INET, socketType: SOCK_STREAM, protocol: IPPROTO_TCP, address: data)
Expand Down