mirror of https://github.com/v2ray/v2ray-core
parent
9206d7a741
commit
514dcffe2e
|
@ -93,6 +93,7 @@ func (w *tcpWorker) handleConnections(conns <-chan internet.Connection) {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case conn := <-conns:
|
case conn := <-conns:
|
||||||
|
conn.SetReusable(false)
|
||||||
conn.Close()
|
conn.Close()
|
||||||
default:
|
default:
|
||||||
break L
|
break L
|
||||||
|
|
|
@ -202,6 +202,7 @@ func (v *Listener) OnReceive(payload *buf.Buffer, src v2net.Destination, origina
|
||||||
select {
|
select {
|
||||||
case v.conns <- netConn:
|
case v.conns <- netConn:
|
||||||
case <-time.After(time.Second * 5):
|
case <-time.After(time.Second * 5):
|
||||||
|
conn.SetReusable(false)
|
||||||
conn.Close()
|
conn.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,13 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"v2ray.com/core/app/log"
|
"v2ray.com/core/app/log"
|
||||||
"v2ray.com/core/common"
|
"v2ray.com/core/common"
|
||||||
"v2ray.com/core/common/errors"
|
"v2ray.com/core/common/errors"
|
||||||
v2net "v2ray.com/core/common/net"
|
v2net "v2ray.com/core/common/net"
|
||||||
|
"v2ray.com/core/common/retry"
|
||||||
"v2ray.com/core/transport/internet"
|
"v2ray.com/core/transport/internet"
|
||||||
"v2ray.com/core/transport/internet/internal"
|
"v2ray.com/core/transport/internet/internal"
|
||||||
v2tls "v2ray.com/core/transport/internet/tls"
|
v2tls "v2ray.com/core/transport/internet/tls"
|
||||||
|
@ -21,7 +21,6 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
type TCPListener struct {
|
type TCPListener struct {
|
||||||
sync.Mutex
|
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
listener *net.TCPListener
|
listener *net.TCPListener
|
||||||
tlsConfig *tls.Config
|
tlsConfig *tls.Config
|
||||||
|
@ -76,13 +75,20 @@ func (v *TCPListener) KeepAccepting() {
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
conn, err := v.listener.Accept()
|
var conn net.Conn
|
||||||
v.Lock()
|
err := retry.ExponentialBackoff(5, 200).On(func() error {
|
||||||
|
rawConn, err := v.listener.Accept()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
conn = rawConn
|
||||||
|
return nil
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warning("TCP|Listener: Failed to accepted raw connections: ", err)
|
log.Warning("TCP|Listener: Failed to accepted raw connections: ", err)
|
||||||
v.Unlock()
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.tlsConfig != nil {
|
if v.tlsConfig != nil {
|
||||||
conn = tls.Server(conn, v.tlsConfig)
|
conn = tls.Server(conn, v.tlsConfig)
|
||||||
}
|
}
|
||||||
|
@ -95,19 +101,16 @@ func (v *TCPListener) KeepAccepting() {
|
||||||
case <-time.After(time.Second * 5):
|
case <-time.After(time.Second * 5):
|
||||||
conn.Close()
|
conn.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
v.Unlock()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *TCPListener) Put(id internal.ConnectionID, conn net.Conn) {
|
func (v *TCPListener) Put(id internal.ConnectionID, conn net.Conn) {
|
||||||
select {
|
select {
|
||||||
case <-v.ctx.Done():
|
|
||||||
conn.Close()
|
|
||||||
return
|
|
||||||
case v.conns <- internal.NewConnection(internal.ConnectionID{}, conn, v, internal.ReuseConnection(v.config.IsConnectionReuse())):
|
case v.conns <- internal.NewConnection(internal.ConnectionID{}, conn, v, internal.ReuseConnection(v.config.IsConnectionReuse())):
|
||||||
case <-time.After(time.Second * 5):
|
case <-time.After(time.Second * 5):
|
||||||
conn.Close()
|
conn.Close()
|
||||||
|
case <-v.ctx.Done():
|
||||||
|
conn.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue