Skip to content

Commit f2d055c

Browse files
authored
Merge pull request #2470 from millenomi/port-android
Port: Android build fixes
2 parents df79904 + b2c45ab commit f2d055c

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

Foundation/Port.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,22 @@ public protocol PortDelegate : class {
8383
func handle(_ message: PortMessage)
8484
}
8585

86-
#if canImport(Glibc)
86+
#if canImport(Glibc) && !os(Android)
8787
import Glibc
8888
fileprivate let SOCK_STREAM = Int32(Glibc.SOCK_STREAM.rawValue)
8989
fileprivate let SOCK_DGRAM = Int32(Glibc.SOCK_DGRAM.rawValue)
9090
fileprivate let IPPROTO_TCP = Int32(Glibc.IPPROTO_TCP)
9191
#endif
9292

93+
#if canImport(Glibc) && os(Android)
94+
import Glibc
95+
fileprivate let SOCK_STREAM = Int32(Glibc.SOCK_STREAM)
96+
fileprivate let SOCK_DGRAM = Int32(Glibc.SOCK_DGRAM)
97+
fileprivate let IPPROTO_TCP = Int32(Glibc.IPPROTO_TCP)
98+
fileprivate let INADDR_ANY: in_addr_t = 0
99+
#endif
100+
101+
93102
#if canImport(WinSock)
94103
import WinSock
95104
#endif
@@ -440,7 +449,7 @@ open class SocketPort : Port {
440449
var address = sockaddr_in(settingLength: ())
441450
address.sin_family = sa_family_t(AF_INET)
442451
address.sin_port = in_port_t(port).bigEndian
443-
address.sin_addr.s_addr = INADDR_ANY
452+
address.sin_addr.s_addr = in_addr_t(INADDR_ANY).bigEndian
444453

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

@@ -529,7 +538,7 @@ open class SocketPort : Port {
529538
var sinAddr = sockaddr_in(settingLength: ())
530539
sinAddr.sin_family = sa_family_t(AF_INET)
531540
sinAddr.sin_port = port.bigEndian
532-
sinAddr.sin_addr.s_addr = INADDR_LOOPBACK.bigEndian
541+
sinAddr.sin_addr.s_addr = in_addr_t(INADDR_LOOPBACK).bigEndian
533542

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

0 commit comments

Comments
 (0)