From 3abb26565bdb721c5f0a83a7729606656196e6ba Mon Sep 17 00:00:00 2001 From: Erik Date: Mon, 11 May 2015 09:19:46 -0400 Subject: [PATCH] tweak closing engine --- README.md | 2 +- SocketIOClientSwift/SocketEngine.swift | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e27c80b..c7ba2d6 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ Methods 5. `emitWithAck(event:String, _ items:AnyObject...) -> (timeout:UInt64, callback:(NSArray?) -> Void) -> Void` - Sends a message that requests an acknowledgement from the server. Returns a function which you can use to add a handler. See example. Note: The message is not sent until you call the returned function. 6. `emitWithAck(event:String, withItems items:[AnyObject]) -> (UInt64, (NSArray?) -> Void) -> Void` - `emitWithAck` for Objective-C. Note: The message is not sent until you call the returned function. 7. `connect()` - Establishes a connection to the server. A "connect" event is fired upon successful connection. -8. `connect(#timeoutAfter:Int, withTimeoutHandler handler:(() -> Void)?)` - Connect to the server. If it isn't connect after timeoutAfter seconds, the handler is called. +8. `connect(#timeoutAfter:Int, withTimeoutHandler handler:(() -> Void)?)` - Connect to the server. If it isn't connected after timeoutAfter seconds, the handler is called. 9. `close(#fast:Bool)` - Closes the socket. Once a socket is closed it should not be reopened. Pass true to fast if you're closing from a background task. 10. `reconnect()` - Causes the client to reconnect to the server. diff --git a/SocketIOClientSwift/SocketEngine.swift b/SocketIOClientSwift/SocketEngine.swift index cb6861f..629e8fc 100644 --- a/SocketIOClientSwift/SocketEngine.swift +++ b/SocketIOClientSwift/SocketEngine.swift @@ -119,13 +119,14 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient { self.pingTimer?.invalidate() self.closed = true - self.write("", withType: PacketType.CLOSE, withData: nil) self.ws?.disconnect() - self.stopPolling() if fast || self.polling { + self.write("", withType: PacketType.CLOSE, withData: nil) self.client?.engineDidClose("Disconnect") } + + self.stopPolling() } private func createBinaryDataForSend(data:NSData) -> (NSData?, String?) {