From 72b65655108e78b233f559bfbed9bf387ee89ca5 Mon Sep 17 00:00:00 2001 From: Erik Date: Sat, 10 Sep 2016 10:12:37 -0400 Subject: [PATCH] refactors --- Source/SocketEngine.swift | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Source/SocketEngine.swift b/Source/SocketEngine.swift index 1baed43..1919f57 100644 --- a/Source/SocketEngine.swift +++ b/Source/SocketEngine.swift @@ -466,23 +466,22 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll } private func sendPing() { - if !connected { - return - } + guard connected else { return } - //Server is not responding + // Server is not responding if pongsMissed > pongsMissedMax { client?.engineDidClose(reason: "Ping timeout") + return } - if let pingInterval = pingInterval { - pongsMissed += 1 - write("", withType: .ping, withData: []) - - let time = DispatchTime.now() + Double(Int64(pingInterval * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC) - DispatchQueue.main.asyncAfter(deadline: time) {[weak self] in self?.sendPing() } - } + guard let pingInterval = pingInterval else { return } + + pongsMissed += 1 + write("", withType: .ping, withData: []) + + let time = DispatchTime.now() + Double(Int64(pingInterval * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC) + DispatchQueue.main.asyncAfter(deadline: time) {[weak self] in self?.sendPing() } } // Moves from long-polling to websockets @@ -532,6 +531,7 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll if closed { client?.engineDidClose(reason: "Disconnect") + return }