mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-21 18:22:37 +02:00
Protect ws writing in Gorilla ws
This commit is contained in:
parent
1e115e3893
commit
ed8def4d9b
@ -3,6 +3,7 @@ package ws
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
@ -10,11 +11,12 @@ import (
|
|||||||
|
|
||||||
type Conn struct {
|
type Conn struct {
|
||||||
*websocket.Conn
|
*websocket.Conn
|
||||||
|
mu sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConn(wsConn *websocket.Conn) net.Conn {
|
func NewConn(wsConn *websocket.Conn) net.Conn {
|
||||||
return &Conn{
|
return &Conn{
|
||||||
wsConn,
|
Conn: wsConn,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +34,9 @@ func (c *Conn) Read(b []byte) (n int, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conn) Write(b []byte) (int, error) {
|
func (c *Conn) Write(b []byte) (int, error) {
|
||||||
|
c.mu.Lock()
|
||||||
err := c.WriteMessage(websocket.BinaryMessage, b)
|
err := c.WriteMessage(websocket.BinaryMessage, b)
|
||||||
|
c.mu.Unlock()
|
||||||
return len(b), err
|
return len(b), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user