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 2022/01/15 10:33:10 UTC
[dubbo-getty] branch master updated: Fix: fix connection was assigned a nil will lead to panic
This is an automated email from the ASF dual-hosted git repository.
alexstocks pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-getty.git
The following commit(s) were added to refs/heads/master by this push:
new 431c47e Fix: fix connection was assigned a nil will lead to panic
new 0b14a0d Merge pull request #92 from takewofly/feat/connect_session
431c47e is described below
commit 431c47e8a3b5779800b6c6f0332a973c9b23b330
Author: jason <lv...@gmail.com>
AuthorDate: Tue Jan 11 22:52:37 2022 +0800
Fix: fix connection was assigned a nil will lead to panic
---
session.go | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 119 insertions(+), 8 deletions(-)
diff --git a/session.go b/session.go
index be225c2..5bfa4da 100644
--- a/session.go
+++ b/session.go
@@ -73,7 +73,6 @@ type Session interface {
IsClosed() bool
// EndPoint get endpoint type
EndPoint() EndPoint
-
SetMaxMsgLen(int)
SetName(string)
SetEventListener(EventListener)
@@ -81,9 +80,7 @@ type Session interface {
SetReader(Reader)
SetWriter(Writer)
SetCronPeriod(int)
-
SetWaitTime(time.Duration)
-
GetAttribute(interface{}) interface{}
SetAttribute(interface{}, interface{})
RemoveAttribute(interface{})
@@ -565,11 +562,6 @@ func (s *session) run() {
func (s *session) addTask(pkg interface{}) {
f := func() {
- s.lock.RLock()
- defer s.lock.RUnlock()
- if s.Connection == nil {
- return
- }
s.listener.OnMessage(s, pkg)
s.incReadPkgNum()
}
@@ -878,3 +870,122 @@ func (s *session) Close() {
s.stop()
log.Infof("%s closed now. its current gr num is %d", s.sessionToken(), s.grNum.Load())
}
+
+// GetActive return connection's time
+func (s *session) GetActive() time.Time {
+ if s == nil {
+ return launchTime
+ }
+ s.lock.RLock()
+ defer s.lock.RUnlock()
+ if s.Connection != nil {
+ return s.Connection.GetActive()
+ }
+ return launchTime
+}
+
+// UpdateActive update connection's active time
+func (s *session) UpdateActive() {
+ if s == nil {
+ return
+ }
+ s.lock.RLock()
+ defer s.lock.RUnlock()
+
+ if s.Connection != nil {
+ s.Connection.UpdateActive()
+ }
+}
+
+func (s *session) ID() uint32 {
+ if s == nil {
+ return 0
+ }
+ s.lock.RLock()
+ defer s.lock.RUnlock()
+ if s.Connection != nil {
+ return s.Connection.ID()
+ }
+ return 0
+}
+
+func (s *session) LocalAddr() string {
+ if s == nil {
+ return ""
+ }
+ s.lock.RLock()
+ defer s.lock.RUnlock()
+ if s.Connection != nil {
+ return s.Connection.LocalAddr()
+ }
+ return ""
+}
+
+func (s *session) RemoteAddr() string {
+ if s == nil {
+ return ""
+ }
+ s.lock.RLock()
+ defer s.lock.RUnlock()
+ if s.Connection != nil {
+ return s.Connection.RemoteAddr()
+ }
+ return ""
+}
+
+func (s *session) incReadPkgNum() {
+ if s == nil {
+ return
+ }
+ s.lock.RLock()
+ defer s.lock.RUnlock()
+ if s.Connection != nil {
+ s.Connection.incReadPkgNum()
+ }
+}
+
+func (s *session) incWritePkgNum() {
+ if s == nil {
+ return
+ }
+ s.lock.RLock()
+ defer s.lock.RUnlock()
+ if s.Connection != nil {
+ s.Connection.incWritePkgNum()
+ }
+}
+
+func (s *session) send(pkg interface{}) (int, error) {
+ if s == nil {
+ return 0, nil
+ }
+ s.lock.RLock()
+ defer s.lock.RUnlock()
+ if s.Connection != nil {
+ return s.Connection.send(pkg)
+ }
+ return 0, nil
+}
+
+func (s *session) readTimeout() time.Duration {
+ if s == nil {
+ return time.Duration(0)
+ }
+ s.lock.RLock()
+ defer s.lock.RUnlock()
+ if s.Connection != nil {
+ return s.Connection.readTimeout()
+ }
+ return time.Duration(0)
+}
+
+func (s *session) setSession(ss Session) {
+ if s == nil {
+ return
+ }
+ s.lock.RLock()
+ if s.Connection != nil {
+ s.Connection.setSession(ss)
+ }
+ s.lock.RUnlock()
+}