This commit is contained in:
Dreamacro 2020-10-29 00:32:31 +08:00
parent 9a62b1081d
commit b98e9ea202
2 changed files with 9 additions and 5 deletions

View file

@ -2,6 +2,7 @@ package tunnel
import (
"net"
"sync/atomic"
"time"
C "github.com/Dreamacro/clash/constant"
@ -38,7 +39,7 @@ func (tt *tcpTracker) Read(b []byte) (int, error) {
n, err := tt.Conn.Read(b)
download := int64(n)
tt.manager.PushDownloaded(download)
tt.DownloadTotal += download
atomic.AddInt64(&tt.DownloadTotal, download)
return n, err
}
@ -46,7 +47,7 @@ func (tt *tcpTracker) Write(b []byte) (int, error) {
n, err := tt.Conn.Write(b)
upload := int64(n)
tt.manager.PushUploaded(upload)
tt.UploadTotal += upload
atomic.AddInt64(&tt.UploadTotal, upload)
return n, err
}
@ -93,7 +94,7 @@ func (ut *udpTracker) ReadFrom(b []byte) (int, net.Addr, error) {
n, addr, err := ut.PacketConn.ReadFrom(b)
download := int64(n)
ut.manager.PushDownloaded(download)
ut.DownloadTotal += download
atomic.AddInt64(&ut.DownloadTotal, download)
return n, addr, err
}
@ -101,7 +102,7 @@ func (ut *udpTracker) WriteTo(b []byte, addr net.Addr) (int, error) {
n, err := ut.PacketConn.WriteTo(b, addr)
upload := int64(n)
ut.manager.PushUploaded(upload)
ut.UploadTotal += upload
atomic.AddInt64(&ut.UploadTotal, upload)
return n, err
}

View file

@ -42,7 +42,10 @@ func Add(req C.ServerAdapter) {
// AddPacket add udp Packet to queue
func AddPacket(packet *inbound.PacketAdapter) {
udpQueue <- packet
select {
case udpQueue <- packet:
default:
}
}
// Rules return all rules