decrease copy buffer

This commit is contained in:
ginuerzh 2022-03-31 21:06:33 +08:00
parent 47cfc087e9
commit fc1e6e8ff2
4 changed files with 11 additions and 4 deletions

View File

@ -34,6 +34,15 @@ var (
}, },
}, },
}, },
{
size: 2048,
pool: sync.Pool{
New: func() any {
b := make([]byte, 2048)
return &b
},
},
},
{ {
size: 4096, size: 4096,
pool: sync.Pool{ pool: sync.Pool{

View File

@ -46,7 +46,7 @@ func (d *NetDialer) Dial(ctx context.Context, network, addr string) (net.Conn, e
if d.DialFunc != nil { if d.DialFunc != nil {
return d.DialFunc(ctx, network, addr) return d.DialFunc(ctx, network, addr)
} }
log.Infof("interface: %s %v/%s", ifceName, ifAddr, network) log.Debugf("interface: %s %v/%s", ifceName, ifAddr, network)
switch network { switch network {
case "udp", "udp4", "udp6": case "udp", "udp4", "udp6":

View File

@ -5,8 +5,6 @@ import (
) )
func bindDevice(fd uintptr, ifceName string) error { func bindDevice(fd uintptr, ifceName string) error {
// unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEADDR, 1)
// unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1)
if ifceName == "" { if ifceName == "" {
return nil return nil
} }

View File

@ -26,7 +26,7 @@ func Transport(rw1, rw2 io.ReadWriter) error {
} }
func copyBuffer(dst io.Writer, src io.Reader) error { func copyBuffer(dst io.Writer, src io.Reader) error {
buf := bufpool.Get(16 * 1024) buf := bufpool.Get(4 * 1024)
defer bufpool.Put(buf) defer bufpool.Put(buf)
_, err := io.CopyBuffer(dst, src, *buf) _, err := io.CopyBuffer(dst, src, *buf)