remove nstimer
This commit is contained in:
parent
a53b7167b6
commit
718caba9d9
@ -47,7 +47,6 @@ public final class SocketEngine: NSObject, SocketEnginePollable, SocketEngineWeb
|
|||||||
public private(set) var forcePolling = false
|
public private(set) var forcePolling = false
|
||||||
public private(set) var forceWebsockets = false
|
public private(set) var forceWebsockets = false
|
||||||
public private(set) var invalidated = false
|
public private(set) var invalidated = false
|
||||||
public private(set) var pingTimer: NSTimer?
|
|
||||||
public private(set) var polling = true
|
public private(set) var polling = true
|
||||||
public private(set) var probing = false
|
public private(set) var probing = false
|
||||||
public private(set) var session: NSURLSession?
|
public private(set) var session: NSURLSession?
|
||||||
@ -295,7 +294,6 @@ public final class SocketEngine: NSObject, SocketEnginePollable, SocketEngineWeb
|
|||||||
invalidated = true
|
invalidated = true
|
||||||
connected = false
|
connected = false
|
||||||
|
|
||||||
pingTimer?.invalidate()
|
|
||||||
ws?.disconnect()
|
ws?.disconnect()
|
||||||
stopPolling()
|
stopPolling()
|
||||||
client?.engineDidClose(reason)
|
client?.engineDidClose(reason)
|
||||||
@ -401,8 +399,7 @@ public final class SocketEngine: NSObject, SocketEnginePollable, SocketEngineWeb
|
|||||||
createWebsocketAndConnect()
|
createWebsocketAndConnect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sendPing()
|
||||||
startPingTimer()
|
|
||||||
|
|
||||||
if !forceWebsockets {
|
if !forceWebsockets {
|
||||||
doPoll()
|
doPoll()
|
||||||
@ -487,26 +484,24 @@ public final class SocketEngine: NSObject, SocketEnginePollable, SocketEngineWeb
|
|||||||
websocket = false
|
websocket = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc private func sendPing() {
|
private func sendPing() {
|
||||||
|
if !connected {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
//Server is not responding
|
//Server is not responding
|
||||||
if pongsMissed > pongsMissedMax {
|
if pongsMissed > pongsMissedMax {
|
||||||
pingTimer?.invalidate()
|
|
||||||
client?.engineDidClose("Ping timeout")
|
client?.engineDidClose("Ping timeout")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
pongsMissed += 1
|
|
||||||
write("", withType: .Ping, withData: [])
|
|
||||||
}
|
|
||||||
|
|
||||||
private func startPingTimer() {
|
|
||||||
if let pingInterval = pingInterval {
|
if let pingInterval = pingInterval {
|
||||||
pingTimer?.invalidate()
|
pongsMissed += 1
|
||||||
pingTimer = nil
|
write("", withType: .Ping, withData: [])
|
||||||
|
|
||||||
dispatch_async(dispatch_get_main_queue()) {
|
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(pingInterval * Double(NSEC_PER_SEC)))
|
||||||
self.pingTimer = NSTimer.scheduledTimerWithTimeInterval(pingInterval, target: self,
|
dispatch_after(time, dispatch_get_main_queue()) {[weak self] in
|
||||||
selector: #selector(SocketEngine.sendPing), userInfo: nil, repeats: true)
|
self?.sendPing()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -562,7 +557,6 @@ public final class SocketEngine: NSObject, SocketEnginePollable, SocketEngineWeb
|
|||||||
}
|
}
|
||||||
|
|
||||||
if websocket {
|
if websocket {
|
||||||
pingTimer?.invalidate()
|
|
||||||
connected = false
|
connected = false
|
||||||
websocket = false
|
websocket = false
|
||||||
|
|
||||||
|
|||||||
@ -37,7 +37,6 @@ import Foundation
|
|||||||
var forcePolling: Bool { get }
|
var forcePolling: Bool { get }
|
||||||
var forceWebsockets: Bool { get }
|
var forceWebsockets: Bool { get }
|
||||||
var parseQueue: dispatch_queue_t! { get }
|
var parseQueue: dispatch_queue_t! { get }
|
||||||
var pingTimer: NSTimer? { get }
|
|
||||||
var polling: Bool { get }
|
var polling: Bool { get }
|
||||||
var probing: Bool { get }
|
var probing: Bool { get }
|
||||||
var emitQueue: dispatch_queue_t! { get }
|
var emitQueue: dispatch_queue_t! { get }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user