mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-03 11:57:39 +03:00
parent
0f7de716ac
commit
c7ef05a85b
2 changed files with 9 additions and 10 deletions
|
@ -331,6 +331,10 @@ func (b *Buffer) Len() int {
|
|||
}
|
||||
|
||||
func (b *Buffer) Cap() int {
|
||||
return b.capacity
|
||||
}
|
||||
|
||||
func (b *Buffer) RawCap() int {
|
||||
return len(b.data)
|
||||
}
|
||||
|
||||
|
@ -338,10 +342,6 @@ func (b *Buffer) Bytes() []byte {
|
|||
return b.data[b.start:b.end]
|
||||
}
|
||||
|
||||
func (b *Buffer) Slice() []byte {
|
||||
return b.data[:b.capacity]
|
||||
}
|
||||
|
||||
func (b *Buffer) From(n int) []byte {
|
||||
return b.data[b.start+n : b.end]
|
||||
}
|
||||
|
|
|
@ -295,17 +295,16 @@ func WritePacketWithPool(originSource N.PacketReader, destinationConn N.PacketWr
|
|||
var notFirstTime bool
|
||||
for _, packetBuffer := range packetBuffers {
|
||||
buffer := buf.NewPacket()
|
||||
readBufferRaw := buffer.Slice()
|
||||
readBuffer := buf.With(readBufferRaw[:len(readBufferRaw)-rearHeadroom])
|
||||
readBuffer.Resize(frontHeadroom, 0)
|
||||
_, err = readBuffer.Write(packetBuffer.Buffer.Bytes())
|
||||
buffer.Resize(frontHeadroom, 0)
|
||||
buffer.Reserve(rearHeadroom)
|
||||
_, err = buffer.Write(packetBuffer.Buffer.Bytes())
|
||||
packetBuffer.Buffer.Release()
|
||||
if err != nil {
|
||||
buffer.Release()
|
||||
continue
|
||||
}
|
||||
dataLen := readBuffer.Len()
|
||||
buffer.Resize(readBuffer.Start(), dataLen)
|
||||
dataLen := buffer.Len()
|
||||
buffer.OverCap(rearHeadroom)
|
||||
err = destinationConn.WritePacket(buffer, packetBuffer.Destination)
|
||||
if err != nil {
|
||||
buffer.Leak()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue