tweak closing engine

This commit is contained in:
Erik 2015-05-11 09:19:46 -04:00
parent d7d1da704f
commit 3abb26565b
2 changed files with 4 additions and 3 deletions

View File

@ -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.

View File

@ -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?) {