feat: client handshake info

This commit is contained in:
Toby
2023-11-18 16:19:08 -08:00
parent cccb9558c0
commit 0a77ce4d64
8 changed files with 148 additions and 34 deletions

View File

@@ -12,13 +12,14 @@ import (
type reconnectableClientImpl struct {
config *Config
client Client
info *HandshakeInfo
count int
connectedFunc func(Client, int) // called when successfully connected
connectedFunc func(Client, *HandshakeInfo, int) // called when successfully connected
m sync.Mutex
closed bool // permanent close
}
func NewReconnectableClient(config *Config, connectedFunc func(Client, int), lazy bool) (Client, error) {
func NewReconnectableClient(config *Config, connectedFunc func(Client, *HandshakeInfo, int), lazy bool) (Client, error) {
// Make sure we capture any error in config and return it here,
// so that the caller doesn't have to wait until the first call
// to TCP() or UDP() to get the error (when lazy is true).
@@ -42,13 +43,13 @@ func (rc *reconnectableClientImpl) reconnect() error {
_ = rc.client.Close()
}
var err error
rc.client, err = NewClient(rc.config)
rc.client, rc.info, err = NewClient(rc.config)
if err != nil {
return err
} else {
rc.count++
if rc.connectedFunc != nil {
rc.connectedFunc(rc, rc.count)
rc.connectedFunc(rc, rc.info, rc.count)
}
return nil
}