Compare commits

...

17 Commits

Author SHA1 Message Date
Erik Little
fdb00d63ff
Merge branch 'enhorn-swift2.3' into swift2.3
* enhorn-swift2.3:
  Changes so the legacy build setting is set on the project, instead of each target.
  Adds the legacy option to the build settings, so the project compiles.
2016-09-12 09:30:10 -04:00
Robin Enhorn
a009afc6de Changes so the legacy build setting is set on the project, instead of each target. 2016-09-12 15:23:31 +02:00
Robin Enhorn
c4b1f29c80 Adds the legacy option to the build settings, so the project compiles. 2016-09-12 15:21:23 +02:00
Erik
404fa8cdfa
Merge branch 'development' into swift2.3
* development:
  change spm name
  Modify mac version base mac os 10.9
  Fix cocoapods name
  fix sid bug
  Fix socketio/socket.io-client-swift#472
  bump version
  Refactor engine. Fix infinite recursion in configuration
  Don't send whole packet to handleConnect
  Update readme
  bump version
  update readme
  Renamed modules to make then consistent.
  rename engine init
  Revert "travis plz"
  travis plz
2016-09-02 17:40:58 -04:00
Erik
e3c6993f75
merge development 2016-08-14 10:39:13 -04:00
Erik
a0c6b8b622
Merge develop 2016-08-11 21:38:57 -04:00
Erik
ea1fc1b0cc
Merge branch 'development' into swift2.3
* development:
  bump version
  add check for bad paths
  Fix socketpollable crashing
  make nonobjc
  More privatisation
  Making publicKeyChainForTrust() private.
  api extensions doesn't seem to fail for me
  update readme
  don't use api extensions only
2016-07-29 19:43:18 -04:00
Erik
a74d2fba85
Merge branch 'evanbrass-fix-optional-unwrapping' into swift2.3
* evanbrass-fix-optional-unwrapping:
  Fix errors with force unwrapping optionals
2016-07-28 21:19:47 -04:00
Erik
dbbed11a03
fix warning 2016-07-28 21:19:40 -04:00
Evan Brass
8f0a7c8f82 Fix errors with force unwrapping optionals
- Removing these fixed compile errors on swift 2.3.
2016-07-28 12:23:03 -04:00
Erik Little
4d12f9f510
Merge branch 'development' into swift2.3
* development:
  don't try and start server
2016-07-21 10:51:54 -04:00
Erik Little
a2969680e8
Merge branch 'development' into swift2.3
* development:
  change travis config
  remove log for dorequest
2016-07-21 10:47:39 -04:00
Erik
744d6bd062
Merge branch 'development' into swift2.3
* development:
  bump version
  fix swiftpm
  rename variable
  Enable APPLICATION_EXTENSION_API_ONLY
  fix method call
  fixes
  don't stall queues
  hopefully fix race condition in acks
  refactors
  Update README.md
  refactors, rename file
  refactoring
  refactor some serialization into methods
2016-07-20 11:32:38 -04:00
Erik
5814e8d275 Merge branch 'master' into swift2.3
* master:
  unknown message isn't fatal
  bump version
  notify client when engine disconnects
2016-06-24 02:49:14 -04:00
Erik
be76a1607c merge master 2016-06-17 10:16:52 -04:00
Erik Little
c1a451f314 Merge pull request #398 from davbeck/swift2.3
Updated code to support Swift 2.3
2016-06-16 19:07:28 -04:00
David Beck
0e38039a0c Updated code to support Swift 2.3 2016-06-14 07:31:15 -07:00
9 changed files with 49 additions and 44 deletions

View File

@ -542,9 +542,11 @@
};
572EF2371B51F18A00EEBB58 = {
CreatedOnToolsVersion = 6.4;
LastSwiftMigration = 0800;
};
572EF2411B51F18A00EEBB58 = {
CreatedOnToolsVersion = 6.4;
LastSwiftMigration = 0800;
};
};
};
@ -780,6 +782,7 @@
ONLY_ACTIVE_ARCH = YES;
PRODUCT_NAME = SocketIO;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 2.3;
TVOS_DEPLOYMENT_TARGET = 9.0;
WATCHOS_DEPLOYMENT_TARGET = 2.0;
};
@ -795,6 +798,7 @@
MACOSX_DEPLOYMENT_TARGET = 10.10;
PRODUCT_NAME = SocketIO;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 2.3;
TVOS_DEPLOYMENT_TARGET = 9.0;
WATCHOS_DEPLOYMENT_TARGET = 2.0;
};
@ -1164,6 +1168,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 2.3;
};
name = Debug;
};
@ -1210,6 +1215,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "io.socket.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_VERSION = 2.3;
};
name = Release;
};

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0720"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0720"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0720"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"

