From 1ab9040b4ca3f734feef2c4e01857444a461b148 Mon Sep 17 00:00:00 2001 From: alber Date: Wed, 30 Sep 2020 17:02:04 +0800 Subject: [PATCH] commit --- go.mod | 2 +- go.sum | 4 ++-- internal/tcp_conn/handler.go | 4 ++-- internal/tcp_conn/tcp_server.go | 4 +++- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 326bff1b..c32fb5a0 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module gim go 1.12 require ( - github.com/alberliu/gn v1.1.0 + github.com/alberliu/gn v1.2.0 github.com/denisenkom/go-mssqldb v0.0.0-20200620013148-b91950f658ec // indirect github.com/go-redis/redis v6.14.2+incompatible github.com/go-sql-driver/mysql v1.5.0 diff --git a/go.sum b/go.sum index 982dd383..b8812deb 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc= -github.com/alberliu/gn v1.1.0 h1:rWmm7huvPP0NhuhaiMyK4YWmsoSDA5RcrA7jiAjFHns= -github.com/alberliu/gn v1.1.0/go.mod h1:EAZ/QNlcImJ4AkBwTgqUb73zW2ZuF7FxKIdEbjKLedE= +github.com/alberliu/gn v1.2.0 h1:hwwtVL6BNekdcxzr0EqJkrv38fXvO7rKugC9QpNUP/A= +github.com/alberliu/gn v1.2.0/go.mod h1:EAZ/QNlcImJ4AkBwTgqUb73zW2ZuF7FxKIdEbjKLedE= github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= diff --git a/internal/tcp_conn/handler.go b/internal/tcp_conn/handler.go index dd35cda3..b5555b9b 100644 --- a/internal/tcp_conn/handler.go +++ b/internal/tcp_conn/handler.go @@ -24,7 +24,7 @@ type handler struct{} var Handler = new(handler) func (*handler) OnConnect(c *gn.Conn) { - logger.Logger.Debug("connect:", zap.Int("fd", c.GetFd()), zap.String("addr", c.GetAddr())) + logger.Logger.Debug("connect:", zap.Int32("fd", c.GetFd()), zap.String("addr", c.GetAddr())) } func (h *handler) OnMessage(c *gn.Conn, bytes []byte) { var input pb.Input @@ -91,7 +91,7 @@ func (h *handler) Send(c *gn.Conn, pt pb.PackageType, requestId int64, err error return } - err = gn.EncodeToFD(c.GetFd(), outputBytes) + err = encoder.EncodeToFD(c.GetFd(), outputBytes) if err != nil { logger.Sugar.Error(err) return diff --git a/internal/tcp_conn/tcp_server.go b/internal/tcp_conn/tcp_server.go index ca935e5f..3eeb7516 100644 --- a/internal/tcp_conn/tcp_server.go +++ b/internal/tcp_conn/tcp_server.go @@ -8,11 +8,13 @@ import ( "github.com/alberliu/gn" ) +var encoder = gn.NewHeaderLenEncoder(2, 1024) + var server *gn.Server func StartTCPServer() { var err error - server, err = gn.NewServer(config.TCPConn.TCPListenAddr, &handler{}, gn.WithReadMaxLen(254), gn.WithTimeout(5*time.Minute, 11*time.Minute)) + server, err = gn.NewServer(config.TCPConn.TCPListenAddr, &handler{}, gn.NewHeaderLenDecoder(2, 254), gn.WithTimeout(5*time.Minute, 11*time.Minute)) if err != nil { logger.Sugar.Error(err) panic(err)