Skip to content

Commit 00af160

Browse files
authored
Merge pull request #169 from openziti/disconnect-handler
Add disconnect handler to reconnecting impl. Fixes #168
2 parents 8bb3a42 + b0d9331 commit 00af160

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

reconnecting_dialer.go

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,35 @@ import (
2727
)
2828

2929
type ReconnectingDialerConfig struct {
30-
Identity *identity.TokenId
31-
Endpoint transport.Address
32-
LocalBinding string
33-
Headers map[int32][]byte
34-
TransportConfig transport.Configuration
35-
ReconnectHandler func()
30+
Identity *identity.TokenId
31+
Endpoint transport.Address
32+
LocalBinding string
33+
Headers map[int32][]byte
34+
TransportConfig transport.Configuration
35+
ReconnectHandler func()
36+
DisconnectHandler func()
3637
}
3738

3839
type reconnectingDialer struct {
39-
identity *identity.TokenId
40-
endpoint transport.Address
41-
localBinding string
42-
headers map[int32][]byte
43-
tcfg transport.Configuration
44-
reconnectLock sync.Mutex
45-
reconnectHandler func()
40+
identity *identity.TokenId
41+
endpoint transport.Address
42+
localBinding string
43+
headers map[int32][]byte
44+
tcfg transport.Configuration
45+
reconnectLock sync.Mutex
46+
reconnectHandler func()
47+
disconnectHandler func()
4648
}
4749

4850
func NewReconnectingDialer(config ReconnectingDialerConfig) UnderlayFactory {
4951
return &reconnectingDialer{
50-
identity: config.Identity,
51-
endpoint: config.Endpoint,
52-
headers: config.Headers,
53-
reconnectHandler: config.ReconnectHandler,
54-
tcfg: config.TransportConfig,
55-
localBinding: config.LocalBinding,
52+
identity: config.Identity,
53+
endpoint: config.Endpoint,
54+
headers: config.Headers,
55+
reconnectHandler: config.ReconnectHandler,
56+
disconnectHandler: config.DisconnectHandler,
57+
tcfg: config.TransportConfig,
58+
localBinding: config.LocalBinding,
5659
}
5760
}
5861

@@ -101,6 +104,10 @@ func (dialer *reconnectingDialer) Reconnect(impl *reconnectingImpl) error {
101104
}
102105

103106
impl.reconnecting.Store(true)
107+
if dialer.disconnectHandler != nil {
108+
dialer.disconnectHandler()
109+
}
110+
104111
defer func() {
105112
impl.reconnecting.Store(false)
106113
if dialer.reconnectHandler != nil {

0 commit comments

Comments
 (0)