mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-03 03:47:38 +03:00
Deprecate stack buffer
This commit is contained in:
parent
d852e9c03d
commit
c68251b6d0
18 changed files with 28 additions and 399 deletions
|
@ -64,9 +64,7 @@ func (c *AssociatePacketConn) ReadFrom(p []byte) (n int, addr net.Addr, err erro
|
|||
//warn:unsafe
|
||||
func (c *AssociatePacketConn) WriteTo(p []byte, addr net.Addr) (n int, err error) {
|
||||
destination := M.SocksaddrFromNet(addr)
|
||||
_buffer := buf.StackNewSize(3 + M.SocksaddrSerializer.AddrPortLen(destination) + len(p))
|
||||
defer common.KeepAlive(_buffer)
|
||||
buffer := common.Dup(_buffer)
|
||||
buffer := buf.NewSize(3 + M.SocksaddrSerializer.AddrPortLen(destination) + len(p))
|
||||
defer buffer.Release()
|
||||
common.Must(buffer.WriteZeroN(3))
|
||||
err = M.SocksaddrSerializer.WriteAddrPort(buffer, destination)
|
||||
|
|
|
@ -40,9 +40,7 @@ func NewVectorisedAssociateConn(conn net.Conn, writer N.VectorisedWriter, remote
|
|||
}
|
||||
|
||||
func (v *VectorisedAssociatePacketConn) WriteVectorisedPacket(buffers []*buf.Buffer, destination M.Socksaddr) error {
|
||||
_header := buf.StackNewSize(3 + M.SocksaddrSerializer.AddrPortLen(destination))
|
||||
defer common.KeepAlive(_header)
|
||||
header := common.Dup(_header)
|
||||
header := buf.NewSize(3 + M.SocksaddrSerializer.AddrPortLen(destination))
|
||||
defer header.Release()
|
||||
common.Must(header.WriteZeroN(3))
|
||||
common.Must(M.SocksaddrSerializer.WriteAddrPort(header, destination))
|
||||
|
|
|
@ -85,9 +85,7 @@ func WriteRequest(writer io.Writer, request Request) error {
|
|||
requestLen += len(request.Username)
|
||||
}
|
||||
|
||||
_buffer := buf.StackNewSize(requestLen)
|
||||
defer common.KeepAlive(_buffer)
|
||||
buffer := common.Dup(_buffer)
|
||||
buffer := buf.NewSize(requestLen)
|
||||
defer buffer.Release()
|
||||
|
||||
common.Must(
|
||||
|
@ -145,9 +143,7 @@ func ReadResponse(reader io.Reader) (response Response, err error) {
|
|||
}
|
||||
|
||||
func WriteResponse(writer io.Writer, response Response) error {
|
||||
_buffer := buf.StackNewSize(8)
|
||||
defer common.KeepAlive(_buffer)
|
||||
buffer := common.Dup(_buffer)
|
||||
buffer := buf.NewSize(8)
|
||||
defer buffer.Release()
|
||||
common.Must(
|
||||
buffer.WriteByte(0),
|
||||
|
|
|
@ -48,9 +48,7 @@ type AuthRequest struct {
|
|||
}
|
||||
|
||||
func WriteAuthRequest(writer io.Writer, request AuthRequest) error {
|
||||
_buffer := buf.StackNewSize(len(request.Methods) + 2)
|
||||
defer common.KeepAlive(_buffer)
|
||||
buffer := common.Dup(_buffer)
|
||||
buffer := buf.NewSize(len(request.Methods) + 2)
|
||||
defer buffer.Release()
|
||||
common.Must(
|
||||
buffer.WriteByte(Version),
|
||||
|
@ -120,9 +118,7 @@ type UsernamePasswordAuthRequest struct {
|
|||
}
|
||||
|
||||
func WriteUsernamePasswordAuthRequest(writer io.Writer, request UsernamePasswordAuthRequest) error {
|
||||
_buffer := buf.StackNewSize(3 + len(request.Username) + len(request.Password))
|
||||
defer common.KeepAlive(_buffer)
|
||||
buffer := common.Dup(_buffer)
|
||||
buffer := buf.NewSize(3 + len(request.Username) + len(request.Password))
|
||||
defer buffer.Release()
|
||||
common.Must(
|
||||
buffer.WriteByte(1),
|
||||
|
@ -191,9 +187,7 @@ type Request struct {
|
|||
}
|
||||
|
||||
func WriteRequest(writer io.Writer, request Request) error {
|
||||
_buffer := buf.StackNewSize(3 + M.SocksaddrSerializer.AddrPortLen(request.Destination))
|
||||
defer common.KeepAlive(_buffer)
|
||||
buffer := common.Dup(_buffer)
|
||||
buffer := buf.NewSize(3 + M.SocksaddrSerializer.AddrPortLen(request.Destination))
|
||||
defer buffer.Release()
|
||||
common.Must(
|
||||
buffer.WriteByte(Version),
|
||||
|
@ -244,9 +238,7 @@ func WriteResponse(writer io.Writer, response Response) error {
|
|||
bind.Addr = netip.IPv4Unspecified()
|
||||
}
|
||||
|
||||
_buffer := buf.StackNewSize(3 + M.SocksaddrSerializer.AddrPortLen(bind))
|
||||
defer common.KeepAlive(_buffer)
|
||||
buffer := common.Dup(_buffer)
|
||||
buffer := buf.NewSize(3 + M.SocksaddrSerializer.AddrPortLen(bind))
|
||||
defer buffer.Release()
|
||||
common.Must(
|
||||
buffer.WriteByte(Version),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue