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
This commit is contained in:
Norman Maurer 2018-02-12 13:39:01 +01:00
parent 18a8467dfe
commit aa9728b852
6 changed files with 11 additions and 11 deletions

View File

@ -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<Channel> {
public func bind(to host: String, on port: Int) -> EventLoopFuture<Channel> {
let evGroup = group
do {
let address = try SocketAddress.newAddressResolving(host: host, port: port)

View File

@ -80,7 +80,7 @@ internal class GetaddrinfoResolver: Resolver {
var info: UnsafeMutablePointer<addrinfo>?
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
}

View File

@ -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()

View File

@ -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<addrinfo>?
/* FIXME: this is blocking! */

View File

@ -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)

View File

@ -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)