Split connected and out of tries
This commit is contained in:
parent
c4ebc2f3cd
commit
940e264668
@ -407,21 +407,25 @@ class SocketIOClient: NSObject, SRWebSocketDelegate {
|
|||||||
|
|
||||||
// We lost connection and should attempt to reestablish
|
// We lost connection and should attempt to reestablish
|
||||||
private func tryReconnect(#triesLeft:Int) {
|
private func tryReconnect(#triesLeft:Int) {
|
||||||
if (self.connected || triesLeft <= 0) {
|
if (triesLeft <= 0) {
|
||||||
self.connecting = false
|
self.connecting = false
|
||||||
self.reconnnects = false
|
self.reconnnects = false
|
||||||
self.reconnecting = false
|
self.reconnecting = false
|
||||||
self.handleEvent(event: "disconnect", data: "Failed to reconnect")
|
self.handleEvent(event: "disconnect", data: "Failed to reconnect")
|
||||||
return
|
return
|
||||||
|
} else if (self.connected) {
|
||||||
|
self.connecting = false
|
||||||
|
self.reconnnects = false
|
||||||
|
self.reconnecting = false
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// println("Trying to reconnect #\(reconnectAttempts - triesLeft)")
|
// println("Trying to reconnect #\(reconnectAttempts - triesLeft)")
|
||||||
|
|
||||||
self.reconnecting = true
|
|
||||||
let waitTime = UInt64(self.reconnectWait) * NSEC_PER_SEC
|
let waitTime = UInt64(self.reconnectWait) * NSEC_PER_SEC
|
||||||
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(waitTime))
|
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(waitTime))
|
||||||
|
|
||||||
// Wait reconnectWait and then check if connected. Repeat if not
|
// Wait reconnectWait seconds and then check if connected. Repeat if not
|
||||||
dispatch_after(time, dispatch_get_main_queue()) {[weak self] in
|
dispatch_after(time, dispatch_get_main_queue()) {[weak self] in
|
||||||
if (self == nil || self!.connected) {
|
if (self == nil || self!.connected) {
|
||||||
return
|
return
|
||||||
@ -429,6 +433,7 @@ class SocketIOClient: NSObject, SRWebSocketDelegate {
|
|||||||
|
|
||||||
self!.tryReconnect(triesLeft: triesLeft - 1)
|
self!.tryReconnect(triesLeft: triesLeft - 1)
|
||||||
}
|
}
|
||||||
|
self.reconnecting = true
|
||||||
self.connect()
|
self.connect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user