From fe800c8a6c4cdf622502c7872cd28c5fe42d0dee Mon Sep 17 00:00:00 2001 From: Bill Abt Date: Tue, 2 Aug 2016 09:05:09 -0400 Subject: [PATCH] Changes for the latest toolchain. --- BlueSocket.xcodeproj/project.pbxproj | 22 +++--- README.md | 2 +- Sources/Socket.swift | 70 +++++++++---------- Sources/SocketProtocols.swift | 2 +- Sources/SocketUtils.swift | 31 ++++---- Tests/LinuxMain.swift | 10 +-- .../BasicSocketTests.swift} | 10 ++- Tests/{Socket => SocketTests}/Info.plist | 0 Tests/SocketTests/XCTestManifests.swift | 17 +++++ 9 files changed, 95 insertions(+), 69 deletions(-) rename Tests/{Socket/SocketTests.swift => SocketTests/BasicSocketTests.swift} (94%) rename Tests/{Socket => SocketTests}/Info.plist (100%) create mode 100644 Tests/SocketTests/XCTestManifests.swift diff --git a/BlueSocket.xcodeproj/project.pbxproj b/BlueSocket.xcodeproj/project.pbxproj index 88931c7..82f5b69 100644 --- a/BlueSocket.xcodeproj/project.pbxproj +++ b/BlueSocket.xcodeproj/project.pbxproj @@ -16,7 +16,7 @@ 8CC36DF91C4EA1BE00BAA659 /* Socket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8C0F4C031C4E8630008B2B0A /* Socket.swift */; }; 8CC36DFA1C4EA1BE00BAA659 /* SocketUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8C0F4C041C4E8630008B2B0A /* SocketUtils.swift */; }; 8CC7217B1D4BCB1D00F5FD19 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = 8CC7217A1D4BCB1D00F5FD19 /* LICENSE */; }; - 8CF04E221D4BCBC700C27814 /* SocketTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CC721761D4BCA9400F5FD19 /* SocketTests.swift */; }; + 8CF04E291D4FCE4A00C27814 /* BasicSocketTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CC721761D4BCA9400F5FD19 /* BasicSocketTests.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -30,6 +30,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 8C0039F11D4FE0F50064B65F /* XCTestManifests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = XCTestManifests.swift; path = Tests/SocketTests/XCTestManifests.swift; sourceTree = ""; }; 8C0F4BF61C4E84CC008B2B0A /* Socket.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Socket.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 8C0F4BF91C4E84CC008B2B0A /* Socket.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Socket.h; sourceTree = ""; }; 8C0F4BFB1C4E84CC008B2B0A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -40,10 +41,10 @@ 8CA9B1631C98A00400E607FB /* SocketTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SocketTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 8CC36E021C4EA1BE00BAA659 /* Socket.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Socket.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 8CC36E041C4EA34700BAA659 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; - 8CC721761D4BCA9400F5FD19 /* SocketTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketTests.swift; path = Tests/Socket/SocketTests.swift; sourceTree = ""; }; + 8CC721761D4BCA9400F5FD19 /* BasicSocketTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = BasicSocketTests.swift; path = Tests/SocketTests/BasicSocketTests.swift; sourceTree = ""; }; 8CC721781D4BCAA600F5FD19 /* LinuxMain.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LinuxMain.swift; path = Tests/LinuxMain.swift; sourceTree = ""; }; 8CC7217A1D4BCB1D00F5FD19 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = ""; }; - 8CF04E231D4BD03D00C27814 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = Tests/Socket/Info.plist; sourceTree = ""; }; + 8CF04E231D4BD03D00C27814 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = Tests/SocketTests/Info.plist; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -114,20 +115,21 @@ name = "Supporting Files"; sourceTree = ""; }; - 8CC721751D4BCA7D00F5FD19 /* Socket */ = { + 8CC721751D4BCA7D00F5FD19 /* SocketTests */ = { isa = PBXGroup; children = ( 8CF04E231D4BD03D00C27814 /* Info.plist */, - 8CC721761D4BCA9400F5FD19 /* SocketTests.swift */, + 8CC721761D4BCA9400F5FD19 /* BasicSocketTests.swift */, + 8C0039F11D4FE0F50064B65F /* XCTestManifests.swift */, ); - name = Socket; + name = SocketTests; sourceTree = ""; }; 8CF2D7371C989EE0000A7D2B /* Tests */ = { isa = PBXGroup; children = ( 8CC721781D4BCAA600F5FD19 /* LinuxMain.swift */, - 8CC721751D4BCA7D00F5FD19 /* Socket */, + 8CC721751D4BCA7D00F5FD19 /* SocketTests */, ); name = Tests; sourceTree = ""; @@ -287,7 +289,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 8CF04E221D4BCBC700C27814 /* SocketTests.swift in Sources */, + 8CF04E291D4FCE4A00C27814 /* BasicSocketTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -447,7 +449,7 @@ buildSettings = { CLANG_ANALYZER_NONNULL = YES; COMBINE_HIDPI_IMAGES = YES; - INFOPLIST_FILE = Tests/Socket/Info.plist; + INFOPLIST_FILE = Tests/SocketTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.ibm.oss.SocketTests; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -459,7 +461,7 @@ buildSettings = { CLANG_ANALYZER_NONNULL = YES; COMBINE_HIDPI_IMAGES = YES; - INFOPLIST_FILE = Tests/Socket/Info.plist; + INFOPLIST_FILE = Tests/SocketTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.ibm.oss.SocketTests; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/README.md b/README.md index 1f29329..1890673 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ ![](https://img.shields.io/badge/Swift-3.0-orange.svg?style=flat) -![](https://img.shields.io/badge/Snapshot-7/25-blue.svg?style=flat) +![](https://img.shields.io/badge/Snapshot-7/29-blue.svg?style=flat) # BlueSocket diff --git a/Sources/Socket.swift b/Sources/Socket.swift index 8046208..a8368c3 100644 --- a/Sources/Socket.swift +++ b/Sources/Socket.swift @@ -316,37 +316,37 @@ public class Socket: SocketReader, SocketWriter { /// /// Protocol Family /// - public private(set) var protocolFamily: ProtocolFamily + public internal(set) var protocolFamily: ProtocolFamily /// /// Socket Type /// - public private(set) var socketType: SocketType + public internal(set) var socketType: SocketType /// /// Socket Protocol /// - public private(set) var proto: SocketProtocol + public internal(set) var proto: SocketProtocol /// /// Host name for connection /// - public private(set) var hostname: String? = Socket.NO_HOSTNAME + public internal(set) var hostname: String? = Socket.NO_HOSTNAME /// /// Port for connection /// - public private(set) var port: Int32 = Socket.SOCKET_INVALID_PORT + public internal(set) var port: Int32 = Socket.SOCKET_INVALID_PORT /// /// Address info for socket. /// - public private(set) var address: Address? = nil + public internal(set) var address: Address? = nil /// /// Flag to indicate whether `Socket` is secure or not. /// - public private(set) var isSecure: Bool = false + public internal(set) var isSecure: Bool = false /// /// Returns a string description of the error. @@ -429,7 +429,7 @@ public class Socket: SocketReader, SocketWriter { /// /// - Returns: New Signature instance /// - private init?(protocolFamily: Int32, socketType: Int32, proto: Int32, address: Address?, hostname: String?, port: Int32?) throws { + internal init?(protocolFamily: Int32, socketType: Int32, proto: Int32, address: Address?, hostname: String?, port: Int32?) throws { // This constructor requires all items be present... guard let family = ProtocolFamily.getFamily(forValue: protocolFamily), @@ -466,12 +466,12 @@ public class Socket: SocketReader, SocketWriter { /// /// The error code: **see constants above for possible errors** /// - public private(set) var errorCode: Int32 + public internal(set) var errorCode: Int32 /// /// The reason for the error **(if available)** /// - public private(set) var errorReason: String? + public internal(set) var errorReason: String? /// /// Returns a string description of the error. @@ -485,7 +485,7 @@ public class Socket: SocketReader, SocketWriter { /// /// The buffer size needed to complete the read. /// - public private(set) var bufferSizeNeeded: Int32 + public internal(set) var bufferSizeNeeded: Int32 // MARK: -- Public Functions @@ -593,17 +593,17 @@ public class Socket: SocketReader, SocketWriter { /// /// True if this socket is connected. False otherwise. (Readonly) /// - public private(set) var isConnected: Bool = false + public internal(set) var isConnected: Bool = false /// /// True if this socket is blocking. False otherwise. (Readonly) /// - public private(set) var isBlocking: Bool = true + public internal(set) var isBlocking: Bool = true /// /// True if this socket is listening. False otherwise. (Readonly) /// - public private(set) var isListening: Bool = false + public internal(set) var isListening: Bool = false /// /// True if the socket is listening or connected. @@ -652,13 +652,13 @@ public class Socket: SocketReader, SocketWriter { /// /// The file descriptor representing this socket. (Readonly) /// - public private(set) var socketfd: Int32 = SOCKET_INVALID_DESCRIPTOR + public internal(set) var socketfd: Int32 = SOCKET_INVALID_DESCRIPTOR /// /// The signature for the socket. /// **Note:** See Signature above. /// - public private(set) var signature: Signature? = nil + public internal(set) var signature: Signature? = nil /// /// True if this a server, false otherwise. @@ -1029,12 +1029,12 @@ public class Socket: SocketReader, SocketWriter { var addrSize = socklen_t(sizeofValue(acceptAddr)) #if os(Linux) - let fd = withUnsafeMutablePointer(&acceptAddr) { - Glibc.accept(self.socketfd, UnsafeMutablePointer($0), &addrSize) + let fd = withUnsafeMutablePointer(to: &acceptAddr) { + Glibc.accept(self.socketfd, UnsafeMutableRawPointer($0).assumingMemoryBound(to: sockaddr.self), &addrSize) } #else - let fd = withUnsafeMutablePointer(&acceptAddr) { - Darwin.accept(self.socketfd, UnsafeMutablePointer($0), &addrSize) + let fd = withUnsafeMutablePointer(to: &acceptAddr) { + Darwin.accept(self.socketfd, UnsafeMutableRawPointer($0).assumingMemoryBound(to: sockaddr.self), &addrSize) } #endif if fd < 0 { @@ -1053,12 +1053,12 @@ public class Socket: SocketReader, SocketWriter { var addrSize = socklen_t(sizeofValue(acceptAddr)) #if os(Linux) - let fd = withUnsafeMutablePointer(&acceptAddr) { - Glibc.accept(self.socketfd, UnsafeMutablePointer($0), &addrSize) + let fd = withUnsafeMutablePointer(to: &acceptAddr) { + Glibc.accept(self.socketfd, UnsafeMutableRawPointer($0).assumingMemoryBound(to: sockaddr.self), &addrSize) } #else - let fd = withUnsafeMutablePointer(&acceptAddr) { - Darwin.accept(self.socketfd, UnsafeMutablePointer($0), &addrSize) + let fd = withUnsafeMutablePointer(to: &acceptAddr) { + Darwin.accept(self.socketfd, UnsafeMutableRawPointer($0).assumingMemoryBound(to: sockaddr.self), &addrSize) } #endif if fd < 0 { @@ -1139,12 +1139,12 @@ public class Socket: SocketReader, SocketWriter { var addrSize = socklen_t(sizeofValue(acceptAddr)) #if os(Linux) - let fd = withUnsafeMutablePointer(&acceptAddr) { - Glibc.accept(self.socketfd, UnsafeMutablePointer($0), &addrSize) + let fd = withUnsafeMutablePointer(to: &acceptAddr) { + Glibc.accept(self.socketfd, UnsafeMutableRawPointer($0).assumingMemoryBound(to: sockaddr.self), &addrSize) } #else - let fd = withUnsafeMutablePointer(&acceptAddr) { - Darwin.accept(self.socketfd, UnsafeMutablePointer($0), &addrSize) + let fd = withUnsafeMutablePointer(to: &acceptAddr) { + Darwin.accept(self.socketfd, UnsafeMutableRawPointer($0).assumingMemoryBound(to: sockaddr.self), &addrSize) } #endif if fd < 0 { @@ -1163,12 +1163,12 @@ public class Socket: SocketReader, SocketWriter { var addrSize = socklen_t(sizeofValue(acceptAddr)) #if os(Linux) - let fd = withUnsafeMutablePointer(&acceptAddr) { - Glibc.accept(self.socketfd, UnsafeMutablePointer($0), &addrSize) + let fd = withUnsafeMutablePointer(to: &acceptAddr) { + Glibc.accept(self.socketfd, UnsafeMutableRawPointer($0).assumingMemoryBound(to: sockaddr.self), &addrSize) } #else - let fd = withUnsafeMutablePointer(&acceptAddr) { - Darwin.accept(self.socketfd, UnsafeMutablePointer($0), &addrSize) + let fd = withUnsafeMutablePointer(to: &acceptAddr) { + Darwin.accept(self.socketfd, UnsafeMutableRawPointer($0).assumingMemoryBound(to: sockaddr.self), &addrSize) } #endif if fd < 0 { @@ -1500,11 +1500,11 @@ public class Socket: SocketReader, SocketWriter { var remoteAddr = signature.address!.addr #if os(Linux) - let rc = withUnsafeMutablePointer(&remoteAddr) { + let rc = withUnsafeMutablePointer(to: &remoteAddr) { Glibc.connect(self.socketfd, UnsafeMutablePointer($0), socklen_t(signature.address!.size)) } #else - let rc = withUnsafeMutablePointer(&remoteAddr) { + let rc = withUnsafeMutablePointer(to: &remoteAddr) { Darwin.connect(self.socketfd, UnsafeMutablePointer($0), socklen_t(signature.address!.size)) } #endif @@ -2082,7 +2082,7 @@ public class Socket: SocketReader, SocketWriter { /// public func write(from string: String) throws { - try string.nulTerminatedUTF8.withUnsafeBufferPointer() { + try string.utf8CString.withUnsafeBufferPointer() { // The count returned by nullTerminatedUTF8 includes the null terminator... try self.write(from: $0.baseAddress!, bufSize: $0.count-1) diff --git a/Sources/SocketProtocols.swift b/Sources/SocketProtocols.swift index 68557e2..b82633c 100644 --- a/Sources/SocketProtocols.swift +++ b/Sources/SocketProtocols.swift @@ -113,7 +113,7 @@ public protocol SSLServiceDelegate { /// /// - Returns the number of bytes written. Zero indicates SSL shutdown, less than zero indicates error. /// - func send(buffer: UnsafePointer!, bufSize: Int) throws -> Int + func send(buffer: UnsafeRawPointer!, bufSize: Int) throws -> Int /// /// Low level reader diff --git a/Sources/SocketUtils.swift b/Sources/SocketUtils.swift index 5996163..d9da0f6 100644 --- a/Sources/SocketUtils.swift +++ b/Sources/SocketUtils.swift @@ -38,10 +38,11 @@ public extension sockaddr_storage { public func asAddr() -> sockaddr { var temp = self - let addr = withUnsafePointer(&temp) { - return UnsafePointer($0).pointee + let addr = withUnsafePointer(to: &temp) { + return UnsafeRawPointer($0) } - return addr + return addr.assumingMemoryBound(to: sockaddr.self).pointee + } /// @@ -52,10 +53,10 @@ public extension sockaddr_storage { public func asIPV4() -> sockaddr_in { var temp = self - let addr = withUnsafePointer(&temp) { - return UnsafePointer($0).pointee + let addr = withUnsafePointer(to: &temp) { + return UnsafeRawPointer($0) } - return addr + return addr.assumingMemoryBound(to: sockaddr_in.self).pointee } /// @@ -66,10 +67,10 @@ public extension sockaddr_storage { public func asIPV6() -> sockaddr_in6 { var temp = self - let addr = withUnsafePointer(&temp) { - return UnsafePointer($0).pointee + let addr = withUnsafePointer(to: &temp) { + return UnsafeRawPointer($0) } - return addr + return addr.assumingMemoryBound(to: sockaddr_in6.self).pointee } } @@ -85,10 +86,10 @@ public extension sockaddr_in { public func asAddr() -> sockaddr { var temp = self - let addr = withUnsafePointer(&temp) { - return UnsafePointer($0).pointee + let addr = withUnsafePointer(to: &temp) { + return UnsafeRawPointer($0) } - return addr + return addr.assumingMemoryBound(to: sockaddr.self).pointee } } @@ -104,10 +105,10 @@ public extension sockaddr_in6 { public func asAddr() -> sockaddr { var temp = self - let addr = withUnsafePointer(&temp) { - return UnsafePointer($0).pointee + let addr = withUnsafePointer(to: &temp) { + return UnsafeRawPointer($0) } - return addr + return addr.assumingMemoryBound(to: sockaddr.self).pointee } } diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift index 76403c4..6e419a0 100644 --- a/Tests/LinuxMain.swift +++ b/Tests/LinuxMain.swift @@ -17,8 +17,10 @@ import XCTest -@testable import SocketTestSuite +import SocketTests -XCTMain([ - testCase(SocketTests.allTests) -]) +var tests = [XCTestCaseEntry]() + +tests += BasicSocketTests.allTests() + +XCTMain(tests) diff --git a/Tests/Socket/SocketTests.swift b/Tests/SocketTests/BasicSocketTests.swift similarity index 94% rename from Tests/Socket/SocketTests.swift rename to Tests/SocketTests/BasicSocketTests.swift index 8ab2104..b3b8ab8 100644 --- a/Tests/Socket/SocketTests.swift +++ b/Tests/SocketTests/BasicSocketTests.swift @@ -21,9 +21,9 @@ import XCTest @testable import Socket -class SocketTests: XCTestCase { +class BasicSocketTests: XCTestCase { - #if os(Linux) +/* #if os(Linux) static var allTests : [(String, (SocketTests) -> () throws -> Void)] { return [ @@ -31,7 +31,7 @@ class SocketTests: XCTestCase { ] } #endif - +*/ override func setUp() { super.setUp() // Put setup code here. This method is called before the invocation of each test method in the class. @@ -70,4 +70,8 @@ class SocketTests: XCTestCase { print("Error reported: \(socketError.description)") } } + + static var allTests = [ + ("testSocket", testSocket) + ] } diff --git a/Tests/Socket/Info.plist b/Tests/SocketTests/Info.plist similarity index 100% rename from Tests/Socket/Info.plist rename to Tests/SocketTests/Info.plist diff --git a/Tests/SocketTests/XCTestManifests.swift b/Tests/SocketTests/XCTestManifests.swift new file mode 100644 index 0000000..e49b17d --- /dev/null +++ b/Tests/SocketTests/XCTestManifests.swift @@ -0,0 +1,17 @@ +// +// XCTestManifests.swift +// Socket +// +// Created by Bill Abt on 8/1/16. +// +// + +import XCTest + +#if !os(macOS) + public func allTests() -> [XCTestCaseEntry] { + return [ + testCase(BasicSocketTests.allTests), + ] + } +#endif