0
mirror of https://github.com/XTLS/Xray-core.git synced 2025-06-19 06:39:48 +03:00

Add sniff timeoit

This commit is contained in:
风扇滑翔翼
2025-02-21 10:44:33 +00:00
committed by GitHub
parent be43f66b63
commit 95c2113250
7 changed files with 117 additions and 83 deletions

View File

@ -31,10 +31,18 @@ type cachedReader struct {
sync.Mutex
reader *pipe.Reader
cache buf.MultiBuffer
ReadBufferTimeout time.Duration
}
func (r *cachedReader) Cache(b *buf.Buffer) {
mb, _ := r.reader.ReadMultiBufferTimeout(time.Millisecond * 100)
var timeout time.Duration
if r.ReadBufferTimeout == 0 {
timeout = time.Millisecond * 100
} else {
timeout = r.ReadBufferTimeout
}
mb, _ := r.reader.ReadMultiBufferTimeout(timeout)
r.Lock()
if !mb.IsEmpty() {
r.cache, _ = buf.MergeMulti(r.cache, mb)
@ -360,6 +368,8 @@ func sniffer(ctx context.Context, cReader *cachedReader, metadataOnly bool, netw
sniffer := NewSniffer(ctx)
cReader.ReadBufferTimeout = sniffer.Timeout
metaresult, metadataErr := sniffer.SniffMetadata(ctx)
if metadataOnly {