Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift package manager #706

Merged
merged 7 commits into from
Feb 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ Pods/
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build
Carthage/Build
.build
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
osx_image: xcode9.2
osx_image: xcode11.3
language: objective-c

install:
Expand All @@ -11,3 +11,5 @@ install:
script:
- export IOS_VERSION="11.2" # waiting for xcode9.3 on Travis
- bash Tests/test-all.sh
- swift build
- swift test
34 changes: 34 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// swift-tools-version:5.1
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "CocoaAsyncSocket",
platforms: [
.iOS(.v8),
.macOS(.v10_10),
.tvOS(.v9)
],
products: [
.library(
name: "CocoaAsyncSocket",
targets: ["CocoaAsyncSocket"]),
],
dependencies: [],
targets: [
.target(
name: "CocoaAsyncSocket",
dependencies: [],
path: "Source/GCD",
publicHeadersPath: ""),

.testTarget(name: "SharedObjCTests",
dependencies: ["CocoaAsyncSocket"],
path: "Tests/Shared/ObjC"),

.testTarget(name: "SharedSwiftTests",
dependencies: ["CocoaAsyncSocket"],
path: "Tests/Shared/Swift")
]
)
9 changes: 9 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ The project is currently configured to build for **iOS**, **tvOS** and **Mac**.

Select the correct framework(s) and drag it into your project.

#### Swift Package Manager

Simply add the package dependency to your Package.swift and depend on "CocoaAsyncSocket" in the necessary targets:
```swift
dependencies: [
.package(url: "https://github.com/robbiehanson/CocoaAsyncSocket", from: "7.6.3")
]
```

#### Manual

You can also include it into your project by adding the source files directly, but you should probably be using a dependency manager to keep up to date.
Expand Down
122 changes: 74 additions & 48 deletions Tests/Framework/CocoaAsyncSocketTests.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

