refactors

This commit is contained in:
Erik 2016-09-10 10:12:37 -04:00
parent 31adcd4728
commit 72b6565510
No known key found for this signature in database
GPG Key ID: 4930B7C5FBC1A69D

View File

@ -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
}