From aa9728b852073be0900e23ba976cbea6b51145ea Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Mon, 12 Feb 2018 13:39:01 +0100 Subject: [PATCH] Use Int for port to make API more consistent Motivation: In ClientBootstrap we use Int to represent the port but in ServerBootstrap we use Int32. As swift usually always use Int we should just use Int everywhere to represent the port. Modifications: Change Int32 to Int for port Result: More consistent API --- Sources/NIO/Bootstrap.swift | 2 +- Sources/NIO/GetaddrinfoResolver.swift | 2 +- Sources/NIO/ServerSocket.swift | 2 +- Sources/NIO/SocketAddresses.swift | 4 ++-- Sources/NIOEchoServer/main.swift | 6 +++--- Sources/NIOHTTP1Server/main.swift | 6 +++--- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Sources/NIO/Bootstrap.swift b/Sources/NIO/Bootstrap.swift index 864846c08..66c492c0d 100644 --- a/Sources/NIO/Bootstrap.swift +++ b/Sources/NIO/Bootstrap.swift @@ -89,7 +89,7 @@ public final class ServerBootstrap { /// - parameters: /// - host: The host to bind on. /// - port: The port to bind on. - public func bind(to host: String, on port: Int32) -> EventLoopFuture { + public func bind(to host: String, on port: Int) -> EventLoopFuture { let evGroup = group do { let address = try SocketAddress.newAddressResolving(host: host, port: port) diff --git a/Sources/NIO/GetaddrinfoResolver.swift b/Sources/NIO/GetaddrinfoResolver.swift index f31cc2836..66c12290b 100644 --- a/Sources/NIO/GetaddrinfoResolver.swift +++ b/Sources/NIO/GetaddrinfoResolver.swift @@ -80,7 +80,7 @@ internal class GetaddrinfoResolver: Resolver { var info: UnsafeMutablePointer? guard getaddrinfo(host, String(port), nil, &info) == 0 else { - self.fail(error: SocketAddressError.unknown(host: host, port: Int32(port))) + self.fail(error: SocketAddressError.unknown(host: host, port: port)) return } diff --git a/Sources/NIO/ServerSocket.swift b/Sources/NIO/ServerSocket.swift index 474d0e0c0..9f48444e7 100644 --- a/Sources/NIO/ServerSocket.swift +++ b/Sources/NIO/ServerSocket.swift @@ -13,7 +13,7 @@ //===----------------------------------------------------------------------===// final class ServerSocket: BaseSocket { - public class func bootstrap(protocolFamily: Int32, host: String, port: Int32) throws -> ServerSocket { + public class func bootstrap(protocolFamily: Int32, host: String, port: Int) throws -> ServerSocket { let socket = try ServerSocket(protocolFamily: protocolFamily) try socket.bind(to: SocketAddress.newAddressResolving(host: host, port: port)) try socket.listen() diff --git a/Sources/NIO/SocketAddresses.swift b/Sources/NIO/SocketAddresses.swift index 286f0dc76..e4c7028c1 100644 --- a/Sources/NIO/SocketAddresses.swift +++ b/Sources/NIO/SocketAddresses.swift @@ -15,7 +15,7 @@ /// Special `Error` that may be thrown if we fail to create a `SocketAddress`. public enum SocketAddressError: Error { /// The host is unknown (could not be resolved). - case unknown(host: String, port: Int32) + case unknown(host: String, port: Int) /// The requested `SocketAddress` is not supported. case unsupported /// The requested UDS path is too long. @@ -230,7 +230,7 @@ public enum SocketAddress: CustomStringConvertible { /// - port: the port itself /// - returns: the `SocketAddress` for the host / port pair. /// - throws: a `SocketAddressError.unknown` if we could not resolve the `host`, or `SocketAddressError.unsupported` if the address itself is not supported (yet). - public static func newAddressResolving(host: String, port: Int32) throws -> SocketAddress { + public static func newAddressResolving(host: String, port: Int) throws -> SocketAddress { var info: UnsafeMutablePointer? /* FIXME: this is blocking! */ diff --git a/Sources/NIOEchoServer/main.swift b/Sources/NIOEchoServer/main.swift index 4a89cc820..d0eabc158 100644 --- a/Sources/NIOEchoServer/main.swift +++ b/Sources/NIOEchoServer/main.swift @@ -69,15 +69,15 @@ let arg1 = arguments.dropFirst().first let arg2 = arguments.dropFirst().dropFirst().first let defaultHost = "::1" -let defaultPort: Int32 = 9999 +let defaultPort = 9999 enum BindTo { - case ip(host: String, port: Int32) + case ip(host: String, port: Int) case unixDomainSocket(path: String) } let bindTarget: BindTo -switch (arg1, arg1.flatMap { Int32($0) }, arg2.flatMap { Int32($0) }) { +switch (arg1, arg1.flatMap { Int($0) }, arg2.flatMap { Int($0) }) { case (.some(let h), _ , .some(let p)): /* we got two arguments, let's interpret that as host and port */ bindTarget = .ip(host: h, port: p) diff --git a/Sources/NIOHTTP1Server/main.swift b/Sources/NIOHTTP1Server/main.swift index a3ac92338..6f6a34796 100644 --- a/Sources/NIOHTTP1Server/main.swift +++ b/Sources/NIOHTTP1Server/main.swift @@ -357,17 +357,17 @@ let arg2 = arguments.dropFirst().dropFirst().first let arg3 = arguments.dropFirst().dropFirst().dropFirst().first let defaultHost = "::1" -let defaultPort: Int32 = 8888 +let defaultPort = 8888 let defaultHtdocs = "/dev/null/" enum BindTo { - case ip(host: String, port: Int32) + case ip(host: String, port: Int) case unixDomainSocket(path: String) } let htdocs: String let bindTarget: BindTo -switch (arg1, arg1.flatMap { Int32($0) }, arg2, arg2.flatMap { Int32($0) }, arg3) { +switch (arg1, arg1.flatMap { Int($0) }, arg2, arg2.flatMap { Int($0) }, arg3) { case (.some(let h), _ , _, .some(let p), let maybeHtdocs): /* second arg an integer --> host port [htdocs] */ bindTarget = .ip(host: h, port: p)