optimize: reduce UDP buffer

This commit is contained in:
mzz2017
2023-03-25 13:52:52 +08:00
parent 2ff7e1ba47
commit c0abd753eb
2 changed files with 7 additions and 3 deletions

View File

@ -649,7 +649,7 @@ func (c *ControlPlane) Serve(readyChan chan<- bool, listener *Listener) (err err
return
default:
}
var buf [65535]byte
var buf [EthernetMtu]byte
var oob [120]byte // Size for original dest
n, oobn, _, src, err := udpConn.ReadMsgUDPAddrPort(buf[:], oob[:])
if err != nil {

View File

@ -8,14 +8,18 @@ package control
import (
"errors"
"fmt"
"github.com/daeuniverse/dae/component/outbound/dialer"
"github.com/mzz2017/softwind/netproxy"
"github.com/mzz2017/softwind/pool"
"github.com/daeuniverse/dae/component/outbound/dialer"
"net/netip"
"sync"
"time"
)
const (
EthernetMtu = 1500
)
type UdpHandler func(data []byte, from netip.AddrPort) error
type UdpEndpoint struct {
@ -30,7 +34,7 @@ type UdpEndpoint struct {
}
func (ue *UdpEndpoint) start() {
buf := pool.Get(0xffff)
buf := pool.Get(EthernetMtu)
defer pool.Put(buf)
for {
n, from, err := ue.conn.ReadFrom(buf[:])