remove nodelay option for tunnel

This commit is contained in:
ginuerzh
2023-11-16 20:36:17 +08:00
parent 9584bdbf4c
commit f5a20fd0fc
5 changed files with 35 additions and 96 deletions

View File

@ -1,7 +1,6 @@
package tunnel
import (
"bytes"
"context"
"fmt"
"net"
@ -90,39 +89,20 @@ func (c *tunnelConnector) Connect(ctx context.Context, conn net.Conn, network, a
ID: c.md.tunnelID.ID(),
})
if c.md.noDelay {
if _, err := req.WriteTo(conn); err != nil {
return nil, err
}
// drain the response
if err := readResponse(conn); err != nil {
return nil, err
}
if _, err := req.WriteTo(conn); err != nil {
return nil, err
}
// drain the response
if err := readResponse(conn); err != nil {
return nil, err
}
switch network {
case "tcp", "tcp4", "tcp6":
if !c.md.noDelay {
cc := &tcpConn{
Conn: conn,
wbuf: &bytes.Buffer{},
}
if _, err := req.WriteTo(cc.wbuf); err != nil {
return nil, err
}
conn = cc
}
case "udp", "udp4", "udp6":
cc := &udpConn{
conn = &udpConn{
Conn: conn,
}
if !c.md.noDelay {
cc.wbuf = &bytes.Buffer{}
if _, err := req.WriteTo(cc.wbuf); err != nil {
return nil, err
}
}
conn = cc
default:
err := fmt.Errorf("network %s is unsupported", network)
log.Error(err)