Skip to content

Commit ab04797

Browse files
authored
Merge pull request #19108 from agnosticdev/network-comments
network-comments: Added comments, fixed a few typos, and removed conditional parentheses for consistency
2 parents 35e05d2 + e30efb6 commit ab04797

File tree

4 files changed

+19
-18
lines changed

4 files changed

+19
-18
lines changed

stdlib/public/SDK/Network/NWConnection.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ public final class NWConnection : CustomDebugStringConvertible {
354354
}
355355

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

@@ -478,6 +478,7 @@ public final class NWConnection : CustomDebugStringConvertible {
478478
}
479479
}
480480

481+
/// 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.
481482
public enum SendCompletion {
482483
/// Completion handler to be invoked when send content has been successfully processed, or failed to send due to an error.
483484
/// Note that this does not guarantee that the data was sent out over the network, or acknowledge, but only that

stdlib/public/SDK/Network/NWEndpoint.swift

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ private func getaddrinfo_numeric(_ string: String, family: Int32 = 0) -> NWEndpo
7979
var result: NWEndpoint.Host? = nil
8080

8181
if let sa = addrinfo.pointee.ai_addr {
82-
if (sa.pointee.sa_family == AF_INET) {
82+
if sa.pointee.sa_family == AF_INET {
8383
sa.withMemoryRebound(to: sockaddr_in.self, capacity: 1, { (sin) -> Void in
8484
result = NWEndpoint.Host.ipv4(IPv4Address(sin.pointee.sin_addr, interface))
8585
})
86-
} else if (sa.pointee.sa_family == AF_INET6) {
86+
} else if sa.pointee.sa_family == AF_INET6 {
8787
sa.withMemoryRebound(to: sockaddr_in6.self, capacity: 1, { (sin6) -> Void in
88-
if (sin6.pointee.sin6_scope_id != 0) {
88+
if sin6.pointee.sin6_scope_id != 0 {
8989
interface = NWInterface(Int(sin6.pointee.sin6_scope_id))
9090
}
9191
let ipv6 = IPv6Address(sin6.pointee.sin6_addr, interface);
@@ -107,7 +107,7 @@ private func getnameinfo_numeric(address: UnsafeRawPointer) -> String {
107107
var result : String? = nil
108108
let maxLen = socklen_t(100)
109109
let storage = UnsafeMutablePointer<Int8>.allocate(capacity: Int(maxLen))
110-
if (getnameinfo(sa, socklen_t(sa.pointee.sa_len), storage, maxLen, nil, 0, NI_NUMERICHOST) == 0) {
110+
if getnameinfo(sa, socklen_t(sa.pointee.sa_len), storage, maxLen, nil, 0, NI_NUMERICHOST) == 0 {
111111
result = String(cString: storage)
112112
}
113113
storage.deallocate()
@@ -212,7 +212,7 @@ public struct IPv4Address: IPAddress, Hashable, CustomDebugStringConvertible {
212212
/// - Parameter interface: An optional network interface to scope the address to. Defaults to nil.
213213
/// - Returns: An IPv4Address or nil if the Data parameter did not contain an IPv4 address.
214214
public init?(_ rawValue: Data, _ interface: NWInterface? = nil) {
215-
if (rawValue.count != MemoryLayout<in_addr>.size) {
215+
if rawValue.count != MemoryLayout<in_addr>.size {
216216
return nil
217217
}
218218
let v4 = rawValue.withUnsafeBytes { (ptr: UnsafePointer<in_addr>) -> in_addr in
@@ -378,7 +378,7 @@ public struct IPv6Address: IPAddress, Hashable, CustomDebugStringConvertible {
378378
/// - Parameter interface: An optional interface the address is scoped to. Defaults to nil.
379379
/// - Returns: nil unless the raw data contained an IPv6 address
380380
public init?(_ rawValue: Data, _ interface: NWInterface? = nil) {
381-
if (rawValue.count != MemoryLayout<in6_addr>.size) {
381+
if rawValue.count != MemoryLayout<in6_addr>.size {
382382
return nil
383383
}
384384
let v6 = rawValue.withUnsafeBytes { (ptr: UnsafePointer<in6_addr>) -> in6_addr in
@@ -571,7 +571,7 @@ public enum NWEndpoint: Hashable, CustomDebugStringConvertible {
571571
var hints = addrinfo(ai_flags: AI_DEFAULT, ai_family: AF_INET6, ai_socktype: SOCK_STREAM, ai_protocol: 0,
572572
ai_addrlen: 0, ai_canonname: nil, ai_addr: nil, ai_next: nil)
573573
var resolved : UnsafeMutablePointer<addrinfo>? = nil
574-
if (getaddrinfo(nil, service, &hints, &resolved) != 0) {
574+
if getaddrinfo(nil, service, &hints, &resolved) != 0 {
575575
return nil
576576
}
577577

@@ -630,31 +630,30 @@ public enum NWEndpoint: Hashable, CustomDebugStringConvertible {
630630
if let nwinterface = nw_endpoint_copy_interface(nw) {
631631
interface = NWInterface(nwinterface)
632632
}
633-
if (nw_endpoint_get_type(nw) == Network.nw_endpoint_type_host)
634-
{
633+
if nw_endpoint_get_type(nw) == Network.nw_endpoint_type_host {
635634
let host = NWEndpoint.Host.name(String(cString: nw_endpoint_get_hostname(nw)), interface)
636635
self = .hostPort(host: host, port: NWEndpoint.Port(nw_endpoint_get_port(nw)))
637-
} else if (nw_endpoint_get_type(nw) == Network.nw_endpoint_type_address) {
636+
} else if nw_endpoint_get_type(nw) == Network.nw_endpoint_type_address {
638637
let port = NWEndpoint.Port(nw_endpoint_get_port(nw))
639638
let address = nw_endpoint_get_address(nw)
640-
if (address.pointee.sa_family == AF_INET && address.pointee.sa_len == MemoryLayout<sockaddr_in>.size) {
639+
if address.pointee.sa_family == AF_INET && address.pointee.sa_len == MemoryLayout<sockaddr_in>.size {
641640
let host = address.withMemoryRebound(to: sockaddr_in.self, capacity: 1) {
642641
(sin: UnsafePointer<sockaddr_in>) -> NWEndpoint.Host in
643642
return NWEndpoint.Host.ipv4(IPv4Address(sin.pointee.sin_addr, interface))
644643
}
645644
self = .hostPort(host: host, port: port)
646-
} else if (address.pointee.sa_family == AF_INET6 &&
647-
address.pointee.sa_len == MemoryLayout<sockaddr_in6>.size) {
645+
} else if address.pointee.sa_family == AF_INET6 &&
646+
address.pointee.sa_len == MemoryLayout<sockaddr_in6>.size {
648647
let host = address.withMemoryRebound(to: sockaddr_in6.self, capacity: 1) {
649648
(sin6) -> NWEndpoint.Host in
650-
if (interface == nil && sin6.pointee.sin6_scope_id != 0) {
649+
if interface == nil && sin6.pointee.sin6_scope_id != 0 {
651650
interface = NWInterface(Int(sin6.pointee.sin6_scope_id))
652651
}
653652
return NWEndpoint.Host.ipv6(IPv6Address(sin6.pointee.sin6_addr,
654653
interface))
655654
}
656655
self = .hostPort(host: host, port: port)
657-
} else if (address.pointee.sa_family == AF_UNIX) {
656+
} else if address.pointee.sa_family == AF_UNIX {
658657
// sockaddr_un is very difficult to deal with in swift. Fortunately, nw_endpoint_copy_address_string
659658
// already does exactly what we need.
660659
let path = nw_endpoint_copy_address_string(nw)
@@ -663,7 +662,7 @@ public enum NWEndpoint: Hashable, CustomDebugStringConvertible {
663662
} else {
664663
return nil
665664
}
666-
} else if (nw_endpoint_get_type(nw) == Network.nw_endpoint_type_bonjour_service) {
665+
} else if nw_endpoint_get_type(nw) == Network.nw_endpoint_type_bonjour_service {
667666
self = .service(name: String(cString: nw_endpoint_get_bonjour_service_name(nw)),
668667
type: String(cString: nw_endpoint_get_bonjour_service_type(nw)),
669668
domain: String(cString: nw_endpoint_get_bonjour_service_domain(nw)),

stdlib/public/SDK/Network/NWParameters.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ public final class NWParameters : CustomDebugStringConvertible {
356356
/// idempotent data on the connection before the connection may move
357357
/// into ready state. As a side effect, this may implicitly enable
358358
/// fast open for protocols in the stack, even if they did not have
359-
/// fast open expliclty enabled on them (such as the option to enable
359+
/// fast open explicitly enabled on them (such as the option to enable
360360
/// TCP Fast Open).
361361
public var allowFastOpen: Bool {
362362
set {

stdlib/public/SDK/Network/NWPath.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public struct NWInterface : Hashable, CustomDebugStringConvertible {
7575
}
7676
}
7777

78+
/// The interface type.
7879
public let type: InterfaceType
7980

8081
/// The name of the interface, such as "en0"

0 commit comments

Comments
 (0)