From 551c1437e533a5f6a470112f3b901163c7c2d0dd Mon Sep 17 00:00:00 2001 From: esrrhs Date: Sun, 27 Oct 2019 19:20:35 +0800 Subject: [PATCH] add --- cmd/main.go | 4 ++-- framemgr.go | 7 ++++--- pingtunnel_test.go | 6 ++++++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 4275d6e..453f489 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -48,8 +48,8 @@ Usage: -tcp_rst tcp的超时发送时间,默认400ms Tcp timeout resend time, default 400ms - -tcp_gz tcp数据开启压缩,默认0 - Whether the tcp data is compressed or not, the default is 0. + -tcp_gz 当数据包超过这个大小,tcp将压缩数据,0表示不压缩,默认0 + Tcp will compress data when the packet exceeds this size, 0 means no compression, default 0 ` func main() { diff --git a/framemgr.go b/framemgr.go index dfc9651..91b475c 100644 --- a/framemgr.go +++ b/framemgr.go @@ -98,7 +98,7 @@ func (fm *FrameMgr) cutSendBufferToWindow() { Data: make([]byte, FRAME_MAX_SIZE)} fm.sendb.Read(fd.Data) - if fm.compress > 0 { + if fm.compress > 0 && len(fd.Data) > fm.compress { newb := fm.compressData(fd.Data) if len(newb) < len(fd.Data) { fd.Data = newb @@ -124,7 +124,7 @@ func (fm *FrameMgr) cutSendBufferToWindow() { Data: make([]byte, fm.sendb.Size())} fm.sendb.Read(fd.Data) - if fm.compress > 0 { + if fm.compress > 0 && len(fd.Data) > fm.compress { newb := fm.compressData(fd.Data) if len(newb) < len(fd.Data) { 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) { fm.processPong(f) } else { - loggo.Error("error frame type %s", f.Type) + loggo.Error("error frame type %d", f.Type) } } fm.recvlist.Init() @@ -552,6 +552,7 @@ func (fm *FrameMgr) compressData(src []byte) []byte { var b bytes.Buffer w := zlib.NewWriter(&b) w.Write(src) + w.Close() return b.Bytes() } diff --git a/pingtunnel_test.go b/pingtunnel_test.go index c5ce26b..b6d03b9 100644 --- a/pingtunnel_test.go +++ b/pingtunnel_test.go @@ -95,4 +95,10 @@ func Test0001(t *testing.T) { fm.recvid = 13 fm.windowsize = 10000 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)) }