From 5cd3d1500b5152bb93b184112608c86104798f57 Mon Sep 17 00:00:00 2001 From: Rien Date: Thu, 5 Apr 2018 20:51:56 +0200 Subject: [PATCH] Migration to Swift 4 --- .gitignore | 1 + Package.swift | 2 +- README.md | 6 ++++- Sources/SwifterSockets.Connection.swift | 5 ++-- Sources/SwifterSockets.Receive.swift | 7 +++--- Sources/SwifterSockets.swift | 23 ++++++++++--------- .../SwifterSocketsTests.swift | 17 -------------- 7 files changed, 26 insertions(+), 35 deletions(-) delete mode 100644 Tests/SwifterSocketsTests/SwifterSocketsTests.swift diff --git a/.gitignore b/.gitignore index 65b14e4..126a696 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ build /DerivedData Package.pins +Package.resolved diff --git a/Package.swift b/Package.swift index ea42329..0444249 100644 --- a/Package.swift +++ b/Package.swift @@ -3,6 +3,6 @@ import PackageDescription let package = Package( name: "SwifterSockets", dependencies: [ - .Package(url: "https://github.com/Balancingrock/BRUtils", Version(0, 10, 0)) + .Package(url: "https://github.com/Balancingrock/BRUtils", Version(0, 11, 0)) ] ) diff --git a/README.md b/README.md index 3738122..55f0802 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,11 @@ Note: Planned releases are for information only, they are subject to change with - The current verion will be upgraded to 1.0.0 status when the full set necessary for Swiftfire 1.0.0 has been completed. -#### 0.10.10 (Current) +#### 0.10.11 (Current) + +- Migration to Swift 4, minor adjustments. + +#### 0.10.10 - Upgraded BRUtils to 0.10.0 diff --git a/Sources/SwifterSockets.Connection.swift b/Sources/SwifterSockets.Connection.swift index 10b36c9..12b93a2 100644 --- a/Sources/SwifterSockets.Connection.swift +++ b/Sources/SwifterSockets.Connection.swift @@ -3,7 +3,7 @@ // File: SwifterSockets.Connection.swift // Project: SwifterSockets // -// Version: 0.10.8 +// Version: 0.10.11 // // Author: Marinus van der Lugt // Company: http://balancingrock.nl @@ -48,6 +48,7 @@ // // History // +// 0.10.11 - Migration to Swift 4, minor adjustments. // 0.10.8 - Made incrementUsageCount and decrementUsageCount public. // 0.10.7 - Bugfix: partial reimplementation to prevent crashes due to clashes of receiver events and close events. // 0.10.6 - Renamed 'abortConnection' to 'connectionWasClosed'. @@ -872,7 +873,7 @@ open class Connection: ReceiverProtocol, TransmitterProtocol { if let queue = tqueue() { - let copy = UnsafeMutableRawBufferPointer.allocate(count: buffer.count) + let copy = UnsafeMutableRawBufferPointer.allocate(byteCount: buffer.count, alignment: 8) memcpy(copy.baseAddress, buffer.baseAddress, buffer.count) queue.async { diff --git a/Sources/SwifterSockets.Receive.swift b/Sources/SwifterSockets.Receive.swift index a99f999..4c9901b 100644 --- a/Sources/SwifterSockets.Receive.swift +++ b/Sources/SwifterSockets.Receive.swift @@ -3,7 +3,7 @@ // File: SwifterSockets.Receive.swift // Project: SwifterSockets // -// Version: 0.9.14 +// Version: 0.10.11 // // Author: Marinus van der Lugt // Company: http://balancingrock.nl @@ -48,6 +48,7 @@ // // History // +// 0.10.11 - Migration to Swift 4, minor adjustments. // 0.9.14 - Moved receiver protocol to this file // 0.9.13 - Comment section update // 0.9.12 - Documentation updated to accomodate the documentation tool 'jazzy' @@ -135,7 +136,7 @@ public func tipReceiverLoop( // Allocate the data buffer - let buffer = UnsafeMutableRawPointer.allocate(bytes: bufferSize, alignedTo: 1) + let buffer = UnsafeMutableRawPointer.allocate(byteCount: bufferSize, alignment: 8) // =============================================================================== @@ -201,6 +202,6 @@ public func tipReceiverLoop( // Deallocate the data buffer - buffer.deallocate(bytes: bufferSize, alignedTo: 1) + buffer.deallocate() } diff --git a/Sources/SwifterSockets.swift b/Sources/SwifterSockets.swift index fa73a55..16a2e23 100644 --- a/Sources/SwifterSockets.swift +++ b/Sources/SwifterSockets.swift @@ -3,7 +3,7 @@ // File: SwifterSockets.swift // Project: SwifterSockets // -// Version: 0.10.2 +// Version: 0.10.11 // // Author: Marinus van der Lugt // Company: http://balancingrock.nl @@ -48,6 +48,7 @@ // // History // +// 0.10.10 - Migration to Swift 4, minor adjustments. // 0.10.2 - Added BRUtils for the Result type // 0.10.1 - Analysed compilation time and speed up // 0.10.0 - Added func result @@ -81,7 +82,7 @@ import Foundation /// A helper extensions to allow increment/decrement operations on counter values -extension Integer { +extension BinaryInteger { /// Increases self by one @@ -428,9 +429,9 @@ public func fdSet(_ fd: Int32?, set: inout fd_set) { if let fd = fd { - let intOffset = Int(fd / 32) - let bitOffset = fd % 32 - let mask = 1 << bitOffset + let intOffset: Int32 = fd / 32 + let bitOffset: Int32 = fd % 32 + let mask: Int32 = 1 << bitOffset switch intOffset { case 0: set.fds_bits.0 = set.fds_bits.0 | mask @@ -482,9 +483,9 @@ public func fdClr(_ fd: Int32?, set: inout fd_set) { if let fd = fd { - let intOffset = Int(fd / 32) - let bitOffset = fd % 32 - let mask = ~(1 << bitOffset) + let intOffset: Int32 = fd / 32 + let bitOffset: Int32 = fd % 32 + let mask: Int32 = ~(1 << bitOffset) switch intOffset { case 0: set.fds_bits.0 = set.fds_bits.0 & mask @@ -536,9 +537,9 @@ public func fdIsSet(_ fd: Int32?, set: inout fd_set) -> Bool { if let fd = fd { - let intOffset = Int(fd / 32) - let bitOffset = fd % 32 - let mask = 1 << bitOffset + let intOffset: Int32 = fd / 32 + let bitOffset: Int32 = fd % 32 + let mask: Int32 = 1 << bitOffset switch intOffset { case 0: return set.fds_bits.0 & mask != 0 diff --git a/Tests/SwifterSocketsTests/SwifterSocketsTests.swift b/Tests/SwifterSocketsTests/SwifterSocketsTests.swift deleted file mode 100644 index 25be053..0000000 --- a/Tests/SwifterSocketsTests/SwifterSocketsTests.swift +++ /dev/null @@ -1,17 +0,0 @@ -import XCTest -@testable import SwifterSockets - -class SwifterSocketsTests: XCTestCase { - func testExample() { - // This is an example of a functional test case. - // Use XCTAssert and related functions to verify your tests produce the correct results. - XCTAssertEqual(SwifterSockets().text, "Hello, World!") - } - - - static var allTests : [(String, (SwifterSocketsTests) -> () throws -> Void)] { - return [ - ("testExample", testExample), - ] - } -}