Skip to content

Commit

Permalink
Merge pull request #42 from Vinz1911/develop
Browse files Browse the repository at this point in the history
[M] minor cleanup
  • Loading branch information
Vinz1911 authored Feb 3, 2024
2 parents 1e30a69 + ab8d974 commit 87b92ba
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 13 deletions.
2 changes: 0 additions & 2 deletions Sources/FusionKit/Error/FKConnectionError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public enum FKConnectionError: Error {
case missingHost
case missingPort
case connectionTimeout
case connectionUnsatisfied
case parsingFailed
case readBufferOverflow
case writeBufferOverflow
Expand All @@ -25,7 +24,6 @@ public enum FKConnectionError: Error {
case .missingHost: return "missing host"
case .missingPort: return "missing port"
case .connectionTimeout: return "connection timeout"
case .connectionUnsatisfied: return "connection path is not satisfied"
case .parsingFailed: return "message parsing failed"
case .readBufferOverflow: return "read buffer overflow"
case .writeBufferOverflow: return "write buffer overflow"
Expand Down
2 changes: 1 addition & 1 deletion Sources/FusionKit/Extensions/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal extension Timer {
/// - completion: completion
/// - Returns: a source timer
static func timeout(after: TimeInterval = 3.0, _ completion: @escaping () -> Void) -> DispatchSourceTimer {
let dispatchTimer = DispatchSource.makeTimerSource(flags: .strict, queue: DispatchQueue(label: UUID().uuidString))
let dispatchTimer = DispatchSource.makeTimerSource(flags: .strict, queue: DispatchQueue(label: UUID().uuidString, qos: .userInteractive))
dispatchTimer.setEventHandler(handler: completion)
dispatchTimer.schedule(deadline: .now() + after, repeating: .never)
dispatchTimer.resume()
Expand Down
9 changes: 3 additions & 6 deletions Sources/FusionKit/Model/FKConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ public final class FKConnection: FKConnectionProtocol {
/// - port: the host port
/// - parameters: network parameters
/// - queue: dispatch queue
public required init(host: String, port: UInt16, parameters: NWParameters = .tcp, queue: DispatchQueue = .init(label: UUID().uuidString)) {
if host.isEmpty { fatalError(FKConnectionError.missingHost.description) }
if port == .zero { fatalError(FKConnectionError.missingPort.description) }
public required init(host: String, port: UInt16, parameters: NWParameters = .tcp, queue: DispatchQueue = .init(label: UUID().uuidString, qos: .userInteractive)) {
if host.isEmpty { fatalError(FKConnectionError.missingHost.description) }; if port == .zero { fatalError(FKConnectionError.missingPort.description) }
self.connection = NWConnection(host: NWEndpoint.Host(host), port: NWEndpoint.Port(integerLiteral: port), using: parameters)
self.queue = queue
}
Expand Down Expand Up @@ -115,9 +114,7 @@ private extension FKConnection {
private func cleanup() -> Void {
self.queue.async { [weak self] in
guard let self else { return }
invalidate()
connection.cancel()
framer.reset()
invalidate(); connection.cancel(); framer.reset()
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/FusionKit/Model/FKConnectionOpcodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal enum FKConnectionOpcodes: UInt8 {
case ping = 0x3
}

/// Protocol byte numbers
/// Protocol byte constants
@frozen
internal enum FKConnectionConstants: Int {
case opcode = 0x1
Expand Down
2 changes: 1 addition & 1 deletion Sources/FusionKit/Protocols/FKConnectionProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
import Network

internal protocol FKConnectionProtocol {
/// Access to connection State's
/// The `FKConnectionState` update values
var stateUpdateHandler: (FKConnectionState) -> Void { get set }

/// The `FKConnection` is a custom Network protocol implementation of the Fusion Framing Protocol.
Expand Down
3 changes: 1 addition & 2 deletions Tests/FusionKitTests/FusionKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ private enum TestCase {
}

class FusionKitTests: XCTestCase {
private var connection = FKConnection(host: "atonet.de", port: 7878)
private var connection = FKConnection(host: "weist.org", port: 7878)
private var buffer = "50000"
private let timeout = 10.0
private let uuid = UUID().uuidString
Expand Down Expand Up @@ -59,7 +59,6 @@ class FusionKitTests: XCTestCase {
XCTAssertEqual(FKConnectionError.missingHost.description, "missing host")
XCTAssertEqual(FKConnectionError.missingPort.description, "missing port")
XCTAssertEqual(FKConnectionError.connectionTimeout.description, "connection timeout")
XCTAssertEqual(FKConnectionError.connectionUnsatisfied.description, "connection path is not satisfied")
XCTAssertEqual(FKConnectionError.parsingFailed.description, "message parsing failed")
XCTAssertEqual(FKConnectionError.readBufferOverflow.description, "read buffer overflow")
XCTAssertEqual(FKConnectionError.writeBufferOverflow.description, "write buffer overflow")
Expand Down

0 comments on commit 87b92ba

Please sign in to comment.