diff --git a/Sources/Transmission/Connection.swift b/Sources/Transmission/Connection.swift index 7966d94..1fbd773 100644 --- a/Sources/Transmission/Connection.swift +++ b/Sources/Transmission/Connection.swift @@ -45,13 +45,13 @@ public class Connection self.connectLock.leave() return case .cancelled: - self.connectLock.leave() + self.failConnect() return case .failed(_): - self.connectLock.leave() + self.failConnect() return - case .waiting(let error): - self.connectLock.leave() + case .waiting(_): + self.failConnect() return default: return @@ -64,6 +64,13 @@ public class Connection guard success else {return nil} } + + func failConnect() + { + self.connection.stateUpdateHandler = nil + self.connection.cancel() + self.connectLock.leave() + } public func read(size: Int) -> Data? {