Skip to content

Commit

Permalink
Remove legacy buffer header
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Dec 1, 2023
1 parent 78086b0 commit 575186e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 16 deletions.
14 changes: 4 additions & 10 deletions common/buf/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
E "github.com/sagernet/sing/common/exceptions"
)

const ReversedHeader = 1024

type Buffer struct {
data []byte
start int
Expand All @@ -25,17 +23,13 @@ type Buffer struct {
func New() *Buffer {
return &Buffer{
data: Get(BufferSize),
start: ReversedHeader,
end: ReversedHeader,
managed: true,
}
}

func NewPacket() *Buffer {
return &Buffer{
data: Get(UDPBufferSize),
start: ReversedHeader,
end: ReversedHeader,
managed: true,
}
}
Expand Down Expand Up @@ -277,13 +271,13 @@ func (b *Buffer) Resize(start, end int) {
}

func (b *Buffer) Reset() {
b.start = ReversedHeader
b.end = ReversedHeader
b.start = 0
b.end = 0
}

// Deprecated: use Reset instead.
func (b *Buffer) FullReset() {
b.start = 0
b.end = 0
b.Reset()
}

func (b *Buffer) IncRef() {
Expand Down
2 changes: 1 addition & 1 deletion common/bufio/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (w *BufferedWriter) Write(p []byte) (n int, err error) {
if err != nil {
return
}
w.buffer.FullReset()
w.buffer.Reset()
}
}

Expand Down
6 changes: 3 additions & 3 deletions common/bufio/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (c *ChunkReader) ReadBuffer(buffer *buf.Buffer) error {
} else if !c.cache.IsEmpty() {
return common.Error(buffer.ReadFrom(c.cache))
}
c.cache.FullReset()
c.cache.Reset()
err := c.upstream.ReadBuffer(c.cache)
if err != nil {
c.cache.Release()
Expand All @@ -46,7 +46,7 @@ func (c *ChunkReader) Read(p []byte) (n int, err error) {
} else if !c.cache.IsEmpty() {
return c.cache.Read(p)
}
c.cache.FullReset()
c.cache.Reset()
err = c.upstream.ReadBuffer(c.cache)
if err != nil {
c.cache.Release()
Expand All @@ -70,7 +70,7 @@ func (c *ChunkReader) ReadChunk() (*buf.Buffer, error) {
} else if !c.cache.IsEmpty() {
return c.cache, nil
}
c.cache.FullReset()
c.cache.Reset()
err := c.upstream.ReadBuffer(c.cache)
if err != nil {
c.cache.Release()
Expand Down
4 changes: 2 additions & 2 deletions common/uot/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (c *ServerConn) loopInput() {
if err != nil {
break
}
buffer.FullReset()
buffer.Reset()
_, err = buffer.ReadFullFrom(c.inputReader, int(length))
if err != nil {
break
Expand All @@ -95,7 +95,7 @@ func (c *ServerConn) loopOutput() {
buffer := buf.NewPacket()
defer buffer.Release()
for {
buffer.FullReset()
buffer.Reset()
n, addr, err := buffer.ReadPacketFrom(c)
if err != nil {
break
Expand Down

0 comments on commit 575186e

Please sign in to comment.