Skip to content

network-comments: Added comments, fixed a few typos, and removed conditional parentheses for consistency #19108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion stdlib/public/SDK/Network/NWConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public final class NWConnection : CustomDebugStringConvertible {
}

/// Create a context for sending, that optionally can set expiration (default 0),
/// priority (default 0.5), antecendent (default nil), and protocol metadata (default []]).
/// priority (default 0.5), antecedent (default nil), and protocol metadata (default []]).
public init(identifier: String, expiration: UInt64 = 0, priority: Double = 0.5, isFinal: Bool = false, antecedent: NWConnection.ContentContext? = nil, metadata: [NWProtocolMetadata]? = []) {
self.nw = nw_content_context_create(identifier)

Expand Down Expand Up @@ -478,6 +478,7 @@ public final class NWConnection : CustomDebugStringConvertible {
}
}

/// A type representing a wrapped completion handler invoked when send content has been consumed by the protocol stack, or the lack of a completion handler because the content is idempotent.
public enum SendCompletion {
/// Completion handler to be invoked when send content has been successfully processed, or failed to send due to an error.
/// Note that this does not guarantee that the data was sent out over the network, or acknowledge, but only that
Expand Down
31 changes: 15 additions & 16 deletions stdlib/public/SDK/Network/NWEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ private func getaddrinfo_numeric(_ string: String, family: Int32 = 0) -> NWEndpo
var result: NWEndpoint.Host? = nil

if let sa = addrinfo.pointee.ai_addr {
if (sa.pointee.sa_family == AF_INET) {
if sa.pointee.sa_family == AF_INET {
sa.withMemoryRebound(to: sockaddr_in.self, capacity: 1, { (sin) -> Void in
result = NWEndpoint.Host.ipv4(IPv4Address(sin.pointee.sin_addr, interface))
})
} else if (sa.pointee.sa_family == AF_INET6) {
} else if sa.pointee.sa_family == AF_INET6 {
sa.withMemoryRebound(to: sockaddr_in6.self, capacity: 1, { (sin6) -> Void in
if (sin6.pointee.sin6_scope_id != 0) {
if sin6.pointee.sin6_scope_id != 0 {
interface = NWInterface(Int(sin6.pointee.sin6_scope_id))
}
let ipv6 = IPv6Address(sin6.pointee.sin6_addr, interface);
Expand All @@ -107,7 +107,7 @@ private func getnameinfo_numeric(address: UnsafeRawPointer) -> String {
var result : String? = nil
let maxLen = socklen_t(100)
let storage = UnsafeMutablePointer<Int8>.allocate(capacity: Int(maxLen))
if (getnameinfo(sa, socklen_t(sa.pointee.sa_len), storage, maxLen, nil, 0, NI_NUMERICHOST) == 0) {
if getnameinfo(sa, socklen_t(sa.pointee.sa_len), storage, maxLen, nil, 0, NI_NUMERICHOST) == 0 {
result = String(cString: storage)
}
storage.deallocate()
Expand Down Expand Up @@ -212,7 +212,7 @@ public struct IPv4Address: IPAddress, Hashable, CustomDebugStringConvertible {
/// - Parameter interface: An optional network interface to scope the address to. Defaults to nil.
/// - Returns: An IPv4Address or nil if the Data parameter did not contain an IPv4 address.
public init?(_ rawValue: Data, _ interface: NWInterface? = nil) {
if (rawValue.count != MemoryLayout<in_addr>.size) {
if rawValue.count != MemoryLayout<in_addr>.size {
return nil
}
let v4 = rawValue.withUnsafeBytes { (ptr: UnsafePointer<in_addr>) -> in_addr in
Expand Down Expand Up @@ -378,7 +378,7 @@ public struct IPv6Address: IPAddress, Hashable, CustomDebugStringConvertible {
/// - Parameter interface: An optional interface the address is scoped to. Defaults to nil.
/// - Returns: nil unless the raw data contained an IPv6 address
public init?(_ rawValue: Data, _ interface: NWInterface? = nil) {
if (rawValue.count != MemoryLayout<in6_addr>.size) {
if rawValue.count != MemoryLayout<in6_addr>.size {
return nil
}
let v6 = rawValue.withUnsafeBytes { (ptr: UnsafePointer<in6_addr>) -> in6_addr in
Expand Down Expand Up @@ -571,7 +571,7 @@ public enum NWEndpoint: Hashable, CustomDebugStringConvertible {
var hints = addrinfo(ai_flags: AI_DEFAULT, ai_family: AF_INET6, ai_socktype: SOCK_STREAM, ai_protocol: 0,
ai_addrlen: 0, ai_canonname: nil, ai_addr: nil, ai_next: nil)
var resolved : UnsafeMutablePointer<addrinfo>? = nil
if (getaddrinfo(nil, service, &hints, &resolved) != 0) {
if getaddrinfo(nil, service, &hints, &resolved) != 0 {
return nil
}

Expand Down Expand Up @@ -630,31 +630,30 @@ public enum NWEndpoint: Hashable, CustomDebugStringConvertible {
if let nwinterface = nw_endpoint_copy_interface(nw) {
interface = NWInterface(nwinterface)
}
if (nw_endpoint_get_type(nw) == Network.nw_endpoint_type_host)
{
if nw_endpoint_get_type(nw) == Network.nw_endpoint_type_host {
let host = NWEndpoint.Host.name(String(cString: nw_endpoint_get_hostname(nw)), interface)
self = .hostPort(host: host, port: NWEndpoint.Port(nw_endpoint_get_port(nw)))
} else if (nw_endpoint_get_type(nw) == Network.nw_endpoint_type_address) {
} else if nw_endpoint_get_type(nw) == Network.nw_endpoint_type_address {
let port = NWEndpoint.Port(nw_endpoint_get_port(nw))
let address = nw_endpoint_get_address(nw)
if (address.pointee.sa_family == AF_INET && address.pointee.sa_len == MemoryLayout<sockaddr_in>.size) {
if address.pointee.sa_family == AF_INET && address.pointee.sa_len == MemoryLayout<sockaddr_in>.size {
let host = address.withMemoryRebound(to: sockaddr_in.self, capacity: 1) {
(sin: UnsafePointer<sockaddr_in>) -> NWEndpoint.Host in
return NWEndpoint.Host.ipv4(IPv4Address(sin.pointee.sin_addr, interface))
}
self = .hostPort(host: host, port: port)
} else if (address.pointee.sa_family == AF_INET6 &&
address.pointee.sa_len == MemoryLayout<sockaddr_in6>.size) {
} else if address.pointee.sa_family == AF_INET6 &&
address.pointee.sa_len == MemoryLayout<sockaddr_in6>.size {
let host = address.withMemoryRebound(to: sockaddr_in6.self, capacity: 1) {
(sin6) -> NWEndpoint.Host in
if (interface == nil && sin6.pointee.sin6_scope_id != 0) {
if interface == nil && sin6.pointee.sin6_scope_id != 0 {
interface = NWInterface(Int(sin6.pointee.sin6_scope_id))
}
return NWEndpoint.Host.ipv6(IPv6Address(sin6.pointee.sin6_addr,
interface))
}
self = .hostPort(host: host, port: port)
} else if (address.pointee.sa_family == AF_UNIX) {
} else if address.pointee.sa_family == AF_UNIX {
// sockaddr_un is very difficult to deal with in swift. Fortunately, nw_endpoint_copy_address_string
// already does exactly what we need.
let path = nw_endpoint_copy_address_string(nw)
Expand All @@ -663,7 +662,7 @@ public enum NWEndpoint: Hashable, CustomDebugStringConvertible {
} else {
return nil
}
} else if (nw_endpoint_get_type(nw) == Network.nw_endpoint_type_bonjour_service) {
} else if nw_endpoint_get_type(nw) == Network.nw_endpoint_type_bonjour_service {
self = .service(name: String(cString: nw_endpoint_get_bonjour_service_name(nw)),
type: String(cString: nw_endpoint_get_bonjour_service_type(nw)),
domain: String(cString: nw_endpoint_get_bonjour_service_domain(nw)),
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/SDK/Network/NWParameters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public final class NWParameters : CustomDebugStringConvertible {
/// idempotent data on the connection before the connection may move
/// into ready state. As a side effect, this may implicitly enable
/// fast open for protocols in the stack, even if they did not have
/// fast open expliclty enabled on them (such as the option to enable
/// fast open explicitly enabled on them (such as the option to enable
/// TCP Fast Open).
public var allowFastOpen: Bool {
set {
Expand Down
1 change: 1 addition & 0 deletions stdlib/public/SDK/Network/NWPath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public struct NWInterface : Hashable, CustomDebugStringConvertible {
}
}

/// The interface type.
public let type: InterfaceType

/// The name of the interface, such as "en0"
Expand Down