mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-22 08:31:30 +00:00
Fix TFO async write
This commit is contained in:
parent
b1f289bce5
commit
fe8d46cce5
|
@ -7,6 +7,7 @@ import (
|
|||
"io"
|
||||
"net"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/sagernet/sing/common"
|
||||
|
@ -24,6 +25,7 @@ type slowOpenConn struct {
|
|||
destination M.Socksaddr
|
||||
conn net.Conn
|
||||
create chan struct{}
|
||||
access sync.Mutex
|
||||
err error
|
||||
}
|
||||
|
||||
|
@ -60,7 +62,19 @@ func (c *slowOpenConn) Read(b []byte) (n int, err error) {
|
|||
}
|
||||
|
||||
func (c *slowOpenConn) Write(b []byte) (n int, err error) {
|
||||
if c.conn == nil {
|
||||
if c.conn != nil {
|
||||
return c.conn.Write(b)
|
||||
}
|
||||
c.access.Lock()
|
||||
defer c.access.Unlock()
|
||||
select {
|
||||
case <-c.create:
|
||||
if c.err != nil {
|
||||
return 0, c.err
|
||||
}
|
||||
return c.conn.Write(b)
|
||||
default:
|
||||
}
|
||||
c.conn, err = c.dialer.DialContext(c.ctx, c.network, c.destination.String(), b)
|
||||
if err != nil {
|
||||
c.conn = nil
|
||||
|
@ -68,8 +82,6 @@ func (c *slowOpenConn) Write(b []byte) (n int, err error) {
|
|||
}
|
||||
close(c.create)
|
||||
return
|
||||
}
|
||||
return c.conn.Write(b)
|
||||
}
|
||||
|
||||
func (c *slowOpenConn) Close() error {
|
||||
|
|
Loading…
Reference in a new issue