Skip to content

Commit

Permalink
websocket: simplify sendQueue free logic
Browse files Browse the repository at this point in the history
  • Loading branch information
lesismal committed Sep 17, 2024
1 parent d2b0199 commit c5367d9
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions nbhttp/websocket/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -787,21 +787,19 @@ func (c *Conn) writeFrame(messageType MessageType, sendOpcode, fin bool, data []
}
c.sendQueue = append(c.sendQueue, buf)
isHead := (len(c.sendQueue) == 1)
if isHead {
c.sendQueue[0] = nil
}

if isHead {
c.sendQueue[0] = nil
go func() {
i := 0
for {
_, err := c.Conn.Write(buf)
c.Engine.BodyAllocator.Free(buf)
if err != nil {
c.CloseWithError(err)
return
}
c.Engine.BodyAllocator.Free(buf)
c.sendQueue[i] = nil

i++

c.mux.Lock()
Expand All @@ -816,6 +814,7 @@ func (c *Conn) writeFrame(messageType MessageType, sendOpcode, fin bool, data []
}

buf = c.sendQueue[i]
c.sendQueue[i] = nil

c.mux.Unlock()

Expand Down

0 comments on commit c5367d9

Please sign in to comment.