mirror of
https://github.com/ehang-io/nps.git
synced 2025-09-02 03:16:53 +00:00
fine bandwidth calculation, fix slide window calculated size too large, fix #330
This commit is contained in:
@@ -246,6 +246,15 @@ func (Self *MuxPackager) UnPack(reader io.Reader) (n uint16, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (Self *MuxPackager) reset() {
|
||||
Self.Id = 0
|
||||
Self.Flag = 0
|
||||
Self.Length = 0
|
||||
Self.Content = nil
|
||||
Self.ReadLength = 0
|
||||
Self.Window = 0
|
||||
}
|
||||
|
||||
const (
|
||||
ipV4 = 1
|
||||
domainName = 3
|
||||
|
@@ -93,18 +93,20 @@ type windowBufferPool struct {
|
||||
func (Self *windowBufferPool) New() {
|
||||
Self.pool = sync.Pool{
|
||||
New: func() interface{} {
|
||||
return make([]byte, PoolSizeWindow, PoolSizeWindow)
|
||||
return make([]byte, PoolSizeWindow)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (Self *windowBufferPool) Get() (buf []byte) {
|
||||
buf = Self.pool.Get().([]byte)
|
||||
return buf[:PoolSizeWindow]
|
||||
buf = buf[:PoolSizeWindow]
|
||||
return buf
|
||||
}
|
||||
|
||||
func (Self *windowBufferPool) Put(x []byte) {
|
||||
Self.pool.Put(x[:PoolSizeWindow]) // make buf to full
|
||||
x = x[:0] // clean buf
|
||||
Self.pool.Put(x)
|
||||
}
|
||||
|
||||
type bufferPool struct {
|
||||
@@ -146,6 +148,7 @@ func (Self *muxPackagerPool) Get() *MuxPackager {
|
||||
}
|
||||
|
||||
func (Self *muxPackagerPool) Put(pack *MuxPackager) {
|
||||
pack.reset()
|
||||
Self.pool.Put(pack)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user