Improve split naming

*Socket + *Link
This commit is contained in:
Davide De Rosa 2018-08-24 12:44:17 +02:00
parent 54cc811e47
commit c4b0964c3c
3 changed files with 22 additions and 22 deletions

View File

@ -116,11 +116,11 @@ private extension NEProvider {
switch endpointProtocol.socketType { switch endpointProtocol.socketType {
case .udp: case .udp:
let impl = createUDPSession(to: endpoint, from: nil) let impl = createUDPSession(to: endpoint, from: nil)
return NEUDPInterface(impl: impl) return NEUDPSocket(impl: impl)
case .tcp: case .tcp:
let impl = createTCPConnection(to: endpoint, enableTLS: false, tlsParameters: nil, delegate: nil) let impl = createTCPConnection(to: endpoint, enableTLS: false, tlsParameters: nil, delegate: nil)
return NETCPInterface(impl: impl) return NETCPSocket(impl: impl)
} }
} }
} }

View File

@ -12,7 +12,7 @@ import SwiftyBeaver
private let log = SwiftyBeaver.self private let log = SwiftyBeaver.self
class NETCPInterface: NSObject, GenericSocket { class NETCPSocket: NSObject, GenericSocket {
private static var linkContext = 0 private static var linkContext = 0
private let impl: NWTCPConnection private let impl: NWTCPConnection
@ -55,13 +55,13 @@ class NETCPInterface: NSObject, GenericSocket {
return return
} }
} }
impl.addObserver(self, forKeyPath: #keyPath(NWTCPConnection.state), options: [.initial, .new], context: &NETCPInterface.linkContext) impl.addObserver(self, forKeyPath: #keyPath(NWTCPConnection.state), options: [.initial, .new], context: &NETCPSocket.linkContext)
impl.addObserver(self, forKeyPath: #keyPath(NWTCPConnection.hasBetterPath), options: .new, context: &NETCPInterface.linkContext) impl.addObserver(self, forKeyPath: #keyPath(NWTCPConnection.hasBetterPath), options: .new, context: &NETCPSocket.linkContext)
} }
func unobserve() { func unobserve() {
impl.removeObserver(self, forKeyPath: #keyPath(NWTCPConnection.state), context: &NETCPInterface.linkContext) impl.removeObserver(self, forKeyPath: #keyPath(NWTCPConnection.state), context: &NETCPSocket.linkContext)
impl.removeObserver(self, forKeyPath: #keyPath(NWTCPConnection.hasBetterPath), context: &NETCPInterface.linkContext) impl.removeObserver(self, forKeyPath: #keyPath(NWTCPConnection.hasBetterPath), context: &NETCPSocket.linkContext)
} }
func shutdown() { func shutdown() {
@ -73,17 +73,17 @@ class NETCPInterface: NSObject, GenericSocket {
guard impl.hasBetterPath else { guard impl.hasBetterPath else {
return nil return nil
} }
return NETCPInterface(impl: NWTCPConnection(upgradeFor: impl)) return NETCPSocket(impl: NWTCPConnection(upgradeFor: impl))
} }
func link(withMTU mtu: Int) -> LinkInterface { func link(withMTU mtu: Int) -> LinkInterface {
return NETCPLinkInterface(impl: impl) return NETCPLink(impl: impl)
} }
// MARK: Connection KVO (any queue) // MARK: Connection KVO (any queue)
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
guard (context == &NETCPInterface.linkContext) else { guard (context == &NETCPSocket.linkContext) else {
super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context) super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)
return return
} }
@ -147,7 +147,7 @@ class NETCPInterface: NSObject, GenericSocket {
} }
} }
class NETCPLinkInterface: LinkInterface { class NETCPLink: LinkInterface {
private let impl: NWTCPConnection private let impl: NWTCPConnection
private let maxPacketSize: Int private let maxPacketSize: Int
@ -219,7 +219,7 @@ class NETCPLinkInterface: LinkInterface {
} }
} }
extension NETCPInterface { extension NETCPSocket {
override var description: String { override var description: String {
guard let hostEndpoint = impl.endpoint as? NWHostEndpoint else { guard let hostEndpoint = impl.endpoint as? NWHostEndpoint else {
return impl.endpoint.description return impl.endpoint.description

View File

@ -12,7 +12,7 @@ import SwiftyBeaver
private let log = SwiftyBeaver.self private let log = SwiftyBeaver.self
class NEUDPInterface: NSObject, GenericSocket { class NEUDPSocket: NSObject, GenericSocket {
private static var linkContext = 0 private static var linkContext = 0
private let impl: NWUDPSession private let impl: NWUDPSession
@ -55,13 +55,13 @@ class NEUDPInterface: NSObject, GenericSocket {
return return
} }
} }
impl.addObserver(self, forKeyPath: #keyPath(NWUDPSession.state), options: [.initial, .new], context: &NEUDPInterface.linkContext) impl.addObserver(self, forKeyPath: #keyPath(NWUDPSession.state), options: [.initial, .new], context: &NEUDPSocket.linkContext)
impl.addObserver(self, forKeyPath: #keyPath(NWUDPSession.hasBetterPath), options: .new, context: &NEUDPInterface.linkContext) impl.addObserver(self, forKeyPath: #keyPath(NWUDPSession.hasBetterPath), options: .new, context: &NEUDPSocket.linkContext)
} }
func unobserve() { func unobserve() {
impl.removeObserver(self, forKeyPath: #keyPath(NWUDPSession.state), context: &NEUDPInterface.linkContext) impl.removeObserver(self, forKeyPath: #keyPath(NWUDPSession.state), context: &NEUDPSocket.linkContext)
impl.removeObserver(self, forKeyPath: #keyPath(NWUDPSession.hasBetterPath), context: &NEUDPInterface.linkContext) impl.removeObserver(self, forKeyPath: #keyPath(NWUDPSession.hasBetterPath), context: &NEUDPSocket.linkContext)
} }
func shutdown() { func shutdown() {
@ -72,17 +72,17 @@ class NEUDPInterface: NSObject, GenericSocket {
guard impl.hasBetterPath else { guard impl.hasBetterPath else {
return nil return nil
} }
return NEUDPInterface(impl: NWUDPSession(upgradeFor: impl)) return NEUDPSocket(impl: NWUDPSession(upgradeFor: impl))
} }
func link(withMTU mtu: Int) -> LinkInterface { func link(withMTU mtu: Int) -> LinkInterface {
return NEUDPLinkInterface(impl: impl, mtu: mtu) return NEUDPLink(impl: impl, mtu: mtu)
} }
// MARK: Connection KVO (any queue) // MARK: Connection KVO (any queue)
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
guard (context == &NEUDPInterface.linkContext) else { guard (context == &NEUDPSocket.linkContext) else {
super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context) super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)
return return
} }
@ -149,7 +149,7 @@ class NEUDPInterface: NSObject, GenericSocket {
} }
} }
class NEUDPLinkInterface: LinkInterface { class NEUDPLink: LinkInterface {
private let impl: NWUDPSession private let impl: NWUDPSession
private let maxDatagrams: Int private let maxDatagrams: Int
@ -204,7 +204,7 @@ class NEUDPLinkInterface: LinkInterface {
} }
} }
extension NEUDPInterface { extension NEUDPSocket {
override var description: String { override var description: String {
guard let hostEndpoint = impl.endpoint as? NWHostEndpoint else { guard let hostEndpoint = impl.endpoint as? NWHostEndpoint else {
return impl.endpoint.description return impl.endpoint.description