From feb476c76bd9dcf67dde754bf27c0073d7259366 Mon Sep 17 00:00:00 2001 From: Erasov Ivan Date: Thu, 7 Jun 2018 13:42:13 +0300 Subject: [PATCH] Added comments to document changes reasons --- Source/SocketIO/Engine/SocketEngine.swift | 6 +++++- Source/SocketIO/Manager/SocketManager.swift | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Source/SocketIO/Engine/SocketEngine.swift b/Source/SocketIO/Engine/SocketEngine.swift index 0000de2..bca0944 100644 --- a/Source/SocketIO/Engine/SocketEngine.swift +++ b/Source/SocketIO/Engine/SocketEngine.swift @@ -359,6 +359,7 @@ open class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, So /// /// **You shouldn't call this directly** open func doFastUpgrade() { + if waitingForPoll { DefaultSocketLogger.Logger.error("Outstanding poll when switched to WebSockets," + "we'll probably disconnect soon. You should report this.", type: SocketEngine.logType) @@ -371,7 +372,10 @@ open class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, So fastUpgrade = false probing = false flushProbeWait() - if postWait.count != 0 { + + // Need to flush postWait to socket since it connected successfully + // (moved from flushProbeWait() since it is also called on connected failure) + if !postWait.isEmpty { flushWaitingForPostToWebSocket() } } diff --git a/Source/SocketIO/Manager/SocketManager.swift b/Source/SocketIO/Manager/SocketManager.swift index 571bf8d..830bf93 100644 --- a/Source/SocketIO/Manager/SocketManager.swift +++ b/Source/SocketIO/Manager/SocketManager.swift @@ -168,7 +168,10 @@ open class SocketManager : NSObject, SocketManagerSpec, SocketParsable, SocketDa DefaultSocketLogger.Logger.log("Adding engine", type: SocketManager.logType) engine?.engineQueue.sync { + self.engine?.client = nil + + // Close old engine so it will not leak because of URLSession if in polling mode self.engine?.disconnect(reason: "Adding new engine") }