You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/10/26 04:20:55 UTC

[dubbo-getty] 01/01: Imp: using gxbytes.Buffer WriteNextBegin/WriteNextEnd

This is an automated email from the ASF dual-hosted git repository.

alexstocks pushed a commit to branch feature/gxbytes-buffer
in repository https://gitbox.apache.org/repos/asf/dubbo-getty.git

commit 409eb86812fe58660597cc06beb2bdbcb4a3472b
Author: AlexStocks <al...@foxmail.com>
AuthorDate: Tue Oct 26 12:21:31 2021 +0800

    Imp: using gxbytes.Buffer WriteNextBegin/WriteNextEnd
---
 go.mod     |  2 +-
 go.sum     |  4 ++--
 session.go | 12 ++++--------
 3 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/go.mod b/go.mod
index 8b24c74..3ef84d7 100644
--- a/go.mod
+++ b/go.mod
@@ -3,7 +3,7 @@ module github.com/apache/dubbo-getty
 go 1.14
 
 require (
-	github.com/dubbogo/gost v1.11.12
+	github.com/dubbogo/gost v1.11.19
 	github.com/golang/snappy v0.0.1
 	github.com/gorilla/websocket v1.4.2
 	github.com/montanaflynn/stats v0.6.6
diff --git a/go.sum b/go.sum
index e8ed596..781324d 100644
--- a/go.sum
+++ b/go.sum
@@ -79,8 +79,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
 github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
 github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
 github.com/dubbogo/go-zookeeper v1.0.3/go.mod h1:fn6n2CAEer3novYgk9ULLwAjuV8/g4DdC2ENwRb6E+c=
-github.com/dubbogo/gost v1.11.12 h1:e3861DxHWe509whpMxS6mFBmgmm7r9+bT5iJ/PRufcw=
-github.com/dubbogo/gost v1.11.12/go.mod h1:vIcP9rqz2KsXHPjsAwIUtfJIJjppQLQDcYaZTy/61jI=
+github.com/dubbogo/gost v1.11.19 h1:R1rZ3TNJKV9W5XHLMv+GDO2Wy6UDnwGQtVWbsWYvo0A=
+github.com/dubbogo/gost v1.11.19/go.mod h1:vIcP9rqz2KsXHPjsAwIUtfJIJjppQLQDcYaZTy/61jI=
 github.com/dubbogo/jsonparser v1.0.1/go.mod h1:tYAtpctvSP/tWw4MeelsowSPgXQRVHHWbqL6ynps8jU=
 github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
 github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
diff --git a/session.go b/session.go
index 58e4266..79775f1 100644
--- a/session.go
+++ b/session.go
@@ -597,17 +597,12 @@ func (s *session) handleTCPPackage() error {
 		exit     bool
 		bufLen   int
 		pkgLen   int
-		bufp     *[]byte
 		buf      []byte
-		pktBuf   *bytes.Buffer
+		pktBuf   *gxbytes.Buffer
 		pkg      interface{}
 	)
 
-	// buf = make([]byte, maxReadBufLen)
-	bufp = gxbytes.GetBytes(maxReadBufLen)
-	buf = *bufp
-
-	pktBuf = new(bytes.Buffer)
+	pktBuf = gxbytes.NewBuffer(nil)
 
 	conn = s.Connection.(*gettyTCPConn)
 	for {
@@ -622,6 +617,7 @@ func (s *session) handleTCPPackage() error {
 		for {
 			// for clause for the network timeout condition check
 			// s.conn.SetReadTimeout(time.Now().Add(s.rTimeout))
+			buf = pktBuf.WriteNextBegin(maxReadBufLen)
 			bufLen, err = conn.recv(buf)
 			if err != nil {
 				if netError, ok = perrors.Cause(err).(net.Error); ok && netError.Timeout() {
@@ -646,7 +642,7 @@ func (s *session) handleTCPPackage() error {
 			break
 		}
 		if 0 != bufLen {
-			pktBuf.Write(buf[:bufLen])
+			pktBuf.WriteNextEnd(bufLen)
 			for {
 				if pktBuf.Len() <= 0 {
 					break