Merge branch 'master' into swift-2

* master:
  Invalidate timer on reconnect failure
  fix socketio/socket.io-client-swift#110 calling close while trying to reconnect
This commit is contained in:
Erik 2015-07-03 14:07:03 -04:00
commit 422b93f577

View File

@ -135,6 +135,11 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
engine = SocketEngine(client: self, opts: opts) engine = SocketEngine(client: self, opts: opts)
} }
private func clearReconnectTimer() {
reconnectTimer?.invalidate()
reconnectTimer = nil
}
/** /**
Closes the socket. Only reopen the same socket if you know what you're doing. Closes the socket. Only reopen the same socket if you know what you're doing.
Will turn off automatic reconnects. Will turn off automatic reconnects.
@ -218,8 +223,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
_connecting = false _connecting = false
_reconnecting = false _reconnecting = false
currentReconnectAttempt = 0 currentReconnectAttempt = 0
reconnectTimer?.invalidate() clearReconnectTimer()
reconnectTimer = nil
// Don't handle as internal because something crazy could happen where // Don't handle as internal because something crazy could happen where
// we disconnect before it's handled // we disconnect before it's handled
@ -469,8 +473,10 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
// We lost connection and should attempt to reestablish // We lost connection and should attempt to reestablish
@objc private func tryReconnect() { @objc private func tryReconnect() {
if reconnectAttempts != -1 && currentReconnectAttempt + 1 > reconnectAttempts { if reconnectAttempts != -1 && currentReconnectAttempt + 1 > reconnectAttempts || !reconnects {
clearReconnectTimer()
didDisconnect("Reconnect Failed") didDisconnect("Reconnect Failed")
return return
} else if connected { } else if connected {
_connecting = false _connecting = false