This commit is contained in:
crusader 2018-04-26 21:48:01 +09:00
parent d2e6df0fbf
commit d899e336c7
2 changed files with 32 additions and 24 deletions

View File

@ -87,6 +87,18 @@ func (c *Connectors) logHeader() string {
return fmt.Sprintf("Connector[%s]: ", c.Name) 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() { func (c *Connectors) handleReconnect() {
defer func() { defer func() {
c.stopWg.Done() c.stopWg.Done()
@ -101,14 +113,8 @@ RC_LOOP:
} }
if 0 >= c.GetReconnectTryTime() { if 0 >= c.GetReconnectTryTime() {
c.reconnectedChan <- nil c.onDisconnected()
return
onDisconnected := c.OnDisconnected
if nil != onDisconnected {
onDisconnected(c)
}
continue RC_LOOP
} }
logging.Logger().Debugf("%s connection lost", c.logHeader()) logging.Logger().Debugf("%s connection lost", c.logHeader())
@ -126,10 +132,8 @@ RC_LOOP:
} }
logging.Logger().Debugf("%s reconnecting has been failed", c.logHeader()) logging.Logger().Debugf("%s reconnecting has been failed", c.logHeader())
onDisconnected := c.OnDisconnected c.onDisconnected()
if nil != onDisconnected { return
onDisconnected(c)
}
} }
} }

View File

@ -124,6 +124,18 @@ func (c *Connectors) logHeader() string {
return fmt.Sprintf("Connector[%s]:", c.Name) 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() { func (c *Connectors) handleReconnect() {
defer func() { defer func() {
c.stopWg.Done() c.stopWg.Done()
@ -138,14 +150,8 @@ RC_LOOP:
} }
if 0 >= c.GetReconnectTryTime() { if 0 >= c.GetReconnectTryTime() {
c.reconnectedChan <- nil c.onDisconnected()
return
onDisconnected := c.OnDisconnected
if nil != onDisconnected {
onDisconnected(c)
}
continue RC_LOOP
} }
logging.Logger().Debugf("%s connection lost", c.logHeader()) logging.Logger().Debugf("%s connection lost", c.logHeader())
@ -168,10 +174,8 @@ RC_LOOP:
} }
logging.Logger().Debugf("%s reconnecting has been failed", c.logHeader()) logging.Logger().Debugf("%s reconnecting has been failed", c.logHeader())
onDisconnected := c.OnDisconnected c.onDisconnected()
if nil != onDisconnected { return
onDisconnected(c)
}
} }
} }