mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-04 20:37:40 +03:00
Remove legacy buffer header
This commit is contained in:
parent
6538da6895
commit
30bf59995f
4 changed files with 11 additions and 17 deletions
|
@ -11,8 +11,6 @@ import (
|
||||||
E "github.com/sagernet/sing/common/exceptions"
|
E "github.com/sagernet/sing/common/exceptions"
|
||||||
)
|
)
|
||||||
|
|
||||||
const ReversedHeader = 1024
|
|
||||||
|
|
||||||
type Buffer struct {
|
type Buffer struct {
|
||||||
data []byte
|
data []byte
|
||||||
start int
|
start int
|
||||||
|
@ -25,8 +23,6 @@ type Buffer struct {
|
||||||
func New() *Buffer {
|
func New() *Buffer {
|
||||||
return &Buffer{
|
return &Buffer{
|
||||||
data: Get(BufferSize),
|
data: Get(BufferSize),
|
||||||
start: ReversedHeader,
|
|
||||||
end: ReversedHeader,
|
|
||||||
managed: true,
|
managed: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,8 +30,6 @@ func New() *Buffer {
|
||||||
func NewPacket() *Buffer {
|
func NewPacket() *Buffer {
|
||||||
return &Buffer{
|
return &Buffer{
|
||||||
data: Get(UDPBufferSize),
|
data: Get(UDPBufferSize),
|
||||||
start: ReversedHeader,
|
|
||||||
end: ReversedHeader,
|
|
||||||
managed: true,
|
managed: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -277,15 +271,15 @@ func (b *Buffer) Resize(start, end int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Buffer) Reset() {
|
func (b *Buffer) Reset() {
|
||||||
b.start = ReversedHeader
|
|
||||||
b.end = ReversedHeader
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Buffer) FullReset() {
|
|
||||||
b.start = 0
|
b.start = 0
|
||||||
b.end = 0
|
b.end = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated: use Reset instead.
|
||||||
|
func (b *Buffer) FullReset() {
|
||||||
|
b.Reset()
|
||||||
|
}
|
||||||
|
|
||||||
func (b *Buffer) IncRef() {
|
func (b *Buffer) IncRef() {
|
||||||
atomic.AddInt32(&b.refs, 1)
|
atomic.AddInt32(&b.refs, 1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ func (w *BufferedWriter) Write(p []byte) (n int, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.buffer.FullReset()
|
w.buffer.Reset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ func (c *ChunkReader) ReadBuffer(buffer *buf.Buffer) error {
|
||||||
} else if !c.cache.IsEmpty() {
|
} else if !c.cache.IsEmpty() {
|
||||||
return common.Error(buffer.ReadFrom(c.cache))
|
return common.Error(buffer.ReadFrom(c.cache))
|
||||||
}
|
}
|
||||||
c.cache.FullReset()
|
c.cache.Reset()
|
||||||
err := c.upstream.ReadBuffer(c.cache)
|
err := c.upstream.ReadBuffer(c.cache)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.cache.Release()
|
c.cache.Release()
|
||||||
|
@ -46,7 +46,7 @@ func (c *ChunkReader) Read(p []byte) (n int, err error) {
|
||||||
} else if !c.cache.IsEmpty() {
|
} else if !c.cache.IsEmpty() {
|
||||||
return c.cache.Read(p)
|
return c.cache.Read(p)
|
||||||
}
|
}
|
||||||
c.cache.FullReset()
|
c.cache.Reset()
|
||||||
err = c.upstream.ReadBuffer(c.cache)
|
err = c.upstream.ReadBuffer(c.cache)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.cache.Release()
|
c.cache.Release()
|
||||||
|
@ -70,7 +70,7 @@ func (c *ChunkReader) ReadChunk() (*buf.Buffer, error) {
|
||||||
} else if !c.cache.IsEmpty() {
|
} else if !c.cache.IsEmpty() {
|
||||||
return c.cache, nil
|
return c.cache, nil
|
||||||
}
|
}
|
||||||
c.cache.FullReset()
|
c.cache.Reset()
|
||||||
err := c.upstream.ReadBuffer(c.cache)
|
err := c.upstream.ReadBuffer(c.cache)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.cache.Release()
|
c.cache.Release()
|
||||||
|
|
|
@ -77,7 +77,7 @@ func (c *ServerConn) loopInput() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
buffer.FullReset()
|
buffer.Reset()
|
||||||
_, err = buffer.ReadFullFrom(c.inputReader, int(length))
|
_, err = buffer.ReadFullFrom(c.inputReader, int(length))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
|
@ -95,7 +95,7 @@ func (c *ServerConn) loopOutput() {
|
||||||
buffer := buf.NewPacket()
|
buffer := buf.NewPacket()
|
||||||
defer buffer.Release()
|
defer buffer.Release()
|
||||||
for {
|
for {
|
||||||
buffer.FullReset()
|
buffer.Reset()
|
||||||
n, addr, err := buffer.ReadPacketFrom(c)
|
n, addr, err := buffer.ReadPacketFrom(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue