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 (
|
||||
"fmt"
|
||||
"net"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
@ -10,11 +11,12 @@ import (
|
||||
|
||||
type Conn struct {
|
||||
*websocket.Conn
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
func NewConn(wsConn *websocket.Conn) net.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) {
|
||||
c.mu.Lock()
|
||||
err := c.WriteMessage(websocket.BinaryMessage, b)
|
||||
c.mu.Unlock()
|
||||
return len(b), err
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user