Skip to content

Commit 93f1cfe

Browse files
committed
fix #36
1 parent da1cf9e commit 93f1cfe

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

SwiftIO/SocketEngine.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public class SocketEngine: NSObject, WebSocketDelegate {
164164
self.ws = WebSocket(url: NSURL(string: self.urlWebSocket! + "&sid=\(self.sid)")!)
165165
self.ws?.queue = self.handleQueue
166166
self.ws?.delegate = self
167-
167+
168168
if connect {
169169
self.ws?.connect()
170170
}
@@ -184,16 +184,19 @@ public class SocketEngine: NSObject, WebSocketDelegate {
184184
}
185185

186186
self.waitingForPoll = true
187-
let req = NSURLRequest(URL: NSURL(string: self.urlPolling! + "&sid=\(self.sid)&b64=1")!)
187+
let req = NSMutableURLRequest(URL: NSURL(string: self.urlPolling! + "&sid=\(self.sid)&b64=1")!)
188188

189189
self.doRequest(req)
190190
}
191191

192-
private func doRequest(req:NSURLRequest) {
192+
private func doRequest(req:NSMutableURLRequest) {
193193
if !self.polling {
194194
return
195195
}
196196

197+
req.cachePolicy = NSURLRequestCachePolicy.ReloadIgnoringLocalAndRemoteCacheData
198+
199+
// NSLog("Doing request: \(req)")
197200
self.session.dataTaskWithRequest(req) {[weak self] data, res, err in
198201
if self == nil {
199202
return
@@ -205,7 +208,7 @@ public class SocketEngine: NSObject, WebSocketDelegate {
205208
return
206209
}
207210

208-
// println(data)
211+
// NSLog("Got response: \(res)")
209212

210213
if let str = NSString(data: data, encoding: NSUTF8StringEncoding) as? String {
211214
dispatch_async(self!.parseQueue) {
@@ -219,7 +222,7 @@ public class SocketEngine: NSObject, WebSocketDelegate {
219222
if self!.fastUpgrade {
220223
self?.doFastUpgrade()
221224
return
222-
} else if !self!.closed {
225+
} else if !self!.closed && !self!.websocket {
223226
self?.doPoll()
224227
}
225228
}.resume()
@@ -369,6 +372,7 @@ public class SocketEngine: NSObject, WebSocketDelegate {
369372
length += chr
370373
} else {
371374
if length == "" || testLength(length, &n) {
375+
NSLog("parsing error: \(str)")
372376
self.handlePollingFailed("Error parsing XHR message")
373377
return
374378
}
@@ -377,7 +381,7 @@ public class SocketEngine: NSObject, WebSocketDelegate {
377381

378382
if let lengthInt = length.toInt() {
379383
if lengthInt != msg.length {
380-
println("parsing error")
384+
NSLog("parsing error: \(str)")
381385
return
382386
}
383387
}

0 commit comments

Comments
 (0)