SocketAddress
public enum SocketAddress : CustomStringConvertible
extension SocketAddress: Equatable
extension SocketAddress: Hashable
Represent a socket address to which we may want to connect or bind.
-
A single IPv4 address for
See moreSocketAddress
.Declaration
Swift
public struct IPv4Address
-
A single IPv6 address for
See moreSocketAddress
.Declaration
Swift
public struct IPv6Address
-
A single Unix socket address for
See moreSocketAddress
.Declaration
Swift
public struct UnixSocketAddress
-
An IPv4
SocketAddress
.Declaration
Swift
case v4(IPv4Address)
-
An IPv6
SocketAddress
.Declaration
Swift
case v6(IPv6Address)
-
An UNIX Domain
SocketAddress
.Declaration
Swift
case unixDomainSocket(UnixSocketAddress)
-
A human-readable description of this
SocketAddress
. Mostly useful for logging.Declaration
Swift
public var description: String { get }
-
Undocumented
Declaration
Swift
public var protocolFamily: Int32 { get }
-
Returns the protocol family as defined in
man 2 socket
of thisSocketAddress
.Declaration
Swift
public var `protocol`: NIOBSDSocket.ProtocolFamily { get }
-
Get the IP address as a string
Declaration
Swift
public var ipAddress: String? { get }
-
Get and set the port associated with the address, if defined. When setting to
nil
the port will default to0
for compatible sockets. The rationale for this is that bothnil
and0
can be interpreted as “no preference”. Setting a non-nil value for a unix domain socket is invalid and will result in a fatal error.Declaration
Swift
public var port: Int? { get set }
-
Get the pathname of a UNIX domain socket as a string
Declaration
Swift
public var pathname: String? { get }
-
Calls the given function with a pointer to a
sockaddr
structure and the associated size of that structure.Declaration
Swift
public func withSockAddr<T>(_ body: (UnsafePointer<sockaddr>, Int) throws -> T) rethrows -> T
-
Creates a new IPv4
SocketAddress
.Declaration
Swift
public init(_ addr: sockaddr_in, host: String)
Parameters
addr
the
sockaddr_in
that holds the ipaddress and port.host
the hostname that resolved to the ipaddress.
-
Creates a new IPv6
SocketAddress
.Declaration
Swift
public init(_ addr: sockaddr_in6, host: String)
Parameters
addr
the
sockaddr_in
that holds the ipaddress and port.host
the hostname that resolved to the ipaddress.
-
Creates a new IPv4
SocketAddress
.Declaration
Swift
public init(_ addr: sockaddr_in)
Parameters
addr
the
sockaddr_in
that holds the ipaddress and port. -
Creates a new IPv6
SocketAddress
.Declaration
Swift
public init(_ addr: sockaddr_in6)
Parameters
addr
the
sockaddr_in
that holds the ipaddress and port. -
Creates a new Unix Domain Socket
SocketAddress
.Declaration
Swift
public init(_ addr: sockaddr_un)
Parameters
addr
the
sockaddr_un
that holds the socket path. -
Creates a new UDS
SocketAddress
.Throws
may throwSocketAddressError.unixDomainSocketPathTooLong
if the path is too long.Declaration
Swift
public init(unixDomainSocketPath: String) throws
Parameters
path
the path to use for the
SocketAddress
.Return Value
the
SocketAddress
for the given path. -
Create a new
SocketAddress
for an IP address in string form.Throws
may throwSocketAddressError.failedToParseIPString
if the IP address cannot be parsed.Declaration
Swift
public init(ipAddress: String, port: Int) throws
Parameters
string
The IP address, in string form.
port
The target port.
Return Value
the
SocketAddress
corresponding to this string and port combination. -
Create a new
SocketAddress
for an IP address in ByteBuffer form.Throws
may throwSocketAddressError.failedToParseIPByteBuffer
if the IP address cannot be parsed.Declaration
Swift
public init(packedIPAddress: ByteBuffer, port: Int) throws
Parameters
packedIPAddress
The IP address, in ByteBuffer form.
port
The target port.
Return Value
the
SocketAddress
corresponding to this string and port combination. -
Creates a new
SocketAddress
for the given host (which will be resolved) and port.Warning
This is a blocking call, so please avoid calling this from an
EventLoop
.Throws
a
SocketAddressError.unknown
if we could not resolve thehost
, orSocketAddressError.unsupported
if the address itself is not supported (yet).Declaration
Swift
public static func makeAddressResolvingHost(_ host: String, port: Int) throws -> SocketAddress
Parameters
host
the hostname which should be resolved.
port
the port itself
Return Value
the
SocketAddress
for the host / port pair. -
Declaration
Swift
public static func == (lhs: SocketAddress, rhs: SocketAddress) -> Bool
-
Declaration
Swift
public func hash(into hasher: inout Hasher)
-
Whether this
SocketAddress
corresponds to a multicast address.Declaration
Swift
public var isMulticast: Bool { get }