This commit is contained in:
crusader 2018-04-18 21:11:52 +09:00
parent 750524f29c
commit 68341e3eb5
2 changed files with 26 additions and 0 deletions

View File

@ -22,6 +22,8 @@ type Connectors struct {
Address string `json:"address,omitempty"` Address string `json:"address,omitempty"`
LocalAddress net.Addr `json:"-"` LocalAddress net.Addr `json:"-"`
OnDisconnected func(connector client.Connector) `json:"-"`
stopChan chan struct{} stopChan chan struct{}
stopWg sync.WaitGroup stopWg sync.WaitGroup
@ -102,6 +104,12 @@ RC_LOOP:
if 0 >= c.GetReconnectTryTime() { if 0 >= c.GetReconnectTryTime() {
c.reconnectedChan <- nil c.reconnectedChan <- nil
onDisconnected := c.OnDisconnected
if nil != onDisconnected {
onDisconnected(c)
}
continue RC_LOOP continue RC_LOOP
} }
@ -118,7 +126,12 @@ RC_LOOP:
} }
time.Sleep(c.GetReconnectInterval()) time.Sleep(c.GetReconnectInterval())
} }
logging.Logger().Debugf("%s reconnecting has been failed", c.logHeader()) logging.Logger().Debugf("%s reconnecting has been failed", c.logHeader())
onDisconnected := c.OnDisconnected
if nil != onDisconnected {
onDisconnected(c)
}
} }
} }

View File

@ -52,6 +52,8 @@ type Connectors struct {
// If Proxy is nil or returns a nil *URL, no proxy is used. // If Proxy is nil or returns a nil *URL, no proxy is used.
Proxy func(*http.Request) (*url.URL, error) `json:"-"` Proxy func(*http.Request) (*url.URL, error) `json:"-"`
OnDisconnected func(connector client.Connector) `json:"-"`
serverURL *url.URL serverURL *url.URL
stopChan chan struct{} stopChan chan struct{}
@ -139,6 +141,12 @@ RC_LOOP:
if 0 >= c.GetReconnectTryTime() { if 0 >= c.GetReconnectTryTime() {
c.reconnectedChan <- nil c.reconnectedChan <- nil
onDisconnected := c.OnDisconnected
if nil != onDisconnected {
onDisconnected(c)
}
continue RC_LOOP continue RC_LOOP
} }
@ -161,6 +169,11 @@ RC_LOOP:
time.Sleep(c.GetReconnectInterval()) time.Sleep(c.GetReconnectInterval())
} }
logging.Logger().Debugf("%s reconnecting has been failed", c.logHeader()) logging.Logger().Debugf("%s reconnecting has been failed", c.logHeader())
onDisconnected := c.OnDisconnected
if nil != onDisconnected {
onDisconnected(c)
}
} }
} }