fine bandwidth calculation, fix slide window calculated size too large, fix #330

This commit is contained in:
ffdfgdfg
2019-12-27 00:32:40 +08:00
parent 258be8e67a
commit 076fc8b2e1
4 changed files with 70 additions and 10 deletions

View File

@@ -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

View File

@@ -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)
}