Skip to content

Commit

Permalink
reduce conn lock time
Browse files Browse the repository at this point in the history
  • Loading branch information
robbiev committed Aug 15, 2016
1 parent ea9ce30 commit e0103be
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,9 @@ func (c *WebSocketTextClient) Close() error {
// WriteTextMessage writes a text message to the WebSocket
func (c *WebSocketTextClient) WriteTextMessage(msg []byte) error {
c.connMutex.RLock()
defer c.connMutex.RUnlock()
if err := c.conn.WriteMessage(websocket.TextMessage, msg); err != nil {
conn := c.conn
c.connMutex.RUnlock()
if err := conn.WriteMessage(websocket.TextMessage, msg); err != nil {
c.tryReconnect()
return err
}
Expand Down Expand Up @@ -284,8 +285,9 @@ func (c *WebSocketTextClient) readLoop() {
return
default:
c.connMutex.RLock()
msgType, msg, err := c.conn.ReadMessage()
conn := c.conn
c.connMutex.RUnlock()
msgType, msg, err := conn.ReadMessage()
if err != nil {
go c.OnError(err)
c.tryReconnect()
Expand Down

0 comments on commit e0103be

Please sign in to comment.