Skip to content

Commit

Permalink
recycle xmitBuf uniformly
Browse files Browse the repository at this point in the history
  • Loading branch information
xtaci committed Nov 4, 2019
1 parent 6e70521 commit 9f0f2bc
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
4 changes: 4 additions & 0 deletions sess.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ func (s *UDPSession) WriteBuffers(v [][]byte) (n int, err error) {
func (s *UDPSession) uncork() {
if len(s.txqueue) > 0 {
s.tx(s.txqueue)
// recycle
for k := range s.txqueue {
xmitBuf.Put(s.txqueue[k].Buffers[0])
}
s.txqueue = nil
}
return
Expand Down
1 change: 0 additions & 1 deletion tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ func (s *UDPSession) defaultTx(txqueue []ipv4.Message) {
if n, err := s.conn.WriteTo(txqueue[k].Buffers[0], txqueue[k].Addr); err == nil {
nbytes += n
npkts++
xmitBuf.Put(txqueue[k].Buffers[0])
} else {
s.notifyWriteError(errors.WithStack(err))
break
Expand Down
1 change: 0 additions & 1 deletion tx_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func (s *UDPSession) tx(txqueue []ipv4.Message) {
if n, err := s.xconn.WriteBatch(txqueue, 0); err == nil {
for k := range txqueue[:n] {
nbytes += len(txqueue[k].Buffers[0])
xmitBuf.Put(txqueue[k].Buffers[0])
}
npkts += n
txqueue = txqueue[n:]
Expand Down

0 comments on commit 9f0f2bc

Please sign in to comment.