mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-22 08:31:30 +00:00
Fix v2ray websocket transport
This commit is contained in:
parent
d17e93384b
commit
9dcd427743
|
@ -7,6 +7,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
C "github.com/sagernet/sing-box/constant"
|
C "github.com/sagernet/sing-box/constant"
|
||||||
|
@ -93,6 +94,7 @@ type EarlyWebsocketConn struct {
|
||||||
*Client
|
*Client
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
conn *WebsocketConn
|
conn *WebsocketConn
|
||||||
|
access sync.Mutex
|
||||||
create chan struct{}
|
create chan struct{}
|
||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
@ -146,6 +148,11 @@ func (c *EarlyWebsocketConn) writeRequest(content []byte) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *EarlyWebsocketConn) Write(b []byte) (n int, err error) {
|
func (c *EarlyWebsocketConn) Write(b []byte) (n int, err error) {
|
||||||
|
if c.conn != nil {
|
||||||
|
return c.conn.Write(b)
|
||||||
|
}
|
||||||
|
c.access.Lock()
|
||||||
|
defer c.access.Unlock()
|
||||||
if c.conn != nil {
|
if c.conn != nil {
|
||||||
return c.conn.Write(b)
|
return c.conn.Write(b)
|
||||||
}
|
}
|
||||||
|
@ -159,6 +166,11 @@ func (c *EarlyWebsocketConn) Write(b []byte) (n int, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *EarlyWebsocketConn) WriteBuffer(buffer *buf.Buffer) error {
|
func (c *EarlyWebsocketConn) WriteBuffer(buffer *buf.Buffer) error {
|
||||||
|
if c.conn != nil {
|
||||||
|
return c.conn.WriteBuffer(buffer)
|
||||||
|
}
|
||||||
|
c.access.Lock()
|
||||||
|
defer c.access.Unlock()
|
||||||
if c.conn != nil {
|
if c.conn != nil {
|
||||||
return c.conn.WriteBuffer(buffer)
|
return c.conn.WriteBuffer(buffer)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue