mirror of
https://github.com/wanghongenpin/proxypin.git
synced 2026-03-29 06:59:46 +08:00
34 lines
767 B
Swift
34 lines
767 B
Swift
//
|
|
// ClientPacketWriter.swift
|
|
// ProxyPin
|
|
//
|
|
// Created by wanghongen on 2024/9/
|
|
|
|
import Foundation
|
|
import NetworkExtension
|
|
|
|
class ClientPacketWriter: NSObject {
|
|
private var packetFlow: NEPacketTunnelFlow
|
|
private let packetQueue = DispatchQueue(label: "packetQueue", attributes: .concurrent)
|
|
private var isShutdown = false
|
|
|
|
init(packetFlow: NEPacketTunnelFlow) {
|
|
self.packetFlow = packetFlow
|
|
}
|
|
|
|
func write(data: Data) {
|
|
if !self.isShutdown {
|
|
packetQueue.async {
|
|
self.packetFlow.writePackets([data], withProtocols: [NSNumber(value: AF_INET)])
|
|
}
|
|
}
|
|
}
|
|
|
|
func shutdown() {
|
|
packetQueue.async(flags: .barrier) {
|
|
self.isShutdown = true
|
|
}
|
|
}
|
|
}
|
|
|