mirror of
https://github.com/xtaci/kcp-go.git
synced 2024-04-21 12:32:15 +00:00
recycle xmitBuf uniformly
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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:]
|
||||
|
||||
Reference in New Issue
Block a user