View File

@ -164,10 +164,9 @@ public class SSLSecurity : NSObject {
collect.append(SecCertificateCreateWithData(nil,cert)!)
}
SecTrustSetAnchorCertificates(trust,collect)
var result: SecTrustResultType = 0
var result = SecTrustResultType.Invalid
SecTrustEvaluate(trust,&result)
let r = Int(result)
if r == kSecTrustResultUnspecified || r == kSecTrustResultProceed {
if result == .Unspecified || result == .Proceed {
var trustedCount = 0
for serverCert in serverCerts {
for cert in certs {
@ -211,7 +210,7 @@ public class SSLSecurity : NSObject {
guard let trust = possibleTrust else { return nil }
var result: SecTrustResultType = 0
var result = SecTrustResultType.Invalid
SecTrustEvaluate(trust, &result)
return SecTrustCopyPublicKey(trust)
}
@ -257,4 +256,4 @@ public class SSLSecurity : NSObject {
}
}
}

View File

@ -213,8 +213,8 @@ public final class SocketEngine : NSObject, NSURLSessionDelegate, SocketEnginePo
return (NSURL(), NSURL())
}
let urlPolling = NSURLComponents(string: url.absoluteString)!
let urlWebSocket = NSURLComponents(string: url.absoluteString)!
let urlPolling = NSURLComponents(URL: url, resolvingAgainstBaseURL: true)!
let urlWebSocket = NSURLComponents(URL: url, resolvingAgainstBaseURL: true)!
var queryString = ""
urlWebSocket.path = socketPath
@ -375,7 +375,7 @@ public final class SocketEngine : NSObject, NSURLSessionDelegate, SocketEnginePo
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
}

View File

