This commit is contained in:
Erik 2016-08-28 08:29:00 -04:00
parent c7c824c3c5
commit 2200972f4d
No known key found for this signature in database
GPG Key ID: 4930B7C5FBC1A69D

View File

@ -67,7 +67,7 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable
return nsp + "#" + (engine?.sid ?? "")
}
/// Type safe way to create a new SocketIOClient. opts can be omitted
/// Type safe way to create a new SocketIOClient. config can be omitted
public init(socketURL: NSURL, config: SocketIOClientConfiguration = []) {
self.config = config
self.socketURL = socketURL
@ -150,12 +150,12 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(timeoutAfter) * Int64(NSEC_PER_SEC))
dispatch_after(time, handleQueue) {[weak self] in
if let this = self where this.status != .Connected && this.status != .Disconnected {
this.status = .Disconnected
this.engine?.disconnect("Connect timeout")
guard let this = self where this.status != .Connected && this.status != .Disconnected else { return }
handler?()
}
this.status = .Disconnected
this.engine?.disconnect("Connect timeout")
handler?()
}
}
@ -163,20 +163,20 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable
currentAck += 1
return {[weak self, ack = currentAck] timeout, callback in
if let this = self {
dispatch_sync(this.ackQueue) {
this.ackHandlers.addAck(ack, callback: callback)
}
guard let this = self else { return }
dispatch_sync(this.ackQueue) {
this.ackHandlers.addAck(ack, callback: callback)
}
this._emit(items, ack: ack)
this._emit(items, ack: ack)
if timeout != 0 {
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(timeout * NSEC_PER_SEC))
if timeout != 0 {
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(timeout * NSEC_PER_SEC))
dispatch_after(time, this.ackQueue) {
this.ackHandlers.timeoutAck(ack, onQueue: this.handleQueue)
}
dispatch_after(time, this.ackQueue) {
this.ackHandlers.timeoutAck(ack, onQueue: this.handleQueue)
}
}
}
@ -196,6 +196,7 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable
DefaultSocketLogger.Logger.log("Disconnected: %@", type: logType, args: reason)
reconnecting = false
status = .Disconnected
// Make sure the engine is actually dead.
@ -205,8 +206,6 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable
/// Disconnects the socket.
public func disconnect() {
assert(status != .NotConnected, "Tried closing a NotConnected client")
DefaultSocketLogger.Logger.log("Closing socket", type: logType)
didDisconnect("Disconnect")