chore: support splice for direct outbound

This commit is contained in:
wwqgtxx
2023-04-25 23:01:05 +08:00
parent efcb278f61
commit 7bb5da3005
10 changed files with 76 additions and 9 deletions

View File

@ -1,11 +1,13 @@
package statistic
import (
"io"
"net"
"time"
"github.com/Dreamacro/clash/common/atomic"
"github.com/Dreamacro/clash/common/buf"
N "github.com/Dreamacro/clash/common/net"
"github.com/Dreamacro/clash/common/utils"
C "github.com/Dreamacro/clash/constant"
@ -61,6 +63,15 @@ func (tt *tcpTracker) ReadBuffer(buffer *buf.Buffer) (err error) {
return
}
func (tt *tcpTracker) UnwrapReader() (io.Reader, []N.CountFunc) {
return tt.Conn, []N.CountFunc{func(download int64) {
if tt.pushToManager {
tt.manager.PushDownloaded(download)
}
tt.DownloadTotal.Add(download)
}}
}
func (tt *tcpTracker) Write(b []byte) (int, error) {
n, err := tt.Conn.Write(b)
upload := int64(n)
@ -81,6 +92,15 @@ func (tt *tcpTracker) WriteBuffer(buffer *buf.Buffer) (err error) {
return
}
func (tt *tcpTracker) UnwrapWriter() (io.Writer, []N.CountFunc) {
return tt.Conn, []N.CountFunc{func(upload int64) {
if tt.pushToManager {
tt.manager.PushUploaded(upload)
}
tt.UploadTotal.Add(upload)
}}
}
func (tt *tcpTracker) Close() error {
tt.manager.Leave(tt)
return tt.Conn.Close()