forked from mirror/websocket
fix flate write pool size to work with best compression
This commit is contained in:
parent
2257eda00b
commit
eb457539f7
|
@ -19,7 +19,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
flateWriterPools [maxCompressionLevel - minCompressionLevel]sync.Pool
|
flateWriterPools [maxCompressionLevel - minCompressionLevel + 1]sync.Pool
|
||||||
flateReaderPool = sync.Pool{New: func() interface{} {
|
flateReaderPool = sync.Pool{New: func() interface{} {
|
||||||
return flate.NewReader(nil)
|
return flate.NewReader(nil)
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -41,6 +41,28 @@ func textMessages(num int) [][]byte {
|
||||||
return messages
|
return messages
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCompressNoContextTakeover(t *testing.T) {
|
||||||
|
for level := minCompressionLevel; level <= maxCompressionLevel; level++ {
|
||||||
|
message := textMessages(1)[0]
|
||||||
|
c := fakeNetConn{Reader: nil, Writer: ioutil.Discard}
|
||||||
|
f := compressNoContextTakeover(c, level)
|
||||||
|
n, err := f.Write(message)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error writing using compressNoContextTakeover on level %d: %v", level, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if n != len(message) {
|
||||||
|
t.Errorf("Error writing using compressNoContextTakeover on level %d: not enough bytes written", level)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = f.Close()
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error closing writer on level %d: %v", level, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkWriteNoCompression(b *testing.B) {
|
func BenchmarkWriteNoCompression(b *testing.B) {
|
||||||
w := ioutil.Discard
|
w := ioutil.Discard
|
||||||
c := newConn(fakeNetConn{Reader: nil, Writer: w}, false, 1024, 1024)
|
c := newConn(fakeNetConn{Reader: nil, Writer: w}, false, 1024, 1024)
|
||||||
|
|
Loading…
Reference in New Issue