diff --git a/Source/SocketAckManager.swift b/Source/SocketAckManager.swift index 972e1da..8143243 100644 --- a/Source/SocketAckManager.swift +++ b/Source/SocketAckManager.swift @@ -24,7 +24,7 @@ import Foundation -private struct SocketAck : Hashable, Equatable { +private struct SocketAck : Hashable { let ack: Int var callback: AckCallback! var hashValue: Int { diff --git a/Source/SocketClientManager.swift b/Source/SocketClientManager.swift index 3cf1c34..ae79179 100644 --- a/Source/SocketClientManager.swift +++ b/Source/SocketClientManager.swift @@ -66,7 +66,7 @@ public final class SocketClientManager : NSObject { return sockets.removeValueForKey(label) } - public func removeSocket(socket socket: SocketIOClient) -> SocketIOClient? { + public func removeSocket(socket: SocketIOClient) -> SocketIOClient? { var returnSocket: SocketIOClient? for (label, dictSocket) in sockets where dictSocket === socket { diff --git a/Source/SocketEnginePollable.swift b/Source/SocketEnginePollable.swift index e8d1718..77dc7f6 100644 --- a/Source/SocketEnginePollable.swift +++ b/Source/SocketEnginePollable.swift @@ -59,6 +59,8 @@ extension SocketEnginePollable { } func createRequestForPostWithPostWait() -> NSURLRequest { + defer { postWait.removeAll(keepCapacity: true) } + var postStr = "" for packet in postWait { @@ -69,18 +71,13 @@ extension SocketEnginePollable { DefaultSocketLogger.Logger.log("Created POST string: %@", type: "SocketEnginePolling", args: postStr) - postWait.removeAll(keepCapacity: false) - let req = NSMutableURLRequest(URL: urlPollingWithSid) + let postData = postStr.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)! addHeaders(req) req.HTTPMethod = "POST" req.setValue("text/plain; charset=UTF-8", forHTTPHeaderField: "Content-Type") - - let postData = postStr.dataUsingEncoding(NSUTF8StringEncoding, - allowLossyConversion: false)! - req.HTTPBody = postData req.setValue(String(postData.length), forHTTPHeaderField: "Content-Length") @@ -88,11 +85,10 @@ extension SocketEnginePollable { } public func doPoll() { - if websocket || waitingForPoll || !connected || closed { - return - } + if websocket || waitingForPoll || !connected || closed { return } waitingForPoll = true + let req = NSMutableURLRequest(URL: urlPollingWithSid) addHeaders(req)