Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Tune growBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
bzEq committed Feb 29, 2024
1 parent 1d088b6 commit e36c98d
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions core/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,21 @@ func (self *RawNetPort) Pack(b *iovec.IoVec) error {
}

func (self *RawNetPort) growBuffer() {
const BUFFER_LIMIT = 1 << 20
l := len(self.buf)
// Ensure we have sufficient buffer for UDP transfer.
if l < DEFAULT_UDP_BUFFER_SIZE {
l = DEFAULT_UDP_BUFFER_SIZE * 2
}
if l < self.nr {
l = self.nr * 2
}
if l < DEFAULT_UDP_BUFFER_SIZE {
if l > DEFAULT_BUFFER_SIZE {
l = DEFAULT_BUFFER_SIZE
}
if l > BUFFER_LIMIT {
l = BUFFER_LIMIT
}
if l > len(self.buf) {
self.buf = make([]byte, l)
if l <= len(self.buf) {
return
}
self.buf = make([]byte, l)
}

func (self *RawNetPort) Unpack(b *iovec.IoVec) error {
Expand Down

0 comments on commit e36c98d

Please sign in to comment.