Skip to content

Commit 40fc1bb

Browse files
authored
Merge pull request #6 from 0xWDG/linux-support
Linux Support
2 parents fba0d06 + 8227e9c commit 40fc1bb

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

.github/workflows/test.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ jobs:
1717
swiftlint --reporter github-actions-logging --strict
1818
1919
test_linux:
20-
if: false
2120
runs-on: ubuntu-latest
22-
continue-on-error: true
2321
steps:
2422
- uses: actions/checkout@v3
2523

24+
- name: Envorionment
25+
run: swift --version
26+
2627
- name: Swift test
2728
run: swift test
2829

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
This class is meant for simple network tasks.
44

5+
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2F0xWDG%2FSimpleNetworking%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/0xWDG/SimpleNetworking) [![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2F0xWDG%2FSimpleNetworking%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/0xWDG/SimpleNetworking)
6+
57
## Requirements
68

79
- Swift 5.9+ (Xcode 15+)
8-
- iOS 13+, macOS 10.15+
10+
- iOS 13+, macOS 10.15+, tvOS, watchOS, Linux
911

1012
## Installation
1113

Sources/SimpleNetworking/SimpleNetworking/WebSocket.swift

+7
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ extension SimpleNetworking {
2929

3030
/// Read message from websocket
3131
private func readMessage() {
32+
#if !canImport(FoundationNetworking)
33+
// It looks like it's not supported on Linux (*yet)
34+
// error: extra trailing closure passed in call
35+
// WSSocket?.receive { result in
36+
// ^~~~~~~~~~~
37+
3238
WSSocket?.receive { result in
3339
do {
3440
let message = try result.get()
@@ -58,5 +64,6 @@ extension SimpleNetworking {
5864
}
5965

6066
WSConnectionTries += 1
67+
#endif
6168
}
6269
}

Sources/SimpleNetworking/SimpleNetworking/exec.swift

+14-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,23 @@ extension SimpleNetworking {
2323
/// - line: Caller's line number
2424
/// - function: Caller's function name
2525
/// - Returns: ``NetworkResponse``
26-
internal func exec(
26+
internal func exec( // swiftlint:disable:this function_body_length
2727
with request: URLRequest,
2828
file: String = #file,
2929
line: Int = #line,
3030
function: String = #function) async -> NetworkResponse {
31+
#if canImport(FoundationNetworking)
32+
// Linux support.
33+
do {
34+
return try await withCheckedThrowingContinuation { continuation in
35+
exec(with: request, completionHandler: { response in
36+
continuation.resume(returning: response)
37+
}, file: file, line: line, function: function)
38+
}
39+
} catch {
40+
return .init(error: error, request: request)
41+
}
42+
#else
3143
if let url = request.url,
3244
let mock = mockData[url.absoluteString] {
3345
let data = mock.data ?? .init()
@@ -46,7 +58,6 @@ extension SimpleNetworking {
4658

4759
if let cookies = SimpleNetworking.cookies {
4860
for cookieData in cookies {
49-
// _FIXME: Can crash??
5061
self.session?.configuration.httpCookieStorage?.setCookie(cookieData)
5162
}
5263
}
@@ -85,6 +96,7 @@ extension SimpleNetworking {
8596
} catch {
8697
return .init(error: error, request: request)
8798
}
99+
#endif
88100
}
89101

90102
/// Execute request (legacy, non-async)

0 commit comments

Comments
 (0)