修订代码

This commit is contained in:
hahahrfool
2022-03-30 21:32:35 +08:00
parent 3fa75b181f
commit 4ece4b84dd
8 changed files with 51 additions and 13 deletions

View File

@@ -7,7 +7,7 @@ const (
Log_debug = iota
Log_info
Log_warning
Log_error
Log_error //error一般用于输出一些 连接错误或者客户端协议错误之类的, 但不致命
Log_fatal
//Log_off //不支持不打印致命输出。既然致命我们一定要尸检然后查看病因啊

View File

@@ -2,6 +2,7 @@ package utils
import (
"bytes"
"flag"
"sync"
)
@@ -24,9 +25,13 @@ const StandardBytesLength int = 1500
// https://en.wikipedia.org/wiki/Maximum_transmission_unit
//本作设定的最大buf大小64k
const MaxBufLen = 64 * 1024
var MaxBufLen = DefaultMaxBufLen
const DefaultMaxBufLen = 64 * 1024
func init() {
flag.IntVar(&MaxBufLen, "bl", DefaultMaxBufLen, "buf len")
standardBytesPool = sync.Pool{
New: func() interface{} {
return make([]byte, StandardBytesLength)
@@ -46,6 +51,15 @@ func init() {
}
}
//给了参数调节buf大小后,需要更新pool
func AdjustBufSize() {
standardPacketPool = sync.Pool{
New: func() interface{} {
return make([]byte, MaxBufLen)
},
}
}
//从Pool中获取一个 *bytes.Buffer
func GetBuf() *bytes.Buffer {
return bufPool.Get().(*bytes.Buffer)