Dispose tunnel if can't try next protocol

Return boolean in socketShouldChangeProtocol indicating whether
another protocol is available.
This commit is contained in:
Davide De Rosa 2018-09-07 22:42:26 +02:00
parent de09d0b5da
commit 8adb9871c3
3 changed files with 5 additions and 4 deletions

View File

@ -44,7 +44,7 @@ protocol LinkProducer {
protocol GenericSocketDelegate: class { protocol GenericSocketDelegate: class {
func socketDidTimeout(_ socket: GenericSocket) func socketDidTimeout(_ socket: GenericSocket)
func socketShouldChangeProtocol(_ socket: GenericSocket) func socketShouldChangeProtocol(_ socket: GenericSocket) -> Bool
func socketDidBecomeActive(_ socket: GenericSocket) func socketDidBecomeActive(_ socket: GenericSocket)

View File

@ -79,7 +79,7 @@ class NETCPSocket: NSObject, GenericSocket {
return return
} }
guard _self.isActive else { guard _self.isActive else {
_self.delegate?.socketShouldChangeProtocol(_self) _ = _self.delegate?.socketShouldChangeProtocol(_self)
_self.delegate?.socketDidTimeout(_self) _self.delegate?.socketDidTimeout(_self)
return return
} }

View File

@ -388,11 +388,12 @@ extension TunnelKitProvider: GenericSocketDelegate {
socket.shutdown() socket.shutdown()
} }
func socketShouldChangeProtocol(_ socket: GenericSocket) { func socketShouldChangeProtocol(_ socket: GenericSocket) -> Bool {
guard strategy.tryNextProtocol() else { guard strategy.tryNextProtocol() else {
disposeTunnel(error: ProviderError.exhaustedProtocols) disposeTunnel(error: ProviderError.exhaustedProtocols)
return return false
} }
return true
} }
func socketDidBecomeActive(_ socket: GenericSocket) { func socketDidBecomeActive(_ socket: GenericSocket) {