Fix: vmess websocket udp crash
This commit is contained in:
parent
93e0dbdc78
commit
ad53b42a68
1 changed files with 9 additions and 0 deletions
|
@ -8,6 +8,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
|
@ -17,6 +18,10 @@ type websocketConn struct {
|
||||||
conn *websocket.Conn
|
conn *websocket.Conn
|
||||||
reader io.Reader
|
reader io.Reader
|
||||||
remoteAddr net.Addr
|
remoteAddr net.Addr
|
||||||
|
|
||||||
|
// https://godoc.org/github.com/gorilla/websocket#hdr-Concurrency
|
||||||
|
rMux sync.Mutex
|
||||||
|
wMux sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
type WebsocketConfig struct {
|
type WebsocketConfig struct {
|
||||||
|
@ -29,6 +34,8 @@ type WebsocketConfig struct {
|
||||||
|
|
||||||
// Read implements net.Conn.Read()
|
// Read implements net.Conn.Read()
|
||||||
func (wsc *websocketConn) Read(b []byte) (int, error) {
|
func (wsc *websocketConn) Read(b []byte) (int, error) {
|
||||||
|
wsc.rMux.Lock()
|
||||||
|
defer wsc.rMux.Unlock()
|
||||||
for {
|
for {
|
||||||
reader, err := wsc.getReader()
|
reader, err := wsc.getReader()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -46,6 +53,8 @@ func (wsc *websocketConn) Read(b []byte) (int, error) {
|
||||||
|
|
||||||
// Write implements io.Writer.
|
// Write implements io.Writer.
|
||||||
func (wsc *websocketConn) Write(b []byte) (int, error) {
|
func (wsc *websocketConn) Write(b []byte) (int, error) {
|
||||||
|
wsc.wMux.Lock()
|
||||||
|
defer wsc.wMux.Unlock()
|
||||||
if err := wsc.conn.WriteMessage(websocket.BinaryMessage, b); err != nil {
|
if err := wsc.conn.WriteMessage(websocket.BinaryMessage, b); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue