Skip to content

Commit

Permalink
feat:websocket add sync.Mutex lock
Browse files Browse the repository at this point in the history
  • Loading branch information
geebytes committed Jun 1, 2024
1 parent e5da9b1 commit 1c000e8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion gateway/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"io"
"net/http"
"sync"

"github.com/gorilla/websocket"
)
Expand All @@ -21,6 +22,7 @@ type websocketForwarder struct {
http.ResponseWriter
websocket *websocket.Conn
responseType int
mux sync.Mutex
}

func NewWebsocketForwarder(w http.ResponseWriter, req *http.Request, responseType int) (WebsocketForwarder, error) {
Expand All @@ -32,12 +34,14 @@ func NewWebsocketForwarder(w http.ResponseWriter, req *http.Request, responseTyp
if err != nil {
return nil, err
}
return &websocketForwarder{w, conn, responseType}, nil
return &websocketForwarder{w, conn, responseType,sync.Mutex{}}, nil
}
func (w *websocketForwarder) Flush() {
}
func (w *websocketForwarder) Close() error {
// w.websocket.NextWriter()
w.mux.Lock()
defer w.mux.Unlock()
return w.websocket.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""))
}
func (w *websocketForwarder) CloseConn() error {
Expand Down

0 comments on commit 1c000e8

Please sign in to comment.