mirror of https://github.com/v2ray/v2ray-core
remove lock in websocket connection
parent
cc58f5cb8f
commit
2ba59428c9
|
@ -3,7 +3,6 @@ package websocket
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
|
@ -13,14 +12,9 @@ import (
|
||||||
type wsconn struct {
|
type wsconn struct {
|
||||||
wsc *websocket.Conn
|
wsc *websocket.Conn
|
||||||
reader io.Reader
|
reader io.Reader
|
||||||
rlock sync.Mutex
|
|
||||||
wlock sync.Mutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *wsconn) Read(b []byte) (int, error) {
|
func (c *wsconn) Read(b []byte) (int, error) {
|
||||||
c.rlock.Lock()
|
|
||||||
defer c.rlock.Unlock()
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
reader, err := c.getReader()
|
reader, err := c.getReader()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -50,9 +44,6 @@ func (c *wsconn) getReader() (io.Reader, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *wsconn) Write(b []byte) (int, error) {
|
func (c *wsconn) Write(b []byte) (int, error) {
|
||||||
c.wlock.Lock()
|
|
||||||
defer c.wlock.Unlock()
|
|
||||||
|
|
||||||
if err := c.wsc.WriteMessage(websocket.BinaryMessage, b); err != nil {
|
if err := c.wsc.WriteMessage(websocket.BinaryMessage, b); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue