mirror of
https://github.com/apple/swift-nio
synced 2026-11-29 05:24:21 +00:00
Make swift-nio compile on linux as well
This commit is contained in:
1 parent
0427eaff33
commit
d28a7573de
4 files changed
+19
-10
No files matched your search
@@ -116,8 +116,8 @@ public class Channel : ChannelOutboundInvoker {
|
||||
|
||||
public func setOption<T: ChannelOption>(option: T, value: T.OptionType) throws {
|
||||
if option is SocketOption {
|
||||
let (level, name) = option.value as! (Int32, Int32)
|
||||
try socket.setOption(level: level, name: name, value: value)
|
||||
let (level, name) = option.value as! (Int, Int32)
|
||||
try socket.setOption(level: Int32(level), name: name, value: value)
|
||||
} else if option is AllocatorOption {
|
||||
allocator = value as! ByteBufferAllocator
|
||||
} else if option is RecvAllocatorOption {
|
||||
|
||||
@@ -35,16 +35,17 @@ extension ChannelOption where AssociatedValueType == () {
|
||||
}
|
||||
|
||||
public enum SocketOption: ChannelOption {
|
||||
public typealias AssociatedValueType = (Int32, Int32)
|
||||
public typealias AssociatedValueType = (Int, Int32)
|
||||
|
||||
public typealias OptionType = (Int)
|
||||
|
||||
case const(AssociatedValueType)
|
||||
|
||||
public init(level: Int32, name: Int32) {
|
||||
public init(level: Int, name: Int32) {
|
||||
self = .const((level, name))
|
||||
}
|
||||
|
||||
public var value: (Int32, Int32) {
|
||||
|
||||
public var value: (Int, Int32) {
|
||||
switch self {
|
||||
case .const(let level, let name):
|
||||
return (level, name)
|
||||
@@ -81,7 +82,11 @@ public enum MaxMessagesPerReadOption: ChannelOption {
|
||||
}
|
||||
|
||||
public struct ChannelOptions {
|
||||
public static let Socket = { (level: Int32, name: Int32) -> SocketOption in .const((level, name)) }
|
||||
#if os(Linux)
|
||||
public static let Socket = { (level: Int, name: Int32) -> SocketOption in .const((level, name)) }
|
||||
#else
|
||||
public static let Socket = { (level: Int32, name: Int32) -> SocketOption in .const((Int(level), name)) }
|
||||
#endif
|
||||
public static let Allocator = AllocatorOption.const(())
|
||||
public static let RecvAllocator = RecvAllocatorOption.const(())
|
||||
public static let AutoRead = AutoReadOption.const(())
|
||||
|
||||
@@ -200,7 +200,7 @@ public class Selector {
|
||||
public func close() throws {
|
||||
let _ = try wrapSyscall({ $0 >= 0 }, function: "close") {
|
||||
#if os(Linux)
|
||||
return Glibc.close(self.fd)
|
||||
return Int(Glibc.close(self.fd))
|
||||
#else
|
||||
return Int(Darwin.close(self.fd))
|
||||
#endif
|
||||
|
||||
@@ -72,8 +72,12 @@ public class ServerSocket: BaseSocket {
|
||||
|
||||
#if os(Linux)
|
||||
/* no SO_NOSIGPIPE on Linux :( */
|
||||
let old_sighandler = signal(SIGPIPE, SIG_IGN);
|
||||
if old_sighandler == SIG_ERR {
|
||||
let old_sighandler: sighandler_t = Glibc.signal(SIGPIPE, SIG_IGN)
|
||||
|
||||
let old_sighandler_ptr = unsafeBitCast(old_sighandler, to: UnsafeRawPointer.self)
|
||||
let sig_err_ptr = unsafeBitCast(SIG_ERR, to: UnsafeRawPointer.self)
|
||||
|
||||
if old_sighandler_ptr == sig_err_ptr {
|
||||
return nil
|
||||
}
|
||||
#else
|
||||
|
||||
Reference in new issue
Block a user