From d899e336c7f5edb4b50dc1ac504c51d0122ca02f Mon Sep 17 00:00:00 2001 From: crusader Date: Thu, 26 Apr 2018 21:48:01 +0900 Subject: [PATCH] =?UTF-8?q?=E3=85=91=ED=9B=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- socket/net/client/connector.go | 28 ++++++++++++++++------------ socket/web/client/connector.go | 28 ++++++++++++++++------------ 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/socket/net/client/connector.go b/socket/net/client/connector.go index 055ddb9..7d0fbfd 100644 --- a/socket/net/client/connector.go +++ b/socket/net/client/connector.go @@ -87,6 +87,18 @@ func (c *Connectors) logHeader() string { return fmt.Sprintf("Connector[%s]: ", c.Name) } +func (c *Connectors) onDisconnected() { + close(c.readChan) + close(c.writeChan) + + c.reconnectedChan <- nil + + onDisconnected := c.OnDisconnected + if nil != onDisconnected { + onDisconnected(c) + } +} + func (c *Connectors) handleReconnect() { defer func() { c.stopWg.Done() @@ -101,14 +113,8 @@ RC_LOOP: } if 0 >= c.GetReconnectTryTime() { - c.reconnectedChan <- nil - - onDisconnected := c.OnDisconnected - if nil != onDisconnected { - onDisconnected(c) - } - - continue RC_LOOP + c.onDisconnected() + return } logging.Logger().Debugf("%s connection lost", c.logHeader()) @@ -126,10 +132,8 @@ RC_LOOP: } logging.Logger().Debugf("%s reconnecting has been failed", c.logHeader()) - onDisconnected := c.OnDisconnected - if nil != onDisconnected { - onDisconnected(c) - } + c.onDisconnected() + return } } diff --git a/socket/web/client/connector.go b/socket/web/client/connector.go index 8854174..edadcf1 100644 --- a/socket/web/client/connector.go +++ b/socket/web/client/connector.go @@ -124,6 +124,18 @@ func (c *Connectors) logHeader() string { return fmt.Sprintf("Connector[%s]:", c.Name) } +func (c *Connectors) onDisconnected() { + close(c.readChan) + close(c.writeChan) + + c.reconnectedChan <- nil + + onDisconnected := c.OnDisconnected + if nil != onDisconnected { + onDisconnected(c) + } +} + func (c *Connectors) handleReconnect() { defer func() { c.stopWg.Done() @@ -138,14 +150,8 @@ RC_LOOP: } if 0 >= c.GetReconnectTryTime() { - c.reconnectedChan <- nil - - onDisconnected := c.OnDisconnected - if nil != onDisconnected { - onDisconnected(c) - } - - continue RC_LOOP + c.onDisconnected() + return } logging.Logger().Debugf("%s connection lost", c.logHeader()) @@ -168,10 +174,8 @@ RC_LOOP: } logging.Logger().Debugf("%s reconnecting has been failed", c.logHeader()) - onDisconnected := c.OnDisconnected - if nil != onDisconnected { - onDisconnected(c) - } + c.onDisconnected() + return } }