Skip to content

Commit

Permalink
fix build break on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnzhou committed Jun 21, 2024
1 parent d966586 commit f23382b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions Sources/LCLPing/HTTP/URLSessionClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ final class URLSessionClient: NSObject, Pingable {
func start() -> EventLoopFuture<PingSummary> {
let request = makeRequest(using: config)

#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
let now = Date()
#else
let now = DispatchTime.now()
#endif
for cnt in 0..<self.config.count {
logger.debug("Scheduled #\(cnt) request")
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
self.session?.delegateQueue.schedule(after: .init(now + config.readTimeout.second * Double(cnt))) {
guard let session = self.session else {
logger.debug("Session has been invalidated.")
Expand All @@ -58,6 +63,18 @@ final class URLSessionClient: NSObject, Pingable {
self.taskToSeqNum[id] = cnt
dataTask.resume()
}
#else
self.session?.delegateQueue.underlyingQueue?.asyncAfter(deadline: now + config.readTimeout.second * Double(cnt)) {
guard let session = self.session else {
logger.debug("Session has been invalidated.")
return
}
let dataTask = session.dataTask(with: request)
let id = dataTask.taskIdentifier
self.taskToSeqNum[id] = cnt
dataTask.resume()
}
#endif
}

return self.promise.futureResult
Expand Down
2 changes: 1 addition & 1 deletion Sources/LCLPing/Reachability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public func reachable(via method: PingType,
let result = try client.start().wait()
return result.isSimpleMajority()
case .icmp:
let icmpConfig = ICMPPingClient.Configuration(endpoint: .ipv4(host, 0), count: strategy.count)
let icmpConfig = try ICMPPingClient.Configuration(endpoint: .ipv4(host, 0), count: strategy.count)
let client = ICMPPingClient(configuration: icmpConfig)
let result = try client.start().wait()
return result.isSimpleMajority()
Expand Down

0 comments on commit f23382b

Please sign in to comment.