Skip to content

Commit 60f93e7

Browse files
committed
network-comments: Added comments, fixed a few typos, and removed conditional parentheses for consistency
1 parent 836ad07 commit 60f93e7

File tree

4 files changed

+28
-24
lines changed

4 files changed

+28
-24
lines changed

stdlib/public/SDK/Network/NWConnection.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import _SwiftNetworkOverlayShims
2323
@available(macOS 10.14, iOS 12.0, watchOS 5.0, tvOS 12.0, *)
2424
public final class NWConnection : CustomDebugStringConvertible {
2525

26+
/// String based debugging representation of the NWConnection type.
2627
public var debugDescription: String {
2728
return String("\(self.nw)")
2829
}
@@ -354,7 +355,7 @@ public final class NWConnection : CustomDebugStringConvertible {
354355
}
355356

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

@@ -478,6 +479,7 @@ public final class NWConnection : CustomDebugStringConvertible {
478479
}
479480
}
480481

482+
/// Definition of callbacks used when sending data to the protocol stack.
481483
public enum SendCompletion {
482484
/// Completion handler to be invoked when send content has been successfully processed, or failed to send due to an error.
483485
/// 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: 22 additions & 21 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,14 +107,14 @@ 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()
114114
return result ?? "?"
115115
}
116116

117-
/// An IP address
117+
/// An IP address protocol
118118
@available(macOS 10.14, iOS 12.0, watchOS 5.0, tvOS 12.0, *)
119119
public protocol IPAddress {
120120

@@ -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
@@ -244,7 +244,7 @@ public struct IPv4Address: IPAddress, Hashable, CustomDebugStringConvertible {
244244
/// The interface the address is scoped to, if any.
245245
public let interface: NWInterface?
246246

247-
// Hashable
247+
/// Hashable
248248
public static func == (lhs: IPv4Address, rhs: IPv4Address) -> Bool {
249249
return lhs.address.s_addr == rhs.address.s_addr && lhs.interface == rhs.interface
250250
}
@@ -254,7 +254,7 @@ public struct IPv4Address: IPAddress, Hashable, CustomDebugStringConvertible {
254254
hasher.combine(self.interface)
255255
}
256256

257-
// CustomDebugStringConvertible
257+
/// CustomDebugStringConvertible returning a debug description string of the IPv4 address and interface or just the address.
258258
public var debugDescription: String {
259259
var sin = sockaddr_in(self.address, 0)
260260
let addressString = getnameinfo_numeric(address: &sin)
@@ -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
@@ -434,7 +434,7 @@ public struct IPv6Address: IPAddress, Hashable, CustomDebugStringConvertible {
434434
hasher.combine(self.interface)
435435
}
436436

437-
// CustomDebugStringConvertible
437+
/// CustomDebugStringConvertible returning a debug description string of the IPv6 address and interface or just the address.
438438
public var debugDescription: String {
439439
var sin6 = sockaddr_in6(self.address, 0)
440440
let addressString = getnameinfo_numeric(address: &sin6)
@@ -524,7 +524,7 @@ public enum NWEndpoint: Hashable, CustomDebugStringConvertible {
524524
return interface
525525
}
526526
}
527-
527+
528528
public var debugDescription: String {
529529
switch self {
530530
case .ipv4(let ip4):
@@ -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,32 @@ 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{
634+
635635
let host = NWEndpoint.Host.name(String(cString: nw_endpoint_get_hostname(nw)), interface)
636636
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) {
637+
} else if nw_endpoint_get_type(nw) == Network.nw_endpoint_type_address {
638+
638639
let port = NWEndpoint.Port(nw_endpoint_get_port(nw))
639640
let address = nw_endpoint_get_address(nw)
640-
if (address.pointee.sa_family == AF_INET && address.pointee.sa_len == MemoryLayout<sockaddr_in>.size) {
641+
if address.pointee.sa_family == AF_INET && address.pointee.sa_len == MemoryLayout<sockaddr_in>.size {
641642
let host = address.withMemoryRebound(to: sockaddr_in.self, capacity: 1) {
642643
(sin: UnsafePointer<sockaddr_in>) -> NWEndpoint.Host in
643644
return NWEndpoint.Host.ipv4(IPv4Address(sin.pointee.sin_addr, interface))
644645
}
645646
self = .hostPort(host: host, port: port)
646-
} else if (address.pointee.sa_family == AF_INET6 &&
647-
address.pointee.sa_len == MemoryLayout<sockaddr_in6>.size) {
647+
} else if address.pointee.sa_family == AF_INET6 &&
648+
address.pointee.sa_len == MemoryLayout<sockaddr_in6>.size {
648649
let host = address.withMemoryRebound(to: sockaddr_in6.self, capacity: 1) {
649650
(sin6) -> NWEndpoint.Host in
650-
if (interface == nil && sin6.pointee.sin6_scope_id != 0) {
651+
if interface == nil && sin6.pointee.sin6_scope_id != 0 {
651652
interface = NWInterface(Int(sin6.pointee.sin6_scope_id))
652653
}
653654
return NWEndpoint.Host.ipv6(IPv6Address(sin6.pointee.sin6_addr,
654655
interface))
655656
}
656657
self = .hostPort(host: host, port: port)
657-
} else if (address.pointee.sa_family == AF_UNIX) {
658+
} else if address.pointee.sa_family == AF_UNIX {
658659
// sockaddr_un is very difficult to deal with in swift. Fortunately, nw_endpoint_copy_address_string
659660
// already does exactly what we need.
660661
let path = nw_endpoint_copy_address_string(nw)
@@ -663,7 +664,7 @@ public enum NWEndpoint: Hashable, CustomDebugStringConvertible {
663664
} else {
664665
return nil
665666
}
666-
} else if (nw_endpoint_get_type(nw) == Network.nw_endpoint_type_bonjour_service) {
667+
} else if nw_endpoint_get_type(nw) == Network.nw_endpoint_type_bonjour_service {
667668
self = .service(name: String(cString: nw_endpoint_get_bonjour_service_name(nw)),
668669
type: String(cString: nw_endpoint_get_bonjour_service_type(nw)),
669670
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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public struct NWInterface : Hashable, CustomDebugStringConvertible {
2222
return self.name
2323
}
2424

25+
/// Comparison function to determine the equality of two network interfaces by name and kernel index.
2526
public static func ==(lhs: NWInterface, rhs: NWInterface) -> Bool {
2627
return lhs.index == rhs.index && lhs.name == rhs.name
2728
}
@@ -74,7 +75,7 @@ public struct NWInterface : Hashable, CustomDebugStringConvertible {
7475
}
7576
}
7677
}
77-
78+
// The interface type, such as other, wifi, cellular, wiredEthernet, and loopback.
7879
public let type: InterfaceType
7980

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

0 commit comments

Comments
 (0)