mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-03 11:57:39 +03:00
Fix deadline reader
This commit is contained in:
parent
49166ac427
commit
221f066dba
4 changed files with 10 additions and 16 deletions
|
@ -107,7 +107,7 @@ func (r *packetReader) ReadPacket(buffer *buf.Buffer) (destination M.Socksaddr,
|
|||
}
|
||||
select {
|
||||
case <-r.done:
|
||||
go r.pipeReadFromBuffer(buffer.Cap(), buffer.Start())
|
||||
go r.pipeReadFromBuffer(buffer.FreeLen())
|
||||
default:
|
||||
}
|
||||
return r.readPacket(buffer)
|
||||
|
@ -123,9 +123,7 @@ func (r *packetReader) readPacket(buffer *buf.Buffer) (destination M.Socksaddr,
|
|||
}
|
||||
|
||||
func (r *packetReader) pipeReturnFromBuffer(result *packetReadResult, buffer *buf.Buffer) (M.Socksaddr, error) {
|
||||
buffer.Resize(result.buffer.Start(), 0)
|
||||
n := copy(buffer.FreeBytes(), result.buffer.Bytes())
|
||||
buffer.Truncate(n)
|
||||
n, _ := buffer.Write(result.buffer.Bytes())
|
||||
result.buffer.Advance(n)
|
||||
if !result.buffer.IsEmpty() {
|
||||
r.result <- result
|
||||
|
@ -136,9 +134,8 @@ func (r *packetReader) pipeReturnFromBuffer(result *packetReadResult, buffer *bu
|
|||
}
|
||||
}
|
||||
|
||||
func (r *packetReader) pipeReadFromBuffer(bufLen int, bufStart int) {
|
||||
buffer := buf.NewSize(bufLen)
|
||||
buffer.Advance(bufStart)
|
||||
func (r *packetReader) pipeReadFromBuffer(pLen int) {
|
||||
buffer := buf.NewSize(pLen)
|
||||
destination, err := r.TimeoutPacketReader.ReadPacket(buffer)
|
||||
r.result <- &packetReadResult{
|
||||
buffer: buffer,
|
||||
|
|
|
@ -61,7 +61,7 @@ func (r *fallbackPacketReader) ReadPacket(buffer *buf.Buffer) (destination M.Soc
|
|||
destination, err = r.TimeoutPacketReader.ReadPacket(buffer)
|
||||
return
|
||||
}
|
||||
go r.pipeReadFromBuffer(buffer.Cap(), buffer.Start())
|
||||
go r.pipeReadFromBuffer(buffer.FreeLen())
|
||||
default:
|
||||
}
|
||||
return r.readPacket(buffer)
|
||||
|
|
|
@ -100,7 +100,7 @@ func (r *reader) ReadBuffer(buffer *buf.Buffer) error {
|
|||
}
|
||||
select {
|
||||
case <-r.done:
|
||||
go r.pipeReadBuffer(buffer.Cap(), buffer.Start())
|
||||
go r.pipeReadBuffer(buffer.FreeLen())
|
||||
default:
|
||||
}
|
||||
return r.readBuffer(buffer)
|
||||
|
@ -116,9 +116,7 @@ func (r *reader) readBuffer(buffer *buf.Buffer) error {
|
|||
}
|
||||
|
||||
func (r *reader) pipeReturnBuffer(result *readResult, buffer *buf.Buffer) error {
|
||||
buffer.Resize(result.buffer.Start(), 0)
|
||||
n := copy(buffer.FreeBytes(), result.buffer.Bytes())
|
||||
buffer.Truncate(n)
|
||||
n, _ := buffer.Write(result.buffer.Bytes())
|
||||
result.buffer.Advance(n)
|
||||
if !result.buffer.IsEmpty() {
|
||||
r.result <- result
|
||||
|
@ -129,9 +127,8 @@ func (r *reader) pipeReturnBuffer(result *readResult, buffer *buf.Buffer) error
|
|||
}
|
||||
}
|
||||
|
||||
func (r *reader) pipeReadBuffer(bufLen int, bufStart int) {
|
||||
cacheBuffer := buf.NewSize(bufLen)
|
||||
cacheBuffer.Advance(bufStart)
|
||||
func (r *reader) pipeReadBuffer(pLen int) {
|
||||
cacheBuffer := buf.NewSize(pLen)
|
||||
err := r.ExtendedReader.ReadBuffer(cacheBuffer)
|
||||
r.result <- &readResult{
|
||||
buffer: cacheBuffer,
|
||||
|
|
|
@ -58,7 +58,7 @@ func (r *fallbackReader) ReadBuffer(buffer *buf.Buffer) error {
|
|||
defer r.inRead.Store(false)
|
||||
return r.ExtendedReader.ReadBuffer(buffer)
|
||||
}
|
||||
go r.pipeReadBuffer(buffer.Cap(), buffer.Start())
|
||||
go r.pipeReadBuffer(buffer.FreeLen())
|
||||
default:
|
||||
}
|
||||
return r.readBuffer(buffer)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue