This commit is contained in:
esrrhs 2019-10-27 19:20:35 +08:00
parent 013c6124d9
commit 551c1437e5
3 changed files with 12 additions and 5 deletions

View File

@ -48,8 +48,8 @@ Usage:
-tcp_rst tcp的超时发送时间默认400ms -tcp_rst tcp的超时发送时间默认400ms
Tcp timeout resend time, default 400ms Tcp timeout resend time, default 400ms
-tcp_gz tcp数据开启压缩默认0 -tcp_gz 当数据包超过这个大小tcp将压缩数据0表示不压缩默认0
Whether the tcp data is compressed or not, the default is 0. Tcp will compress data when the packet exceeds this size, 0 means no compression, default 0
` `
func main() { func main() {

View File

@ -98,7 +98,7 @@ func (fm *FrameMgr) cutSendBufferToWindow() {
Data: make([]byte, FRAME_MAX_SIZE)} Data: make([]byte, FRAME_MAX_SIZE)}
fm.sendb.Read(fd.Data) fm.sendb.Read(fd.Data)
if fm.compress > 0 { if fm.compress > 0 && len(fd.Data) > fm.compress {
newb := fm.compressData(fd.Data) newb := fm.compressData(fd.Data)
if len(newb) < len(fd.Data) { if len(newb) < len(fd.Data) {
fd.Data = newb fd.Data = newb
@ -124,7 +124,7 @@ func (fm *FrameMgr) cutSendBufferToWindow() {
Data: make([]byte, fm.sendb.Size())} Data: make([]byte, fm.sendb.Size())}
fm.sendb.Read(fd.Data) fm.sendb.Read(fd.Data)
if fm.compress > 0 { if fm.compress > 0 && len(fd.Data) > fm.compress {
newb := fm.compressData(fd.Data) newb := fm.compressData(fd.Data)
if len(newb) < len(fd.Data) { if len(newb) < len(fd.Data) {
fd.Data = newb fd.Data = newb
@ -218,7 +218,7 @@ func (fm *FrameMgr) preProcessRecvList() (map[int32]int, map[int32]int, map[int3
} else if f.Type == (int32)(Frame_PONG) { } else if f.Type == (int32)(Frame_PONG) {
fm.processPong(f) fm.processPong(f)
} else { } else {
loggo.Error("error frame type %s", f.Type) loggo.Error("error frame type %d", f.Type)
} }
} }
fm.recvlist.Init() fm.recvlist.Init()
@ -552,6 +552,7 @@ func (fm *FrameMgr) compressData(src []byte) []byte {
var b bytes.Buffer var b bytes.Buffer
w := zlib.NewWriter(&b) w := zlib.NewWriter(&b)
w.Write(src) w.Write(src)
w.Close()
return b.Bytes() return b.Bytes()
} }

View File

@ -95,4 +95,10 @@ func Test0001(t *testing.T) {
fm.recvid = 13 fm.recvid = 13
fm.windowsize = 10000 fm.windowsize = 10000
fmt.Println("fm.isIdOld = ", fm.isIdOld(9, FRAME_MAX_ID)) fmt.Println("fm.isIdOld = ", fm.isIdOld(9, FRAME_MAX_ID))
dd := fm.compressData(([]byte)("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
fmt.Println("fm.compressData = ", len(dd))
_, ddd := fm.deCompressData(dd)
fmt.Println("fm.deCompressData = ", (string)(ddd))
} }