From 68341e3eb5398af9a2faeeb6e54fbb10d574bbdc Mon Sep 17 00:00:00 2001 From: crusader Date: Wed, 18 Apr 2018 21:11:52 +0900 Subject: [PATCH] ing --- socket/net/client/connector.go | 13 +++++++++++++ socket/web/client/connector.go | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/socket/net/client/connector.go b/socket/net/client/connector.go index b12dbd9..cff84b7 100644 --- a/socket/net/client/connector.go +++ b/socket/net/client/connector.go @@ -22,6 +22,8 @@ type Connectors struct { Address string `json:"address,omitempty"` LocalAddress net.Addr `json:"-"` + OnDisconnected func(connector client.Connector) `json:"-"` + stopChan chan struct{} stopWg sync.WaitGroup @@ -102,6 +104,12 @@ RC_LOOP: if 0 >= c.GetReconnectTryTime() { c.reconnectedChan <- nil + + onDisconnected := c.OnDisconnected + if nil != onDisconnected { + onDisconnected(c) + } + continue RC_LOOP } @@ -118,7 +126,12 @@ RC_LOOP: } time.Sleep(c.GetReconnectInterval()) } + logging.Logger().Debugf("%s reconnecting has been failed", c.logHeader()) + onDisconnected := c.OnDisconnected + if nil != onDisconnected { + onDisconnected(c) + } } } diff --git a/socket/web/client/connector.go b/socket/web/client/connector.go index 507c016..0345bae 100644 --- a/socket/web/client/connector.go +++ b/socket/web/client/connector.go @@ -52,6 +52,8 @@ type Connectors struct { // If Proxy is nil or returns a nil *URL, no proxy is used. Proxy func(*http.Request) (*url.URL, error) `json:"-"` + OnDisconnected func(connector client.Connector) `json:"-"` + serverURL *url.URL stopChan chan struct{} @@ -139,6 +141,12 @@ RC_LOOP: if 0 >= c.GetReconnectTryTime() { c.reconnectedChan <- nil + + onDisconnected := c.OnDisconnected + if nil != onDisconnected { + onDisconnected(c) + } + continue RC_LOOP } @@ -161,6 +169,11 @@ RC_LOOP: time.Sleep(c.GetReconnectInterval()) } logging.Logger().Debugf("%s reconnecting has been failed", c.logHeader()) + + onDisconnected := c.OnDisconnected + if nil != onDisconnected { + onDisconnected(c) + } } }