swiftlib_sdlan/Sources/Punchnet/SDLFlowTracerActor.swift
2025-07-16 17:23:56 +08:00

44 lines
915 B
Swift

//
// SDLFlowTracer.swift
// Tun
//
// Created by on 2024/5/27.
//
import Foundation
//
actor SDLFlowTracerActor {
enum FlowType {
case forward
case p2p
case inbound
}
private var forwardFlowBytes: UInt32 = 0
private var p2pFlowBytes: UInt32 = 0
private var inFlowBytes: UInt32 = 0
func inc(num: Int, type: FlowType) {
switch type {
case .inbound:
self.inFlowBytes += UInt32(num)
case .forward:
self.forwardFlowBytes += UInt32(num)
case .p2p:
self.p2pFlowBytes += UInt32(num)
}
}
func reset() -> (UInt32, UInt32, UInt32) {
defer {
self.forwardFlowBytes = 0
self.inFlowBytes = 0
self.p2pFlowBytes = 0
}
return (forwardFlowBytes, p2pFlowBytes, inFlowBytes)
}
}