Skip to content

Commit

Permalink
Do not overly protect writes
Browse files Browse the repository at this point in the history
Follow-up to #161

cc @fadams
  • Loading branch information
lukebakken committed Jan 31, 2023
1 parent 2d6096a commit d30def6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
2 changes: 0 additions & 2 deletions channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,6 @@ func (ch *Channel) sendOpen(msg message) (err error) {
return ch.sendClosed(msg)
}

ch.connection.startSendUnflushed()

// Flush the buffer only after all the Frames that comprise the Message
// have been written to maximise benefits of using a buffered writer.
defer func() {
Expand Down
9 changes: 3 additions & 6 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,15 +448,10 @@ func (c *Connection) send(f frame) error {
return err
}

// This method is intended to be used with sendUnflushed() to start a sequence
// of sendUnflushed() calls
func (c *Connection) startSendUnflushed() {
c.sendM.Lock()
}

// This method is intended to be used with sendUnflushed() to end a sequence
// of sendUnflushed() calls and flush the connection
func (c *Connection) endSendUnflushed() error {
c.sendM.Lock()
defer c.sendM.Unlock()
return c.flush()
}
Expand All @@ -481,7 +476,9 @@ func (c *Connection) sendUnflushed(f frame) error {
return ErrClosed
}

c.sendM.Lock()
err := c.writer.WriteFrameNoFlush(f)
c.sendM.Unlock()

if err != nil {
// shutdown could be re-entrant from signaling notify chans
Expand Down

0 comments on commit d30def6

Please sign in to comment.