Skip to content

Commit

Permalink
perf(tunnel): replace io.CopyBuffer with bufio.Copy
Browse files Browse the repository at this point in the history
  • Loading branch information
igoogolx committed Jan 23, 2025
1 parent d0ae6ba commit adb2729
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions internal/tunnel/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import (
"github.com/igoogolx/itun2socks/internal/tunnel/statistic"
"github.com/igoogolx/itun2socks/pkg/log"
"github.com/igoogolx/itun2socks/pkg/network_iface"
"github.com/igoogolx/itun2socks/pkg/pool"
"io"
"github.com/sagernet/sing/common/bufio"
"net"
"sync"
"time"
Expand Down Expand Up @@ -57,8 +56,6 @@ func handleTCPConn(ct conn.TcpConnContext) {
}

func copyPacket(lc net.Conn, rc net.Conn) error {
buf := pool.NewBytes(pool.BufSize)
defer pool.FreeBytes(buf)
err := lc.SetDeadline(time.Now().Add(tcpTimeout))
if err != nil {
return err
Expand All @@ -67,7 +64,7 @@ func copyPacket(lc net.Conn, rc net.Conn) error {
if err != nil {
return err
}
_, err = io.CopyBuffer(lc, rc, buf)
_, err = bufio.Copy(lc, rc)
return err
}

Expand Down

0 comments on commit adb2729

Please sign in to comment.