Skip to content

Commit cc99eae

Browse files
committed
Add messages for socket/engine deinit
1 parent 446cf57 commit cc99eae

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

SocketIOClientSwift/SocketEngine.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
104104
delegate: sessionDelegate, delegateQueue: self.workQueue)
105105
}
106106

107+
deinit {
108+
SocketLogger.log("Engine is being deinit", client: self)
109+
}
110+
107111
public func close(#fast:Bool) {
108112
self.pingTimer?.invalidate()
109113
self.closed = true

SocketIOClientSwift/SocketIOClient.swift

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
6262
return self._connecting
6363
}
6464
public var cookies:[NSHTTPCookie]?
65-
public var engine:SocketEngine?
65+
public var engine:SocketEngine!
6666
public var nsp = "/"
6767
public var reconnects = true
6868
public var reconnecting:Bool {
@@ -143,6 +143,10 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
143143
self.init(socketURL: socketURL, opts: options)
144144
}
145145

146+
deinit {
147+
SocketLogger.log("Client is being deinit", client: self)
148+
}
149+
146150
private func addEngine() {
147151
SocketLogger.log("Adding engine", client: self)
148152

@@ -166,7 +170,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
166170
self._connecting = false
167171
self._connected = false
168172
self._reconnecting = false
169-
self.engine?.close(fast: fast)
173+
self.engine.close(fast: fast)
170174
}
171175

172176
/**
@@ -183,7 +187,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
183187
}
184188

185189
self.addEngine()
186-
self.engine?.open()
190+
self.engine.open()
187191
}
188192

189193
/**
@@ -203,7 +207,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
203207
self.paramConnect = true
204208

205209
self.addEngine()
206-
self.engine?.open(opts: params)
210+
self.engine.open(opts: params)
207211
}
208212

209213
private func createOnAck(event:String, items:[AnyObject]) -> OnAckCallback {
@@ -238,7 +242,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
238242
self.currentReconnectAttempt = 0
239243
self.reconnectTimer?.invalidate()
240244
self.reconnectTimer = nil
241-
self._sid = self.engine?.sid
245+
self._sid = self.engine.sid
242246

243247
// Don't handle as internal because something crazy could happen where
244248
// we disconnect before it's handled
@@ -323,9 +327,9 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
323327
SocketLogger.log("Emitting: \(str)", client: self)
324328

325329
if packet.type == SocketPacket.PacketType.BINARY_EVENT {
326-
self.engine?.send(str, withData: packet.binary)
330+
self.engine.send(str, withData: packet.binary)
327331
} else {
328-
self.engine?.send(str, withData: nil)
332+
self.engine.send(str, withData: nil)
329333
}
330334
}
331335

@@ -343,11 +347,11 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
343347
str = packet.createAck()
344348

345349
SocketLogger.log("Emitting Ack: \(str)", client: self!)
346-
350+
347351
if packet.type == SocketPacket.PacketType.BINARY_ACK {
348-
self?.engine?.send(str, withData: packet.binary)
352+
self?.engine.send(str, withData: packet.binary)
349353
} else {
350-
self?.engine?.send(str, withData: nil)
354+
self?.engine.send(str, withData: nil)
351355
}
352356
}
353357
}
@@ -409,7 +413,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
409413
SocketLogger.log("Joining namespace", client: self)
410414

411415
if self.nsp != "/" {
412-
self.engine?.send("0/\(self.nsp)", withData: nil)
416+
self.engine.send("0/\(self.nsp)", withData: nil)
413417
}
414418
}
415419

SocketIOClientSwift/SocketLogger.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ final class SocketLogger {
3737
return
3838
}
3939

40-
dispatch_async(printQueue) {
41-
NSLog("%@: %@", altType ?? client.logType, message)
40+
dispatch_async(printQueue) {[type = client.logType] in
41+
NSLog("%@: %@", altType ?? type, message)
4242
}
4343
}
4444

@@ -47,7 +47,7 @@ final class SocketLogger {
4747
return
4848
}
4949

50-
dispatch_async(printQueue) {
50+
dispatch_async(printQueue) {[type = client.logType] in
5151
NSLog("ERROR %@: %@", altType ?? client.logType, message)
5252
}
5353
}

SocketIOClientSwift/SwiftRegex.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public class SwiftRegex: NSObject, BooleanType {
152152
pos = matchRange.location + matchRange.length
153153
}
154154

155-
out.appendString(substring( NSRange(location:pos, length:targetRange.length-pos))!)
155+
out.appendString(substring(NSRange(location:pos, length:targetRange.length-pos))!)
156156

157157
return out as String
158158
}

0 commit comments

Comments
 (0)