70 changes: 46 additions & 24 deletions Tests/Mac/CocoaAsyncSocket.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,27 @@
/* Begin PBXBuildFile section */
2DBCA5C81B8CF4F3004F3128 /* GCDAsyncSocketUNTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2DBCA5C71B8CF4F3004F3128 /* GCDAsyncSocketUNTests.m */; };
439EF337A9890757E22FAEC3 /* Pods_CocoaAsyncSocketTestsMac.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1859AD1F79C285DFDC07C37C /* Pods_CocoaAsyncSocketTestsMac.framework */; };
D938B4E51B752ED500FE8AB3 /* GCDAsyncSocketConnectionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D938B4E31B752ED500FE8AB3 /* GCDAsyncSocketConnectionTests.m */; };
D978FC20206EDBC800DDC47E /* SwiftTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D978FC1D206EDBC800DDC47E /* SwiftTests.swift */; };
D978FC21206EDBC800DDC47E /* TestServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = D978FC1E206EDBC800DDC47E /* TestServer.swift */; };
D978FC22206EDBC800DDC47E /* TestSocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = D978FC1F206EDBC800DDC47E /* TestSocket.swift */; };
D978FC24206EDBDD00DDC47E /* SecureSocketServer.p12 in Resources */ = {isa = PBXBuildFile; fileRef = D978FC23206EDBDD00DDC47E /* SecureSocketServer.p12 */; };
D978FC27206EDC5200DDC47E /* GCDAsyncSocketReadTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D978FC26206EDC5200DDC47E /* GCDAsyncSocketReadTests.swift */; };
871084EE23FA9C050004F896 /* GCDAsyncUdpSocketConnectionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 871084EC23FA9C050004F896 /* GCDAsyncUdpSocketConnectionTests.m */; };
871084EF23FA9C050004F896 /* GCDAsyncSocketConnectionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 871084ED23FA9C050004F896 /* GCDAsyncSocketConnectionTests.m */; };
871084F623FA9C140004F896 /* TestServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 871084F123FA9C140004F896 /* TestServer.swift */; };
871084F723FA9C140004F896 /* SwiftTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 871084F223FA9C140004F896 /* SwiftTests.swift */; };
871084F823FA9C140004F896 /* SecureSocketServer.p12 in Resources */ = {isa = PBXBuildFile; fileRef = 871084F323FA9C140004F896 /* SecureSocketServer.p12 */; };
871084F923FA9C140004F896 /* TestSocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 871084F423FA9C140004F896 /* TestSocket.swift */; };
871084FA23FA9C140004F896 /* GCDAsyncSocketReadTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 871084F523FA9C140004F896 /* GCDAsyncSocketReadTests.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
08EFE8D9A08D54EDB815BD18 /* Pods-CocoaAsyncSocketTestsMac.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CocoaAsyncSocketTestsMac.debug.xcconfig"; path = "Pods/Target Support Files/Pods-CocoaAsyncSocketTestsMac/Pods-CocoaAsyncSocketTestsMac.debug.xcconfig"; sourceTree = "<group>"; };
1859AD1F79C285DFDC07C37C /* Pods_CocoaAsyncSocketTestsMac.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_CocoaAsyncSocketTestsMac.framework; sourceTree = BUILT_PRODUCTS_DIR; };
2DBCA5C71B8CF4F3004F3128 /* GCDAsyncSocketUNTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDAsyncSocketUNTests.m; sourceTree = SOURCE_ROOT; };
4CB28BA2043D8CD03AFA18E8 /* Pods-CocoaAsyncSocketTestsMac.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CocoaAsyncSocketTestsMac.release.xcconfig"; path = "Pods/Target Support Files/Pods-CocoaAsyncSocketTestsMac/Pods-CocoaAsyncSocketTestsMac.release.xcconfig"; sourceTree = "<group>"; };
D938B4E31B752ED500FE8AB3 /* GCDAsyncSocketConnectionTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GCDAsyncSocketConnectionTests.m; path = ../Shared/GCDAsyncSocketConnectionTests.m; sourceTree = "<group>"; };
D978FC1D206EDBC800DDC47E /* SwiftTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SwiftTests.swift; path = ../Shared/SwiftTests.swift; sourceTree = "<group>"; };
D978FC1E206EDBC800DDC47E /* TestServer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TestServer.swift; path = ../Shared/TestServer.swift; sourceTree = "<group>"; };
D978FC1F206EDBC800DDC47E /* TestSocket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TestSocket.swift; path = ../Shared/TestSocket.swift; sourceTree = "<group>"; };
D978FC23206EDBDD00DDC47E /* SecureSocketServer.p12 */ = {isa = PBXFileReference; lastKnownFileType = file; name = SecureSocketServer.p12; path = ../Shared/SecureSocketServer.p12; sourceTree = "<group>"; };
D978FC26206EDC5200DDC47E /* GCDAsyncSocketReadTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = GCDAsyncSocketReadTests.swift; path = ../Shared/GCDAsyncSocketReadTests.swift; sourceTree = "<group>"; };
871084EC23FA9C050004F896 /* GCDAsyncUdpSocketConnectionTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDAsyncUdpSocketConnectionTests.m; sourceTree = "<group>"; };
871084ED23FA9C050004F896 /* GCDAsyncSocketConnectionTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDAsyncSocketConnectionTests.m; sourceTree = "<group>"; };
871084F123FA9C140004F896 /* TestServer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestServer.swift; sourceTree = "<group>"; };
871084F223FA9C140004F896 /* SwiftTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftTests.swift; sourceTree = "<group>"; };
871084F323FA9C140004F896 /* SecureSocketServer.p12 */ = {isa = PBXFileReference; lastKnownFileType = file; path = SecureSocketServer.p12; sourceTree = "<group>"; };
871084F423FA9C140004F896 /* TestSocket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestSocket.swift; sourceTree = "<group>"; };
871084F523FA9C140004F896 /* GCDAsyncSocketReadTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GCDAsyncSocketReadTests.swift; sourceTree = "<group>"; };
D9BC0D8D1A0458EF0059D906 /* CocoaAsyncSocketTestsMac.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CocoaAsyncSocketTestsMac.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
D9BC0D901A0458EF0059D906 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -61,15 +63,34 @@
name = Frameworks;
sourceTree = "<group>";
};
871084EB23FA9C050004F896 /* ObjC */ = {
isa = PBXGroup;
children = (
871084EC23FA9C050004F896 /* GCDAsyncUdpSocketConnectionTests.m */,
871084ED23FA9C050004F896 /* GCDAsyncSocketConnectionTests.m */,
);
name = ObjC;
path = ../Shared/ObjC;
sourceTree = "<group>";
};
871084F023FA9C140004F896 /* Swift */ = {
isa = PBXGroup;
children = (
871084F123FA9C140004F896 /* TestServer.swift */,
871084F223FA9C140004F896 /* SwiftTests.swift */,
871084F323FA9C140004F896 /* SecureSocketServer.p12 */,
871084F423FA9C140004F896 /* TestSocket.swift */,
871084F523FA9C140004F896 /* GCDAsyncSocketReadTests.swift */,
);
name = Swift;
path = ../Shared/Swift;
sourceTree = "<group>";
};
D938B4E61B752ED800FE8AB3 /* Shared */ = {
isa = PBXGroup;
children = (
D978FC26206EDC5200DDC47E /* GCDAsyncSocketReadTests.swift */,
D978FC1D206EDBC800DDC47E /* SwiftTests.swift */,
D978FC23206EDBDD00DDC47E /* SecureSocketServer.p12 */,
D978FC1E206EDBC800DDC47E /* TestServer.swift */,
D978FC1F206EDBC800DDC47E /* TestSocket.swift */,
D938B4E31B752ED500FE8AB3 /* GCDAsyncSocketConnectionTests.m */,
871084F023FA9C140004F896 /* Swift */,
871084EB23FA9C050004F896 /* ObjC */,
);
name = Shared;
sourceTree = "<group>";
Expand Down Expand Up @@ -179,7 +200,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D978FC24206EDBDD00DDC47E /* SecureSocketServer.p12 in Resources */,
871084F823FA9C140004F896 /* SecureSocketServer.p12 in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -244,12 +265,13 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D978FC22206EDBC800DDC47E /* TestSocket.swift in Sources */,
D978FC21206EDBC800DDC47E /* TestServer.swift in Sources */,
D978FC27206EDC5200DDC47E /* GCDAsyncSocketReadTests.swift in Sources */,
871084F623FA9C140004F896 /* TestServer.swift in Sources */,
871084EF23FA9C050004F896 /* GCDAsyncSocketConnectionTests.m in Sources */,
871084F923FA9C140004F896 /* TestSocket.swift in Sources */,
871084F723FA9C140004F896 /* SwiftTests.swift in Sources */,
2DBCA5C81B8CF4F3004F3128 /* GCDAsyncSocketUNTests.m in Sources */,
D938B4E51B752ED500FE8AB3 /* GCDAsyncSocketConnectionTests.m in Sources */,
D978FC20206EDBC800DDC47E /* SwiftTests.swift in Sources */,
871084FA23FA9C140004F896 /* GCDAsyncSocketReadTests.swift in Sources */,
871084EE23FA9C050004F896 /* GCDAsyncUdpSocketConnectionTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,12 @@ class SwiftTests: XCTestCase, GCDAsyncSocketDelegate {

let socketFD4 = Darwin.socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
XCTAssertTrue(socketFD4 >= 0, "Failed to create IPv4 socket");


let addrSize = MemoryLayout.size(ofValue: addr)

withUnsafeMutablePointer(to: &addr) {
$0.withMemoryRebound(to: sockaddr.self, capacity: 1) {
let errorCode = Darwin.connect(socketFD4, $0, socklen_t(MemoryLayout.size(ofValue: addr)));
let errorCode = Darwin.connect(socketFD4, $0, socklen_t(addrSize));
XCTAssertTrue(errorCode == 0, "Failed to connect to server");
}
}
Expand Down Expand Up @@ -194,10 +196,12 @@ class SwiftTests: XCTestCase, GCDAsyncSocketDelegate {

let socketFD6 = Darwin.socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP)
XCTAssertTrue(socketFD6 >= 0, "Failed to create IPv4 socket");


let addrSize = MemoryLayout.size(ofValue: addr)

withUnsafeMutablePointer(to: &addr) {
$0.withMemoryRebound(to: sockaddr.self, capacity: 1) {
let errorCode = Darwin.connect(socketFD6, $0, socklen_t(MemoryLayout.size(ofValue: addr)));
let errorCode = Darwin.connect(socketFD6, $0, socklen_t(addrSize));
XCTAssertTrue(errorCode == 0, "Failed to connect to server");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ class TestServer: NSObject {
* https://developer.apple.com/documentation/security/certificate_key_and_trust_services/identities/importing_an_identity
*/
static var identity: SecIdentity = {
let bundle = Bundle(for: TestServer.self)

guard let url = bundle.url(forResource: "SecureSocketServer", withExtension: "p12") else {
guard let url = credentialsFileURL else {
fatalError("Missing the server cert resource from the bundle")
}

Expand All @@ -47,6 +46,20 @@ class TestServer: NSObject {
}
}()

static private var credentialsFileURL: URL? {
let fileName = "SecureSocketServer"
let fileExtension = "p12"

#if SWIFT_PACKAGE
let thisSourceFile = URL(fileURLWithPath: #file)
let thisSourceDirectory = thisSourceFile.deletingLastPathComponent()
return thisSourceDirectory.appendingPathComponent("\(fileName).\(fileExtension)")
#else
let bundle = Bundle(for: TestServer.self)
return bundle.url(forResource: fileName, withExtension: fileExtension)
#endif
}

private static func randomValidPort() -> UInt16 {
let minPort = UInt32(1024)
let maxPort = UInt32(UINT16_MAX)
Expand All @@ -59,8 +72,8 @@ class TestServer: NSObject {

typealias Callback = TestSocket.Callback

var onAccept: Callback
var onDisconnect: Callback
var onAccept: Callback = nil
var onDisconnect: Callback = nil

let port: UInt16 = TestServer.randomValidPort()
let queue = DispatchQueue(label: "com.asyncSocket.TestServerDelegate")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ class TestSocket: NSObject {

typealias Callback = Optional<() -> Void>

var onConnect: Callback
var onSecure: Callback
var onRead: Callback
var onWrite: Callback
var onDisconnect: Callback
var onConnect: Callback = nil
var onSecure: Callback = nil
var onRead: Callback = nil
var onWrite: Callback = nil
var onDisconnect: Callback = nil

// MARK: Counters

Expand Down
Loading