mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2024-11-15 13:41:23 +08:00
29 lines
525 B
Go
29 lines
525 B
Go
|
package adapters
|
||
|
|
||
|
import (
|
||
|
"net"
|
||
|
|
||
|
C "github.com/Dreamacro/clash/constant"
|
||
|
)
|
||
|
|
||
|
type TrafficTrack struct {
|
||
|
net.Conn
|
||
|
traffic *C.Traffic
|
||
|
}
|
||
|
|
||
|
func (tt *TrafficTrack) Read(b []byte) (int, error) {
|
||
|
n, err := tt.Conn.Read(b)
|
||
|
tt.traffic.Down() <- int64(n)
|
||
|
return n, err
|
||
|
}
|
||
|
|
||
|
func (tt *TrafficTrack) Write(b []byte) (int, error) {
|
||
|
n, err := tt.Conn.Write(b)
|
||
|
tt.traffic.Up() <- int64(n)
|
||
|
return n, err
|
||
|
}
|
||
|
|
||
|
func NewTrafficTrack(conn net.Conn, traffic *C.Traffic) *TrafficTrack {
|
||
|
return &TrafficTrack{traffic: traffic, Conn: conn}
|
||
|
}
|