mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-05 04:47:40 +03:00
Fix calculate reader headroom
This commit is contained in:
parent
4ab8cac5eb
commit
8fb1634c9a
1 changed files with 26 additions and 2 deletions
|
@ -98,6 +98,29 @@ func CalculateFrontHeadroom(writer any) int {
|
||||||
return headroom
|
return headroom
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func calculateReaderFrontHeadroom(reader any) int {
|
||||||
|
var headroom int
|
||||||
|
for {
|
||||||
|
if reader == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if lazyRoom, isLazy := reader.(LazyHeadroom); isLazy && lazyRoom.LazyHeadroom() {
|
||||||
|
return DefaultHeadroom
|
||||||
|
}
|
||||||
|
if headroomWriter, needHeadroom := reader.(FrontHeadroom); needHeadroom {
|
||||||
|
headroom += headroomWriter.FrontHeadroom()
|
||||||
|
}
|
||||||
|
if upstreamWriter, hasUpstreamWriter := reader.(WithUpstreamReader); hasUpstreamWriter {
|
||||||
|
reader = upstreamWriter.UpstreamReader()
|
||||||
|
} else if upstream, hasUpstream := reader.(common.WithUpstream); hasUpstream {
|
||||||
|
reader = upstream.Upstream()
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return headroom
|
||||||
|
}
|
||||||
|
|
||||||
func CalculateRearHeadroom(writer any) int {
|
func CalculateRearHeadroom(writer any) int {
|
||||||
var headroom int
|
var headroom int
|
||||||
for {
|
for {
|
||||||
|
@ -131,14 +154,15 @@ type WriterWithMTU interface {
|
||||||
|
|
||||||
func CalculateMTU(reader any, writer any) int {
|
func CalculateMTU(reader any, writer any) int {
|
||||||
readerMTU := calculateReaderMTU(reader)
|
readerMTU := calculateReaderMTU(reader)
|
||||||
|
readerHeadroom := calculateReaderFrontHeadroom(reader)
|
||||||
writerMTU := calculateWriterMTU(writer)
|
writerMTU := calculateWriterMTU(writer)
|
||||||
if readerMTU > writerMTU {
|
if readerMTU > writerMTU {
|
||||||
return readerMTU
|
return readerMTU + readerHeadroom
|
||||||
}
|
}
|
||||||
if writerMTU > buf.BufferSize {
|
if writerMTU > buf.BufferSize {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
return writerMTU
|
return writerMTU + readerHeadroom
|
||||||
}
|
}
|
||||||
|
|
||||||
func calculateReaderMTU(reader any) int {
|
func calculateReaderMTU(reader any) int {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue