Make engine single queued

Fix polling

allow building of refactor branch

remove self reference

Some refactoring
This commit is contained in:
Erik 2017-05-03 22:48:25 -04:00
parent 7e494f4bcb
commit ed049e888d
No known key found for this signature in database
GPG Key ID: 4930B7C5FBC1A69D
4 changed files with 119 additions and 118 deletions

View File

@ -6,6 +6,7 @@ branches:
only: only:
- master - master
- development - development
- refactor-engine
before_install: before_install:
- brew update - brew update
- brew outdated xctool || brew upgrade xctool - brew outdated xctool || brew upgrade xctool

View File

@ -22,12 +22,11 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
import Dispatch
import Foundation import Foundation
public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, SocketEngineWebsocket { public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, SocketEngineWebsocket {
public let emitQueue = DispatchQueue(label: "com.socketio.engineEmitQueue", attributes: []) public let engineQueue = DispatchQueue(label: "com.socketio.engineHandleQueue", attributes: [])
public let handleQueue = DispatchQueue(label: "com.socketio.engineHandleQueue", attributes: [])
public let parseQueue = DispatchQueue(label: "com.socketio.engineParseQueue", attributes: [])
public var connectParams: [String: Any]? { public var connectParams: [String: Any]? {
didSet { didSet {
@ -101,7 +100,7 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
forceWebsockets = force forceWebsockets = force
case let .path(path): case let .path(path):
socketPath = path socketPath = path
if !socketPath.hasSuffix("/") { if !socketPath.hasSuffix("/") {
socketPath += "/" socketPath += "/"
} }
@ -119,12 +118,12 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
} }
super.init() super.init()
sessionDelegate = sessionDelegate ?? self sessionDelegate = sessionDelegate ?? self
(urlPolling, urlWebSocket) = createURLs() (urlPolling, urlWebSocket) = createURLs()
} }
public convenience init(client: SocketEngineClient, url: URL, options: NSDictionary?) { public convenience init(client: SocketEngineClient, url: URL, options: NSDictionary?) {
self.init(client: client, url: url, config: options?.toSocketConfiguration() ?? []) self.init(client: client, url: url, config: options?.toSocketConfiguration() ?? [])
} }
@ -139,7 +138,7 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
do { do {
let dict = try msg.toNSDictionary() let dict = try msg.toNSDictionary()
guard let error = dict["message"] as? String else { return } guard let error = dict["message"] as? String else { return }
/* /*
0: Unknown transport 0: Unknown transport
1: Unknown sid 1: Unknown sid
@ -155,7 +154,7 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
private func handleBase64(message: String) { private func handleBase64(message: String) {
// binary in base64 string // binary in base64 string
let noPrefix = message[message.index(message.startIndex, offsetBy: 2)..<message.endIndex] let noPrefix = message[message.index(message.startIndex, offsetBy: 2)..<message.endIndex]
if let data = NSData(base64Encoded: noPrefix, options: .ignoreUnknownCharacters) { if let data = NSData(base64Encoded: noPrefix, options: .ignoreUnknownCharacters) {
client?.parseEngineBinaryData(data as Data) client?.parseEngineBinaryData(data as Data)
} }
@ -174,6 +173,12 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
/// Starts the connection to the server /// Starts the connection to the server
public func connect() { public func connect() {
engineQueue.async {
self._connect()
}
}
private func _connect() {
if connected { if connected {
DefaultSocketLogger.Logger.error("Engine tried opening while connected. Assuming this was a reconnect", type: logType) DefaultSocketLogger.Logger.error("Engine tried opening while connected. Assuming this was a reconnect", type: logType)
disconnect(reason: "reconnect") disconnect(reason: "reconnect")
@ -191,8 +196,7 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
return return
} }
var reqPolling = URLRequest(url: urlPolling, cachePolicy: .reloadIgnoringLocalCacheData, var reqPolling = URLRequest(url: urlPolling, cachePolicy: .reloadIgnoringLocalCacheData, timeoutInterval: 60.0)
timeoutInterval: 60.0)
if cookies != nil { if cookies != nil {
let headers = HTTPCookie.requestHeaderFields(with: cookies!) let headers = HTTPCookie.requestHeaderFields(with: cookies!)
@ -216,7 +220,7 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
var urlPolling = URLComponents(string: url.absoluteString)! var urlPolling = URLComponents(string: url.absoluteString)!
var urlWebSocket = URLComponents(string: url.absoluteString)! var urlWebSocket = URLComponents(string: url.absoluteString)!
var queryString = "" var queryString = ""
urlWebSocket.path = socketPath urlWebSocket.path = socketPath
urlPolling.path = socketPath urlPolling.path = socketPath
@ -244,7 +248,6 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
} }
private func createWebsocketAndConnect() { private func createWebsocketAndConnect() {
ws?.delegate = nil ws?.delegate = nil
ws = WebSocket(url: urlWebSocketWithSid as URL) ws = WebSocket(url: urlWebSocketWithSid as URL)
@ -261,7 +264,7 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
} }
} }
ws?.callbackQueue = handleQueue ws?.callbackQueue = engineQueue
ws?.voipEnabled = voipEnabled ws?.voipEnabled = voipEnabled
ws?.delegate = self ws?.delegate = self
ws?.disableSSLCertValidation = selfSigned ws?.disableSSLCertValidation = selfSigned
@ -277,6 +280,12 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
} }
public func disconnect(reason: String) { public func disconnect(reason: String) {
engineQueue.async {
self._disconnect(reason: reason)
}
}
private func _disconnect(reason: String) {
guard connected else { return closeOutEngine(reason: reason) } guard connected else { return closeOutEngine(reason: reason) }
DefaultSocketLogger.Logger.log("Engine is being closed.", type: logType) DefaultSocketLogger.Logger.log("Engine is being closed.", type: logType)
@ -296,12 +305,10 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
// We need to take special care when we're polling that we send it ASAP // We need to take special care when we're polling that we send it ASAP
// Also make sure we're on the emitQueue since we're touching postWait // Also make sure we're on the emitQueue since we're touching postWait
private func disconnectPolling(reason: String) { private func disconnectPolling(reason: String) {
emitQueue.sync { postWait.append(String(SocketEnginePacketType.close.rawValue))
self.postWait.append(String(SocketEnginePacketType.close.rawValue))
let req = self.createRequestForPostWithPostWait() doRequest(for: createRequestForPostWithPostWait()) {_, _, _ in }
self.doRequest(for: req) {_, _, _ in } closeOutEngine(reason: reason)
self.closeOutEngine(reason: reason)
}
} }
public func doFastUpgrade() { public func doFastUpgrade() {
@ -321,16 +328,14 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
private func flushProbeWait() { private func flushProbeWait() {
DefaultSocketLogger.Logger.log("Flushing probe wait", type: logType) DefaultSocketLogger.Logger.log("Flushing probe wait", type: logType)
emitQueue.async { for waiter in probeWait {
for waiter in self.probeWait { write(waiter.msg, withType: waiter.type, withData: waiter.data)
self.write(waiter.msg, withType: waiter.type, withData: waiter.data) }
}
self.probeWait.removeAll(keepingCapacity: false) probeWait.removeAll(keepingCapacity: false)
if self.postWait.count != 0 { if postWait.count != 0 {
self.flushWaitingForPostToWebSocket() flushWaitingForPostToWebSocket()
}
} }
} }
@ -357,47 +362,47 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
private func handleNOOP() { private func handleNOOP() {
doPoll() doPoll()
} }
private func handleOpen(openData: String) { private func handleOpen(openData: String) {
guard let json = try? openData.toNSDictionary() else { guard let json = try? openData.toNSDictionary() else {
didError(reason: "Error parsing open packet") didError(reason: "Error parsing open packet")
return return
} }
guard let sid = json["sid"] as? String else { guard let sid = json["sid"] as? String else {
didError(reason: "Open packet contained no sid") didError(reason: "Open packet contained no sid")
return return
} }
let upgradeWs: Bool let upgradeWs: Bool
self.sid = sid self.sid = sid
connected = true connected = true
pongsMissed = 0 pongsMissed = 0
if let upgrades = json["upgrades"] as? [String] { if let upgrades = json["upgrades"] as? [String] {
upgradeWs = upgrades.contains("websocket") upgradeWs = upgrades.contains("websocket")
} else { } else {
upgradeWs = false upgradeWs = false
} }
if let pingInterval = json["pingInterval"] as? Double, let pingTimeout = json["pingTimeout"] as? Double { if let pingInterval = json["pingInterval"] as? Double, let pingTimeout = json["pingTimeout"] as? Double {
self.pingInterval = pingInterval / 1000.0 self.pingInterval = pingInterval / 1000.0
self.pingTimeout = pingTimeout / 1000.0 self.pingTimeout = pingTimeout / 1000.0
} }
if !forcePolling && !forceWebsockets && upgradeWs { if !forcePolling && !forceWebsockets && upgradeWs {
createWebsocketAndConnect() createWebsocketAndConnect()
} }
sendPing() sendPing()
if !forceWebsockets { if !forceWebsockets {
doPoll() doPoll()
} }
client?.engineDidOpen(reason: "Connect") client?.engineDidOpen(reason: "Connect")
} }
@ -421,14 +426,14 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
let reader = SocketStringReader(message: message) let reader = SocketStringReader(message: message)
let fixedString: String let fixedString: String
if message.hasPrefix("b4") { if message.hasPrefix("b4") {
return handleBase64(message: message) return handleBase64(message: message)
} }
guard let type = SocketEnginePacketType(rawValue: Int(reader.currentCharacter) ?? -1) else { guard let type = SocketEnginePacketType(rawValue: Int(reader.currentCharacter) ?? -1) else {
checkAndHandleEngineError(message) checkAndHandleEngineError(message)
return return
} }
@ -456,13 +461,16 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
// Puts the engine back in its default state // Puts the engine back in its default state
private func resetEngine() { private func resetEngine() {
let queue = OperationQueue()
queue.underlyingQueue = engineQueue
closed = false closed = false
connected = false connected = false
fastUpgrade = false fastUpgrade = false
polling = true polling = true
probing = false probing = false
invalidated = false invalidated = false
session = Foundation.URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: OperationQueue.main) session = Foundation.URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: queue)
sid = "" sid = ""
waitingForPoll = false waitingForPoll = false
waitingForPost = false waitingForPost = false
@ -475,17 +483,16 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
// Server is not responding // Server is not responding
if pongsMissed > pongsMissedMax { if pongsMissed > pongsMissedMax {
client?.engineDidClose(reason: "Ping timeout") client?.engineDidClose(reason: "Ping timeout")
return return
} }
guard let pingInterval = pingInterval else { return } guard let pingInterval = pingInterval else { return }
pongsMissed += 1 pongsMissed += 1
write("", withType: .ping, withData: []) write("", withType: .ping, withData: [])
let time = DispatchTime.now() + Double(Int64(pingInterval * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC) engineQueue.asyncAfter(deadline: DispatchTime.now() + Double(pingInterval)) {[weak self] in self?.sendPing() }
DispatchQueue.main.asyncAfter(deadline: time) {[weak self] in self?.sendPing() }
} }
// Moves from long-polling to websockets // Moves from long-polling to websockets
@ -501,16 +508,16 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
/// Write a message, independent of transport. /// Write a message, independent of transport.
public func write(_ msg: String, withType type: SocketEnginePacketType, withData data: [Data]) { public func write(_ msg: String, withType type: SocketEnginePacketType, withData data: [Data]) {
emitQueue.async { engineQueue.async {
guard self.connected else { return } guard self.connected else { return }
if self.websocket { if self.websocket {
DefaultSocketLogger.Logger.log("Writing ws: %@ has data: %@", DefaultSocketLogger.Logger.log("Writing ws: %@ has data: %@",
type: self.logType, args: msg, data.count != 0) type: self.logType, args: msg, data.count != 0)
self.sendWebSocketMessage(msg, withType: type, withData: data) self.sendWebSocketMessage(msg, withType: type, withData: data)
} else if !self.probing { } else if !self.probing {
DefaultSocketLogger.Logger.log("Writing poll: %@ has data: %@", DefaultSocketLogger.Logger.log("Writing poll: %@ has data: %@",
type: self.logType, args: msg, data.count != 0) type: self.logType, args: msg, data.count != 0)
self.sendPollMessage(msg, withType: type, withData: data) self.sendPollMessage(msg, withType: type, withData: data)
} else { } else {
self.probeWait.append((msg, type, data)) self.probeWait.append((msg, type, data))
@ -535,7 +542,7 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
if closed { if closed {
client?.engineDidClose(reason: "Disconnect") client?.engineDidClose(reason: "Disconnect")
return return
} }
@ -557,7 +564,7 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
extension SocketEngine { extension SocketEngine {
public func URLSession(session: URLSession, didBecomeInvalidWithError error: NSError?) { public func URLSession(session: URLSession, didBecomeInvalidWithError error: NSError?) {
DefaultSocketLogger.Logger.error("Engine URLSession became invalid", type: "SocketEngine") DefaultSocketLogger.Logger.error("Engine URLSession became invalid", type: "SocketEngine")
didError(reason: "Engine URLSession became invalid") didError(reason: "Engine URLSession became invalid")
} }
} }

View File

@ -27,7 +27,7 @@ import Foundation
/// Protocol that is used to implement socket.io polling support /// Protocol that is used to implement socket.io polling support
public protocol SocketEnginePollable : SocketEngineSpec { public protocol SocketEnginePollable : SocketEngineSpec {
var invalidated: Bool { get } var invalidated: Bool { get }
/// Holds strings waiting to be sent over polling. /// Holds strings waiting to be sent over polling.
/// You shouldn't need to mess with this. /// You shouldn't need to mess with this.
var postWait: [String] { get set } var postWait: [String] { get set }
var session: URLSession? { get } var session: URLSession? { get }
@ -37,7 +37,7 @@ public protocol SocketEnginePollable : SocketEngineSpec {
/// Because socket.io doesn't let you send two post request at the same time /// Because socket.io doesn't let you send two post request at the same time
/// we have to keep track if there's an outstanding post /// we have to keep track if there's an outstanding post
var waitingForPost: Bool { get set } var waitingForPost: Bool { get set }
func doPoll() func doPoll()
func sendPollMessage(_ message: String, withType type: SocketEnginePacketType, withData datas: [Data]) func sendPollMessage(_ message: String, withType type: SocketEnginePacketType, withData datas: [Data])
func stopPolling() func stopPolling()
@ -47,95 +47,94 @@ public protocol SocketEnginePollable : SocketEngineSpec {
extension SocketEnginePollable { extension SocketEnginePollable {
private func addHeaders(for req: URLRequest) -> URLRequest { private func addHeaders(for req: URLRequest) -> URLRequest {
var req = req var req = req
if cookies != nil { if cookies != nil {
let headers = HTTPCookie.requestHeaderFields(with: cookies!) let headers = HTTPCookie.requestHeaderFields(with: cookies!)
req.allHTTPHeaderFields = headers req.allHTTPHeaderFields = headers
} }
if extraHeaders != nil { if extraHeaders != nil {
for (headerName, value) in extraHeaders! { for (headerName, value) in extraHeaders! {
req.setValue(value, forHTTPHeaderField: headerName) req.setValue(value, forHTTPHeaderField: headerName)
} }
} }
return req return req
} }
func createRequestForPostWithPostWait() -> URLRequest { func createRequestForPostWithPostWait() -> URLRequest {
defer { postWait.removeAll(keepingCapacity: true) } defer { postWait.removeAll(keepingCapacity: true) }
var postStr = "" var postStr = ""
for packet in postWait { for packet in postWait {
let len = packet.characters.count let len = packet.characters.count
postStr += "\(len):\(packet)" postStr += "\(len):\(packet)"
} }
DefaultSocketLogger.Logger.log("Created POST string: %@", type: "SocketEnginePolling", args: postStr) DefaultSocketLogger.Logger.log("Created POST string: %@", type: "SocketEnginePolling", args: postStr)
var req = URLRequest(url: urlPollingWithSid) var req = URLRequest(url: urlPollingWithSid)
let postData = postStr.data(using: .utf8, allowLossyConversion: false)! let postData = postStr.data(using: .utf8, allowLossyConversion: false)!
req = addHeaders(for: req) req = addHeaders(for: req)
req.httpMethod = "POST" req.httpMethod = "POST"
req.setValue("text/plain; charset=UTF-8", forHTTPHeaderField: "Content-Type") req.setValue("text/plain; charset=UTF-8", forHTTPHeaderField: "Content-Type")
req.httpBody = postData req.httpBody = postData
req.setValue(String(postData.count), forHTTPHeaderField: "Content-Length") req.setValue(String(postData.count), forHTTPHeaderField: "Content-Length")
return req as URLRequest return req
} }
public func doPoll() { public func doPoll() {
if websocket || waitingForPoll || !connected || closed { if websocket || waitingForPoll || !connected || closed {
return return
} }
waitingForPoll = true
var req = URLRequest(url: urlPollingWithSid) var req = URLRequest(url: urlPollingWithSid)
req = addHeaders(for: req) req = addHeaders(for: req)
doLongPoll(for: req ) doLongPoll(for: req )
} }
func doRequest(for req: URLRequest, callbackWith callback: @escaping (Data?, URLResponse?, Error?) -> Void) { func doRequest(for req: URLRequest, callbackWith callback: @escaping (Data?, URLResponse?, Error?) -> Void) {
if !polling || closed || invalidated || fastUpgrade { if !polling || closed || invalidated || fastUpgrade {
return return
} }
DefaultSocketLogger.Logger.log("Doing polling request", type: "SocketEnginePolling") DefaultSocketLogger.Logger.log("Doing polling %@ %@", type: "SocketEnginePolling",
args: req.httpMethod ?? "", req)
session?.dataTask(with: req, completionHandler: callback).resume() session?.dataTask(with: req, completionHandler: callback).resume()
} }
func doLongPoll(for req: URLRequest) { func doLongPoll(for req: URLRequest) {
waitingForPoll = true
doRequest(for: req) {[weak self] data, res, err in doRequest(for: req) {[weak self] data, res, err in
guard let this = self, this.polling else { return } guard let this = self, this.polling else { return }
if err != nil || data == nil { if err != nil || data == nil {
DefaultSocketLogger.Logger.error(err?.localizedDescription ?? "Error", type: "SocketEnginePolling") DefaultSocketLogger.Logger.error(err?.localizedDescription ?? "Error", type: "SocketEnginePolling")
if this.polling { if this.polling {
this.didError(reason: err?.localizedDescription ?? "Error") this.didError(reason: err?.localizedDescription ?? "Error")
} }
return return
} }
DefaultSocketLogger.Logger.log("Got polling response", type: "SocketEnginePolling") DefaultSocketLogger.Logger.log("Got polling response", type: "SocketEnginePolling")
if let str = String(data: data!, encoding: String.Encoding.utf8) { if let str = String(data: data!, encoding: String.Encoding.utf8) {
this.parseQueue.async { this.parsePollingMessage(str)
this.parsePollingMessage(str)
}
} }
this.waitingForPoll = false this.waitingForPoll = false
if this.fastUpgrade { if this.fastUpgrade {
this.doFastUpgrade() this.doFastUpgrade()
} else if !this.closed && this.polling { } else if !this.closed && this.polling {
@ -143,7 +142,7 @@ extension SocketEnginePollable {
} }
} }
} }
private func flushWaitingForPost() { private func flushWaitingForPost() {
if postWait.count == 0 || !connected { if postWait.count == 0 || !connected {
return return
@ -151,79 +150,75 @@ extension SocketEnginePollable {
flushWaitingForPostToWebSocket() flushWaitingForPostToWebSocket()
return return
} }
let req = createRequestForPostWithPostWait() let req = createRequestForPostWithPostWait()
waitingForPost = true waitingForPost = true
DefaultSocketLogger.Logger.log("POSTing", type: "SocketEnginePolling") DefaultSocketLogger.Logger.log("POSTing", type: "SocketEnginePolling")
doRequest(for: req) {[weak self] data, res, err in doRequest(for: req) {[weak self] data, res, err in
guard let this = self else { return } guard let this = self else { return }
if err != nil { if err != nil {
DefaultSocketLogger.Logger.error(err?.localizedDescription ?? "Error", type: "SocketEnginePolling") DefaultSocketLogger.Logger.error(err?.localizedDescription ?? "Error", type: "SocketEnginePolling")
if this.polling { if this.polling {
this.didError(reason: err?.localizedDescription ?? "Error") this.didError(reason: err?.localizedDescription ?? "Error")
} }
return return
} }
this.waitingForPost = false this.waitingForPost = false
this.emitQueue.async { if !this.fastUpgrade {
if !this.fastUpgrade { this.flushWaitingForPost()
this.flushWaitingForPost() this.doPoll()
this.doPoll()
}
} }
} }
} }
func parsePollingMessage(_ str: String) { func parsePollingMessage(_ str: String) {
guard str.characters.count != 1 else { return } guard str.characters.count != 1 else { return }
var reader = SocketStringReader(message: str) var reader = SocketStringReader(message: str)
while reader.hasNext { while reader.hasNext {
if let n = Int(reader.readUntilOccurence(of: ":")) { if let n = Int(reader.readUntilOccurence(of: ":")) {
let str = reader.read(count: n) parseEngineMessage(reader.read(count: n), fromPolling: true)
handleQueue.async { self.parseEngineMessage(str, fromPolling: true) }
} else { } else {
handleQueue.async { self.parseEngineMessage(str, fromPolling: true) } parseEngineMessage(str, fromPolling: true)
break break
} }
} }
} }
/// Send polling message. /// Send polling message.
/// Only call on emitQueue /// Only call on emitQueue
public func sendPollMessage(_ message: String, withType type: SocketEnginePacketType, withData datas: [Data]) { public func sendPollMessage(_ message: String, withType type: SocketEnginePacketType, withData datas: [Data]) {
DefaultSocketLogger.Logger.log("Sending poll: %@ as type: %@", type: "SocketEnginePolling", args: message, type.rawValue) DefaultSocketLogger.Logger.log("Sending poll: %@ as type: %@", type: "SocketEnginePolling", args: message, type.rawValue)
let fixedMessage: String let fixedMessage: String
if doubleEncodeUTF8 { if doubleEncodeUTF8 {
fixedMessage = doubleEncodeUTF8(message) fixedMessage = doubleEncodeUTF8(message)
} else { } else {
fixedMessage = message fixedMessage = message
} }
postWait.append(String(type.rawValue) + fixedMessage) postWait.append(String(type.rawValue) + fixedMessage)
for data in datas { for data in datas {
if case let .right(bin) = createBinaryDataForSend(using: data) { if case let .right(bin) = createBinaryDataForSend(using: data) {
postWait.append(bin) postWait.append(bin)
} }
} }
if !waitingForPost { if !waitingForPost {
flushWaitingForPost() flushWaitingForPost()
} }
} }
public func stopPolling() { public func stopPolling() {
waitingForPoll = false waitingForPoll = false
waitingForPost = false waitingForPost = false

View File

@ -32,15 +32,13 @@ import Foundation
var connectParams: [String: Any]? { get set } var connectParams: [String: Any]? { get set }
var doubleEncodeUTF8: Bool { get } var doubleEncodeUTF8: Bool { get }
var cookies: [HTTPCookie]? { get } var cookies: [HTTPCookie]? { get }
var engineQueue: DispatchQueue { get }
var extraHeaders: [String: String]? { get } var extraHeaders: [String: String]? { get }
var fastUpgrade: Bool { get } var fastUpgrade: Bool { get }
var forcePolling: Bool { get } var forcePolling: Bool { get }
var forceWebsockets: Bool { get } var forceWebsockets: Bool { get }
var parseQueue: DispatchQueue { get }
var polling: Bool { get } var polling: Bool { get }
var probing: Bool { get } var probing: Bool { get }
var emitQueue: DispatchQueue { get }
var handleQueue: DispatchQueue { get }
var sid: String { get } var sid: String { get }
var socketPath: String { get } var socketPath: String { get }
var urlPolling: URL { get } var urlPolling: URL { get }