@ -72,7 +72,7 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable
self.config = config
self.socketURL = socketURL
if socketURL.absoluteString.hasPrefix("https://") {
if socketURL.absoluteString?.hasPrefix("https://") ?? false {
self.config.insert(.Secure(true))
}

View File

@ -78,7 +78,7 @@ public struct SocketIOClientConfiguration : ArrayLiteralConvertible, CollectionT
return backingArray.generate()
}
public mutating func insert(element: Element, replacing replace: Bool = true) {
public mutating func insert(_ element: Element, replacing replace: Bool = true) {
for i in 0..<backingArray.count where backingArray[i] == element {
guard replace else { return }

View File

@ -179,14 +179,14 @@ public class WebSocket: NSObject, NSStreamDelegate {
createHTTPRequest()
isConnecting = false
}
/**
Disconnect from the server. I send a Close control frame to the server, then expect the server to respond with a Close control frame and close the socket from its end. I notify my delegate once the socket has been closed.
If you supply a non-nil `forceTimeout`, I wait at most that long (in seconds) for the server to close the socket. After the timeout expires, I close the socket and notify my delegate.
If you supply a zero (or negative) `forceTimeout`, I immediately close the socket (without sending a Close control frame) and notify my delegate.
- Parameter forceTimeout: Maximum time to wait for the server to close the socket.
*/
public func disconnect(forceTimeout forceTimeout: NSTimeInterval? = nil) {
@ -198,18 +198,18 @@ public class WebSocket: NSObject, NSStreamDelegate {
fallthrough
case .None:
writeError(CloseCode.Normal.rawValue)
default:
disconnectStream(nil)
break
}
}
/**
Write a string to the websocket. This sends it as a text frame.
If you supply a non-nil completion block, I will perform it when the write completes.
- parameter str: The string to write.
- parameter completion: The (optional) completion handler.
*/
@ -217,12 +217,12 @@ public class WebSocket: NSObject, NSStreamDelegate {
guard isConnected else { return }
dequeueWrite(str.dataUsingEncoding(NSUTF8StringEncoding)!, code: .TextFrame, writeCompletion: completion)
}
/**
Write binary data to the websocket. This sends it as a binary frame.
If you supply a non-nil completion block, I will perform it when the write completes.
- parameter data: The data to write.
- parameter completion: The (optional) completion handler.
*/
@ -240,13 +240,13 @@ public class WebSocket: NSObject, NSStreamDelegate {
/// Private method that starts the connection.
private func createHTTPRequest() {
let urlRequest = CFHTTPMessageCreateRequest(kCFAllocatorDefault, "GET",
url, kCFHTTPVersion1_1).takeRetainedValue()
var port = url.port
if port == nil {
if supportedSSLSchemes.contains(url.scheme) {
if supportedSSLSchemes.contains(url.scheme!) {
port = 443
} else {
port = 80
@ -294,7 +294,7 @@ public class WebSocket: NSObject, NSStreamDelegate {
private func initStreamsWithData(data: NSData, _ port: Int) {
//higher level API we will cut over to at some point
//NSStream.getStreamsToHostWithName(url.host, port: url.port.integerValue, inputStream: &inputStream, outputStream: &outputStream)
var readStream: Unmanaged<CFReadStream>?
var writeStream: Unmanaged<CFWriteStream>?
let h: NSString = url.host!
@ -304,7 +304,7 @@ public class WebSocket: NSObject, NSStreamDelegate {
guard let inStream = inputStream, let outStream = outputStream else { return }
inStream.delegate = self
outStream.delegate = self
if supportedSSLSchemes.contains(url.scheme) {
if supportedSSLSchemes.contains(url.scheme!) {
inStream.setProperty(NSStreamSocketSecurityLevelNegotiatedSSL, forKey: NSStreamSocketSecurityLevelKey)
outStream.setProperty(NSStreamSocketSecurityLevelNegotiatedSSL, forKey: NSStreamSocketSecurityLevelKey)
} else {
@ -340,11 +340,11 @@ public class WebSocket: NSObject, NSStreamDelegate {
CFWriteStreamSetDispatchQueue(outStream, WebSocket.sharedWorkQueue)
inStream.open()
outStream.open()
self.mutex.lock()
self.readyToWrite = true
self.mutex.unlock()
let bytes = UnsafePointer<UInt8>(data.bytes)
var out = timeout * 1000000 // wait 5 seconds before giving up
writeQueue.addOperationWithBlock { [weak self] in
@ -365,7 +365,7 @@ public class WebSocket: NSObject, NSStreamDelegate {
// Delegate for the stream methods. Processes incoming bytes.
public func stream(aStream: NSStream, handleEvent eventCode: NSStreamEvent) {
if let sec = security where !certValidated && [.HasBytesAvailable, .HasSpaceAvailable].contains(eventCode) {
let possibleTrust: AnyObject? = aStream.propertyForKey(kCFStreamPropertySSLPeerTrust as String)
if let trust: AnyObject = possibleTrust {
@ -400,7 +400,7 @@ public class WebSocket: NSObject, NSStreamDelegate {
cleanupStream()
doDisconnect(error)
}
private func cleanupStream() {
outputStream?.delegate = nil
inputStream?.delegate = nil
@ -421,7 +421,7 @@ public class WebSocket: NSObject, NSStreamDelegate {
let buf = NSMutableData(capacity: BUFFER_MAX)
let buffer = UnsafeMutablePointer<UInt8>(buf!.bytes)
let length = inputStream!.read(buffer, maxLength: BUFFER_MAX)
guard length > 0 else { return }
var process = false
if inputQueue.count == 0 {
@ -552,7 +552,7 @@ public class WebSocket: NSObject, NSStreamDelegate {
buffer[offset + i] = UInt8((value >> (8*UInt64(7 - i))) & 0xff)
}
}
/// 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> {
@ -714,7 +714,7 @@ public class WebSocket: NSObject, NSStreamDelegate {
return buffer.fromOffset(step)
}
}
/// Process all messages in the buffer if possible.
private func processRawMessagesInBuffer(pointer: UnsafePointer<UInt8>, bufferLen: Int) {
var buffer = UnsafeBufferPointer(start: pointer, count: bufferLen)
@ -802,7 +802,7 @@ public class WebSocket: NSObject, NSStreamDelegate {
let maskKey = UnsafeMutablePointer<UInt8>(buffer + offset)
SecRandomCopyBytes(kSecRandomDefault, Int(sizeof(UInt32)), maskKey)
offset += sizeof(UInt32)
for i in 0..<dataLength {
buffer[offset] = bytes[i] ^ maskKey[i % sizeof(UInt32)]
offset += 1
@ -831,11 +831,11 @@ public class WebSocket: NSObject, NSStreamDelegate {
callback()
}
}
break
}
}
}
}
@ -862,23 +862,23 @@ public class WebSocket: NSObject, NSStreamDelegate {
mutex.unlock()
cleanupStream()
}
}
private extension NSData {
convenience init(buffer: UnsafeBufferPointer<UInt8>) {
self.init(bytes: buffer.baseAddress, length: buffer.count)
}
}
private extension UnsafeBufferPointer {
func fromOffset(offset: Int) -> UnsafeBufferPointer<Element> {
return UnsafeBufferPointer<Element>(start: baseAddress.advancedBy(offset), count: count - offset)
}
}
private let emptyBuffer = UnsafeBufferPointer<UInt8>(start: nil, count: 0)