From 20761d2183c978cdfd2c73b64b1f0b5f1be01a93 Mon Sep 17 00:00:00 2001 From: "arraykeys@gmail.com" Date: Fri, 21 Sep 2018 12:01:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dencrypt.Conn=E9=87=8A?= =?UTF-8?q?=E6=94=BE=E5=86=85=E5=AD=98,=E5=AF=BC=E8=87=B4=E7=9A=84?= =?UTF-8?q?=E6=BD=9C=E5=9C=A8panic=E9=97=AE=E9=A2=98.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/lib/transport/encrypt/conn.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/core/lib/transport/encrypt/conn.go b/core/lib/transport/encrypt/conn.go index 9080da2..a9ed308 100644 --- a/core/lib/transport/encrypt/conn.go +++ b/core/lib/transport/encrypt/conn.go @@ -2,6 +2,7 @@ package encrypt import ( "crypto/cipher" + "fmt" "io" "net" @@ -33,15 +34,23 @@ func NewConn(c net.Conn, method, password string) (conn net.Conn, err error) { return } func (s *Conn) Read(b []byte) (n int, err error) { + if s.r == nil { + return 0, fmt.Errorf("use of closed connection") + } return s.r.Read(b) } func (s *Conn) Write(b []byte) (n int, err error) { + if s.w == nil { + return 0, fmt.Errorf("use of closed connection") + } return s.w.Write(b) } func (s *Conn) Close() (err error) { - err = s.Conn.Close() - s.Cipher = nil - s.r = nil - s.w = nil - return err + if s.Cipher != nil { + err = s.Conn.Close() + s.Cipher = nil + s.r = nil + s.w = nil + } + return }