Skip to content

Commit

Permalink
fix some build regressions with Swift 5.9 on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
lhoward committed Jan 11, 2024
1 parent 6a91bba commit 37faad0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
5 changes: 5 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ PlatformDependencies = [
PlatformTransportPackage = .package(url: "https://github.com/swhitty/FlyingFox", branch: "main")

PlatformDependencies = [
.product(
name: "FlyingFox",
package: "FlyingFox",
condition: .when(platforms: [.macOS, .iOS])
),
.product(
name: "FlyingSocks",
package: "FlyingFox",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,9 @@ import FlyingSocks
import Foundation
import SwiftOCA

/// A remote WebSocket endpoint
actor AES70OCP1FlyingFoxController: AES70ControllerPrivate {
var subscriptions = [OcaONo: NSMutableSet]()

private let input: AsyncStream<WSMessage>
private let output: AsyncStream<WSMessage>.Continuation
private var endpoint: AES70OCP1FlyingFoxDeviceEndpoint?

private var keepAliveTask: Task<(), Error>?
private var lastMessageReceivedTime = Date.distantPast

private var messages: AnyAsyncSequence<(Ocp1Message, Bool)> {
input.flatMap {
extension AsyncStream where Element == WSMessage {
fileprivate var ocp1DecodedMessages: AnyAsyncSequence<(Ocp1Message, Bool)> {
flatMap {
// TODO: handle OCP.1 PDUs split over multiple frames
guard case let .data(data) = $0 else {
throw Ocp1Error.invalidMessageType
Expand All @@ -54,20 +44,30 @@ actor AES70OCP1FlyingFoxController: AES70ControllerPrivate {
return messages.map { ($0, messageType == .ocaCmdRrq) }.async
}.eraseToAnyAsyncSequence()
}
}

/// A remote WebSocket endpoint
actor AES70OCP1FlyingFoxController: AES70ControllerPrivate {
var subscriptions = [OcaONo: NSMutableSet]()

private let outputStream: AsyncStream<WSMessage>.Continuation
private var endpoint: AES70OCP1FlyingFoxDeviceEndpoint?

private var keepAliveTask: Task<(), Error>?
private var lastMessageReceivedTime = Date.distantPast

init(
input: AsyncStream<WSMessage>,
output: AsyncStream<WSMessage>.Continuation,
inputStream: AsyncStream<WSMessage>,
outputStream: AsyncStream<WSMessage>.Continuation,
endpoint: AES70OCP1FlyingFoxDeviceEndpoint?
) {
self.input = input
self.output = output
self.outputStream = outputStream
self.endpoint = endpoint

Task { @AES70Device in
await self.endpoint?.register(controller: self)
do {
for try await (message, rrq) in await messages {
for try await (message, rrq) in inputStream.ocp1DecodedMessages {
var response: Ocp1Response?

await self.updateLastMessageReceivedTime()
Expand Down Expand Up @@ -106,22 +106,22 @@ actor AES70OCP1FlyingFoxController: AES70ControllerPrivate {
await self.endpoint?.logger.logError(error, on: self)
}
await self.endpoint?.deregister(controller: self)
try? await self.close()
await self.close()
}
}

var connectionIsStale: Bool {
private var connectionIsStale: Bool {
lastMessageReceivedTime + 3 * TimeInterval(keepAliveInterval) /
TimeInterval(NSEC_PER_SEC) < Date()
}

var keepAliveInterval: UInt64 = 0 {
private var keepAliveInterval: UInt64 = 0 {
didSet {
if keepAliveInterval != 0, keepAliveInterval != oldValue {
keepAliveTask = Task<(), Error> {
repeat {
if connectionIsStale {
try await self.close()
await self.close()
break
}
try await sendKeepAlive()
Expand All @@ -135,7 +135,7 @@ actor AES70OCP1FlyingFoxController: AES70ControllerPrivate {
}
}

func setKeepAliveInterval(_ keepAliveInterval: UInt64) {
private func setKeepAliveInterval(_ keepAliveInterval: UInt64) {
self.keepAliveInterval = keepAliveInterval
}

Expand All @@ -148,16 +148,16 @@ actor AES70OCP1FlyingFoxController: AES70ControllerPrivate {
messages,
type: messageType
)
output.yield(.data(messagePduData))
outputStream.yield(.data(messagePduData))
}

private func sendKeepAlive() async throws {
let keepAlive = Ocp1KeepAlive1(heartBeatTime: OcaUint16(keepAliveInterval / NSEC_PER_SEC))
try await sendMessage(keepAlive, type: .ocaKeepAlive)
}

func close() async throws {
output.finish()
private func close() async {
outputStream.finish()

keepAliveTask?.cancel()
keepAliveTask = nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

#if os(macOS) || os(iOS)

@preconcurrency
import AsyncExtensions
@preconcurrency
@_implementationOnly
import FlyingFox
@_implementationOnly
Expand Down Expand Up @@ -54,8 +52,8 @@ public final class AES70OCP1FlyingFoxDeviceEndpoint: AES70BonjourRegistrableDevi
{
AsyncStream<WSMessage> { continuation in
_ = AES70OCP1FlyingFoxController(
input: client,
output: continuation,
inputStream: client,
outputStream: continuation,
endpoint: endpoint
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,7 @@ public final class AES70OCP1FlyingSocksDeviceEndpoint: AES70BonjourRegistrableDe
try await withThrowingDiscardingTaskGroup { [logger] group in
for try await socket in socket.sockets {
group.addTask {
try await self.handleController(AES70OCP1FlyingSocksController(
socket: socket,
logger: logger
))
try await self.handleController(AES70OCP1FlyingSocksController(socket: socket))
}
}
}
Expand Down

0 comments on commit 37faad0

Please sign in to comment.