From 2b9be052a4246864dc2a34371fde907f12f6e216 Mon Sep 17 00:00:00 2001 From: mohanson Date: Wed, 2 Oct 2024 21:22:40 +0800 Subject: [PATCH] No longer request a 2-byte buffer in advance for udp conn --- protocol/ashe/engine.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/protocol/ashe/engine.go b/protocol/ashe/engine.go index cb45b55..35eff02 100644 --- a/protocol/ashe/engine.go +++ b/protocol/ashe/engine.go @@ -66,12 +66,11 @@ func NewTCPConn(c io.ReadWriteCloser) *TCPConn { // UDPConn is an implementation of the Conn interface for udp network connections. type UDPConn struct { io.ReadWriteCloser - b []byte } // NewUDPConn returns a new UDPConn. func NewUDPConn(c io.ReadWriteCloser) *UDPConn { - return &UDPConn{ReadWriteCloser: c, b: make([]byte, 2)} + return &UDPConn{ReadWriteCloser: c} } // Read reads up to len(p) bytes into p. @@ -89,8 +88,9 @@ func (c *UDPConn) Write(p []byte) (int, error) { // Maximum udp payload size is 65527(equal to 65535 - 8) bytes in theoretically. The 8 in the formula means the udp // header, which contains source port, destination port, length and checksum. doa.Doa(len(p) <= 65527) - binary.BigEndian.PutUint16(c.b, uint16(len(p))) - _, err := c.ReadWriteCloser.Write(c.b[:2]) + b := make([]byte, 2) + binary.BigEndian.PutUint16(b, uint16(len(p))) + _, err := c.ReadWriteCloser.Write(b) if err != nil { return 0, err }