Skip to content

Commit

Permalink
Improve: #1038 and #1041
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamacro committed Oct 28, 2020
1 parent 9a62b10 commit b98e9ea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 5 additions & 4 deletions tunnel/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tunnel

import (
"net"
"sync/atomic"
"time"

C "github.com/Dreamacro/clash/constant"
Expand Down Expand Up @@ -38,15 +39,15 @@ 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
}

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
}

Expand Down Expand Up @@ -93,15 +94,15 @@ 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
}

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
}

Expand Down
5 changes: 4 additions & 1 deletion tunnel/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b98e9ea

Please sign in to comment.