punchnet-macos/Tun/Super/SDLSuperServiceProxy.swift
2026-05-21 23:57:24 +08:00

37 lines
812 B
Swift

//
// SDLSuperServiceProxy.swift
// punchnet
//
// Created by on 2026/5/21.
//
import Foundation
actor SDLSuperServiceProxy {
private var superService: SDLSuperService?
private var generation: UInt64 = 0
func replace(_ superService: SDLSuperService?) async {
self.generation &+= 1
let oldSuperService = self.superService
self.superService = superService
if oldSuperService !== superService {
await oldSuperService?.stop()
}
}
func stop() async {
self.generation &+= 1
let superService = self.superService
self.superService = nil
await superService?.stop()
}
func send(type: SDLPacketType, data: Data) async {
await self.superService?.send(type: type, data: data)
}
}