Fix Xcode 8 Beta 3 issues/warnings
This commit is contained in:
parent
f214de1407
commit
777fa30c76
@ -151,8 +151,7 @@ public final class SocketEngine : NSObject, SocketEnginePollable, SocketEngineWe
|
||||
if message.hasPrefix("b4") {
|
||||
// binary in base64 string
|
||||
let noPrefix = message[message.characters.index(message.startIndex, offsetBy: 2)..<message.endIndex]
|
||||
|
||||
if let data = Data(base64Encoded: noPrefix, options: Data.Base64EncodingOptions(rawValue: 0)) {
|
||||
if let data = Data(base64Encoded: noPrefix, options: Data.Base64DecodingOptions(rawValue: 0)) {
|
||||
client?.parseEngineBinaryData(data)
|
||||
}
|
||||
|
||||
@ -372,7 +371,7 @@ public final class SocketEngine : NSObject, SocketEnginePollable, SocketEngineWe
|
||||
upgradeWs = false
|
||||
}
|
||||
|
||||
if let pingInterval = json["pingInterval"] as? Double, pingTimeout = json["pingTimeout"] as? Double {
|
||||
if let pingInterval = json["pingInterval"] as? Double, let pingTimeout = json["pingTimeout"] as? Double {
|
||||
self.pingInterval = pingInterval / 1000.0
|
||||
self.pingTimeout = pingTimeout / 1000.0
|
||||
}
|
||||
|
||||
@ -113,7 +113,7 @@ extension SocketEnginePollable {
|
||||
|
||||
func doLongPoll(for req: URLRequest) {
|
||||
doRequest(for: req) {[weak self] data, res, err in
|
||||
guard let this = self where this.polling else { return }
|
||||
guard let this = self, this.polling else { return }
|
||||
|
||||
if err != nil || data == nil {
|
||||
DefaultSocketLogger.Logger.error(err?.localizedDescription ?? "Error", type: "SocketEnginePolling")
|
||||
|
||||
@ -92,7 +92,7 @@ extension SocketEngineSpec {
|
||||
|
||||
func doubleEncodeUTF8(_ string: String) -> String {
|
||||
if let latin1 = string.data(using: String.Encoding.utf8),
|
||||
utf8 = NSString(data: latin1, encoding: String.Encoding.isoLatin1.rawValue) {
|
||||
let utf8 = NSString(data: latin1, encoding: String.Encoding.isoLatin1.rawValue) {
|
||||
return utf8 as String
|
||||
} else {
|
||||
return string
|
||||
@ -101,7 +101,7 @@ extension SocketEngineSpec {
|
||||
|
||||
func fixDoubleUTF8(_ string: String) -> String {
|
||||
if let utf8 = string.data(using: String.Encoding.isoLatin1),
|
||||
latin1 = NSString(data: utf8, encoding: String.Encoding.utf8.rawValue) {
|
||||
let latin1 = NSString(data: utf8, encoding: String.Encoding.utf8.rawValue) {
|
||||
return latin1 as String
|
||||
} else {
|
||||
return string
|
||||
|
||||
@ -150,7 +150,7 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable
|
||||
let time = DispatchTime.now() + Double(Int64(timeoutAfter) * Int64(NSEC_PER_SEC)) / Double(NSEC_PER_SEC)
|
||||
|
||||
handleQueue.after(when: time) {[weak self] in
|
||||
if let this = self where this.status != .connected && this.status != .disconnected {
|
||||
if let this = self, this.status != .connected && this.status != .disconnected {
|
||||
this.status = .disconnected
|
||||
this.engine?.disconnect(reason: "Connect timeout")
|
||||
|
||||
|
||||
@ -217,7 +217,7 @@ extension NSDictionary {
|
||||
var options = Set<SocketIOClientOption>()
|
||||
|
||||
for (rawKey, value) in self {
|
||||
if let key = rawKey as? String, opt = NSDictionary.keyValueToSocketIOClientOption(key, value: value) {
|
||||
if let key = rawKey as? String, let opt = NSDictionary.keyValueToSocketIOClientOption(key, value: value) {
|
||||
options.insertIgnore(opt)
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,7 +96,7 @@ public class SSLSecurity : NSObject {
|
||||
DispatchQueue.global(attributes: DispatchQueue.GlobalAttributes.qosDefault).async {
|
||||
let pubKeys = certs.reduce([SecKey]()) { (pubKeys: [SecKey], cert: SSLCert) -> [SecKey] in
|
||||
var pubKeys = pubKeys
|
||||
if let data = cert.certData where cert.key == nil {
|
||||
if let data = cert.certData, cert.key == nil {
|
||||
cert.key = self.extractPublicKey(data)
|
||||
}
|
||||
if let key = cert.key {
|
||||
|
||||
@ -305,7 +305,7 @@ public class WebSocket : NSObject, StreamDelegate {
|
||||
}
|
||||
if let cipherSuites = self.enabledSSLCipherSuites {
|
||||
if let sslContextIn = CFReadStreamCopyProperty(inputStream, CFStreamPropertyKey(rawValue: kCFStreamPropertySSLContext)) as! SSLContext?,
|
||||
sslContextOut = CFWriteStreamCopyProperty(outputStream, CFStreamPropertyKey(rawValue: kCFStreamPropertySSLContext)) as! SSLContext? {
|
||||
let sslContextOut = CFWriteStreamCopyProperty(outputStream, CFStreamPropertyKey(rawValue: kCFStreamPropertySSLContext)) as! SSLContext? {
|
||||
let resIn = SSLSetEnabledCiphers(sslContextIn, cipherSuites, cipherSuites.count)
|
||||
let resOut = SSLSetEnabledCiphers(sslContextOut, cipherSuites, cipherSuites.count)
|
||||
if resIn != errSecSuccess {
|
||||
@ -349,7 +349,7 @@ public class WebSocket : NSObject, StreamDelegate {
|
||||
|
||||
//delegate for the stream methods. Processes incoming bytes
|
||||
public func stream(_ aStream: Stream, handle eventCode: Stream.Event) {
|
||||
if let sec = security where !certValidated && [.hasBytesAvailable, .hasSpaceAvailable].contains(eventCode) {
|
||||
if let sec = security, !certValidated && [.hasBytesAvailable, .hasSpaceAvailable].contains(eventCode) {
|
||||
let possibleTrust: AnyObject? = aStream.property(forKey: kCFStreamPropertySSLPeerTrust as Stream.PropertyKey)
|
||||
if let trust: AnyObject = possibleTrust {
|
||||
let domain: AnyObject? = aStream.property(forKey: kCFStreamSSLPeerName as Stream.PropertyKey)
|
||||
@ -534,7 +534,7 @@ public class WebSocket : NSObject, StreamDelegate {
|
||||
}
|
||||
|
||||
/// Process one message at the start of `buffer`. Return another buffer (sharing storage) that contains the leftover contents of `buffer` that I didn't process.
|
||||
@warn_unused_result
|
||||
|
||||
private func processOneRawMessage(inBuffer buffer: UnsafeBufferPointer<UInt8>) -> UnsafeBufferPointer<UInt8> {
|
||||
let response = readStack.last
|
||||
guard let baseAddress = buffer.baseAddress else { fatalError("") }
|
||||
@ -543,7 +543,7 @@ public class WebSocket : NSObject, StreamDelegate {
|
||||
fragBuffer = Data(buffer: buffer)
|
||||
return emptyBuffer
|
||||
}
|
||||
if let response = response where response.bytesLeft > 0 {
|
||||
if let response = response, response.bytesLeft > 0 {
|
||||
var len = response.bytesLeft
|
||||
var extra = bufferLen - response.bytesLeft
|
||||
if response.bytesLeft > bufferLen {
|
||||
@ -612,10 +612,10 @@ public class WebSocket : NSObject, StreamDelegate {
|
||||
var dataLength = UInt64(payloadLen)
|
||||
if dataLength == 127 {
|
||||
dataLength = WebSocket.readUint64(baseAddress, offset: offset)
|
||||
offset += sizeof(UInt64)
|
||||
offset += sizeof(UInt64.self)
|
||||
} else if dataLength == 126 {
|
||||
dataLength = UInt64(WebSocket.readUint16(baseAddress, offset: offset))
|
||||
offset += sizeof(UInt16)
|
||||
offset += sizeof(UInt16.self)
|
||||
}
|
||||
if bufferLen < offset || UInt64(bufferLen - offset) < dataLength {
|
||||
fragBuffer = Data(bytes: baseAddress, count: bufferLen)
|
||||
@ -754,10 +754,10 @@ public class WebSocket : NSObject, StreamDelegate {
|
||||
|
||||
///write a an error to the socket
|
||||
private func writeError(_ code: UInt16) {
|
||||
let buf = NSMutableData(capacity: sizeof(UInt16))
|
||||
let buf = NSMutableData(capacity: sizeof(UInt16.self))
|
||||
let buffer = UnsafeMutablePointer<UInt8>(buf!.bytes)
|
||||
WebSocket.writeUint16(buffer, offset: 0, value: code)
|
||||
dequeueWrite(Data(bytes: buffer, count: sizeof(UInt16)), code: .connectionClose)
|
||||
dequeueWrite(Data(bytes: buffer, count: sizeof(UInt16.self)), code: .connectionClose)
|
||||
}
|
||||
///used to write things to the stream
|
||||
private func dequeueWrite(_ data: Data, code: OpCode, writeCompletion: (() -> ())? = nil) {
|
||||
@ -775,19 +775,19 @@ public class WebSocket : NSObject, StreamDelegate {
|
||||
} else if dataLength <= Int(UInt16.max) {
|
||||
buffer[1] = 126
|
||||
WebSocket.writeUint16(buffer, offset: offset, value: UInt16(dataLength))
|
||||
offset += sizeof(UInt16)
|
||||
offset += sizeof(UInt16.self)
|
||||
} else {
|
||||
buffer[1] = 127
|
||||
WebSocket.writeUint64(buffer, offset: offset, value: UInt64(dataLength))
|
||||
offset += sizeof(UInt64)
|
||||
offset += sizeof(UInt64.self)
|
||||
}
|
||||
buffer[1] |= s.MaskMask
|
||||
let maskKey = UnsafeMutablePointer<UInt8>(buffer + offset)
|
||||
SecRandomCopyBytes(kSecRandomDefault, Int(sizeof(UInt32)), maskKey)
|
||||
offset += sizeof(UInt32)
|
||||
_ = SecRandomCopyBytes(kSecRandomDefault, Int(sizeof(UInt32.self)), maskKey)
|
||||
offset += sizeof(UInt32.self)
|
||||
|
||||
for i in 0..<dataLength {
|
||||
buffer[offset] = bytes[i] ^ maskKey[i % sizeof(UInt32)]
|
||||
buffer[offset] = bytes[i] ^ maskKey[i % sizeof(UInt32.self)]
|
||||
offset += 1
|
||||
}
|
||||
var total = 0
|
||||
@ -809,7 +809,7 @@ public class WebSocket : NSObject, StreamDelegate {
|
||||
total += len
|
||||
}
|
||||
if total >= offset {
|
||||
if let queue = self?.queue, callback = writeCompletion {
|
||||
if let queue = self?.queue, let callback = writeCompletion {
|
||||
queue.asynchronously() {
|
||||
callback()
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user