Update starscream for new dep; add spm build

This commit is contained in:
Erik 2017-07-08 09:40:50 -04:00
parent f00af67283
commit 781a9e32ca
No known key found for this signature in database
GPG Key ID: 4930B7C5FBC1A69D
3 changed files with 31 additions and 29 deletions

View File

@ -12,4 +12,5 @@ before_install:
script: script:
- xcodebuild -project Socket.IO-Client-Swift.xcodeproj -scheme SocketIO-Mac build-for-testing -quiet - xcodebuild -project Socket.IO-Client-Swift.xcodeproj -scheme SocketIO-Mac build-for-testing -quiet
- xctool -project Socket.IO-Client-Swift.xcodeproj -scheme SocketIO-Mac run-tests --parallelize - xctool -project Socket.IO-Client-Swift.xcodeproj -scheme SocketIO-Mac run-tests --parallelize
- swift build
#script: xcodebuild -project Socket.IO-Client-Swift.xcodeproj -scheme SocketIO-Mac build test #script: xcodebuild -project Socket.IO-Client-Swift.xcodeproj -scheme SocketIO-Mac build test

View File

@ -25,19 +25,19 @@
// //
////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////
import Foundation import Foundation
import zlib import CZLib
class Decompressor { class Decompressor {
private var strm = z_stream() private var strm = z_stream()
private var buffer = [UInt8](repeating: 0, count: 0x2000) private var buffer = [UInt8](repeating: 0, count: 0x2000)
private var inflateInitialized = false private var inflateInitialized = false
private let windowBits:Int private let windowBits:Int
init?(windowBits:Int) { init?(windowBits:Int) {
self.windowBits = windowBits self.windowBits = windowBits
guard initInflate() else { return nil } guard initInflate() else { return nil }
} }
private func initInflate() -> Bool { private func initInflate() -> Bool {
if Z_OK == inflateInit2_(&strm, -CInt(windowBits), if Z_OK == inflateInit2_(&strm, -CInt(windowBits),
ZLIB_VERSION, CInt(MemoryLayout<z_stream>.size)) ZLIB_VERSION, CInt(MemoryLayout<z_stream>.size))
@ -47,59 +47,59 @@ class Decompressor {
} }
return false return false
} }
func reset() throws { func reset() throws {
teardownInflate() teardownInflate()
guard initInflate() else { throw NSError() } guard initInflate() else { throw NSError() }
} }
func decompress(_ data: Data, finish: Bool) throws -> Data { func decompress(_ data: Data, finish: Bool) throws -> Data {
return try data.withUnsafeBytes { (bytes:UnsafePointer<UInt8>) -> Data in return try data.withUnsafeBytes { (bytes:UnsafePointer<UInt8>) -> Data in
return try decompress(bytes: bytes, count: data.count, finish: finish) return try decompress(bytes: bytes, count: data.count, finish: finish)
} }
} }
func decompress(bytes: UnsafePointer<UInt8>, count: Int, finish: Bool) throws -> Data { func decompress(bytes: UnsafePointer<UInt8>, count: Int, finish: Bool) throws -> Data {
var decompressed = Data() var decompressed = Data()
try decompress(bytes: bytes, count: count, out: &decompressed) try decompress(bytes: bytes, count: count, out: &decompressed)
if finish { if finish {
let tail:[UInt8] = [0x00, 0x00, 0xFF, 0xFF] let tail:[UInt8] = [0x00, 0x00, 0xFF, 0xFF]
try decompress(bytes: tail, count: tail.count, out: &decompressed) try decompress(bytes: tail, count: tail.count, out: &decompressed)
} }
return decompressed return decompressed
} }
private func decompress(bytes: UnsafePointer<UInt8>, count: Int, out:inout Data) throws { private func decompress(bytes: UnsafePointer<UInt8>, count: Int, out:inout Data) throws {
var res:CInt = 0 var res:CInt = 0
strm.next_in = UnsafeMutablePointer<UInt8>(mutating: bytes) strm.next_in = UnsafeMutablePointer<UInt8>(mutating: bytes)
strm.avail_in = CUnsignedInt(count) strm.avail_in = CUnsignedInt(count)
repeat { repeat {
strm.next_out = UnsafeMutablePointer<UInt8>(&buffer) strm.next_out = UnsafeMutablePointer<UInt8>(&buffer)
strm.avail_out = CUnsignedInt(buffer.count) strm.avail_out = CUnsignedInt(buffer.count)
res = inflate(&strm, 0) res = inflate(&strm, 0)
let byteCount = buffer.count - Int(strm.avail_out) let byteCount = buffer.count - Int(strm.avail_out)
out.append(buffer, count: byteCount) out.append(buffer, count: byteCount)
} while res == Z_OK && strm.avail_out == 0 } while res == Z_OK && strm.avail_out == 0
guard (res == Z_OK && strm.avail_out > 0) guard (res == Z_OK && strm.avail_out > 0)
|| (res == Z_BUF_ERROR && Int(strm.avail_out) == buffer.count) || (res == Z_BUF_ERROR && Int(strm.avail_out) == buffer.count)
else { else {
throw NSError(domain: WebSocket.ErrorDomain, code: Int(WebSocket.InternalErrorCode.compressionError.rawValue), userInfo: nil) throw NSError(domain: WebSocket.ErrorDomain, code: Int(WebSocket.InternalErrorCode.compressionError.rawValue), userInfo: nil)
} }
} }
private func teardownInflate() { private func teardownInflate() {
if inflateInitialized, Z_OK == inflateEnd(&strm) { if inflateInitialized, Z_OK == inflateEnd(&strm) {
inflateInitialized = false inflateInitialized = false
} }
} }
deinit { deinit {
teardownInflate() teardownInflate()
} }
@ -110,12 +110,12 @@ class Compressor {
private var buffer = [UInt8](repeating: 0, count: 0x2000) private var buffer = [UInt8](repeating: 0, count: 0x2000)
private var deflateInitialized = false private var deflateInitialized = false
private let windowBits:Int private let windowBits:Int
init?(windowBits: Int) { init?(windowBits: Int) {
self.windowBits = windowBits self.windowBits = windowBits
guard initDeflate() else { return nil } guard initDeflate() else { return nil }
} }
private func initDeflate() -> Bool { private func initDeflate() -> Bool {
if Z_OK == deflateInit2_(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, if Z_OK == deflateInit2_(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED,
-CInt(windowBits), 8, Z_DEFAULT_STRATEGY, -CInt(windowBits), 8, Z_DEFAULT_STRATEGY,
@ -126,48 +126,48 @@ class Compressor {
} }
return false return false
} }
func reset() throws { func reset() throws {
teardownDeflate() teardownDeflate()
guard initDeflate() else { throw NSError() } guard initDeflate() else { throw NSError() }
} }
func compress(_ data: Data) throws -> Data { func compress(_ data: Data) throws -> Data {
var compressed = Data() var compressed = Data()
var res:CInt = 0 var res:CInt = 0
data.withUnsafeBytes { (ptr:UnsafePointer<UInt8>) -> Void in data.withUnsafeBytes { (ptr:UnsafePointer<UInt8>) -> Void in
strm.next_in = UnsafeMutablePointer<UInt8>(mutating: ptr) strm.next_in = UnsafeMutablePointer<UInt8>(mutating: ptr)
strm.avail_in = CUnsignedInt(data.count) strm.avail_in = CUnsignedInt(data.count)
repeat { repeat {
strm.next_out = UnsafeMutablePointer<UInt8>(&buffer) strm.next_out = UnsafeMutablePointer<UInt8>(&buffer)
strm.avail_out = CUnsignedInt(buffer.count) strm.avail_out = CUnsignedInt(buffer.count)
res = deflate(&strm, Z_SYNC_FLUSH) res = deflate(&strm, Z_SYNC_FLUSH)
let byteCount = buffer.count - Int(strm.avail_out) let byteCount = buffer.count - Int(strm.avail_out)
compressed.append(buffer, count: byteCount) compressed.append(buffer, count: byteCount)
} }
while res == Z_OK && strm.avail_out == 0 while res == Z_OK && strm.avail_out == 0
} }
guard res == Z_OK && strm.avail_out > 0 guard res == Z_OK && strm.avail_out > 0
|| (res == Z_BUF_ERROR && Int(strm.avail_out) == buffer.count) || (res == Z_BUF_ERROR && Int(strm.avail_out) == buffer.count)
else { else {
throw NSError(domain: WebSocket.ErrorDomain, code: Int(WebSocket.InternalErrorCode.compressionError.rawValue), userInfo: nil) throw NSError(domain: WebSocket.ErrorDomain, code: Int(WebSocket.InternalErrorCode.compressionError.rawValue), userInfo: nil)
} }
compressed.removeLast(4) compressed.removeLast(4)
return compressed return compressed
} }
private func teardownDeflate() { private func teardownDeflate() {
if deflateInitialized, Z_OK == deflateEnd(&strm) { if deflateInitialized, Z_OK == deflateEnd(&strm) {
deflateInitialized = false deflateInitialized = false
} }
} }
deinit { deinit {
teardownDeflate() teardownDeflate()
} }

View File

@ -1,6 +1,7 @@
module zlib [system] { module CZLib [system] {
header "include.h" header "include.h"
link "z" link "z"
export *
} }
module CommonCrypto [system] { module CommonCrypto [system] {
header "include.h" header "include.h"