From 553144277d865d05afe3d18682b1da83c4961b26 Mon Sep 17 00:00:00 2001 From: chenqinghe Date: Tue, 18 Oct 2022 16:27:35 +0800 Subject: [PATCH] feat: add some log --- client.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index b712a16..21ccaf9 100644 --- a/client.go +++ b/client.go @@ -17,11 +17,11 @@ type Client struct { } type NewClientOptions struct { - Authenticator Authenticator EnableKeepalive bool KeepalivePeriod time.Duration HeartbeatPacketFactory func() Packet OnConnected func(c Conn) error + OnSessionCreated func(s *Session) OnClosed func(session *Session) NeedReconnect bool ReconnectPolicy ReconnectPolicy @@ -41,7 +41,7 @@ func NewClient(codec Codec, handler Handler, opts *NewClientOptions) *Client { closed: make(chan struct{}), } cli.mgr = NewManager(handler, &NewManagerOptions{ - Authenticator: opts.Authenticator, + OnSessionCreated: opts.OnSessionCreated, AfterSessionClosed: func(s *Session) { cli.reconnect(s) }, @@ -80,6 +80,8 @@ func (cli *Client) reconnect(sess *Session) { policy := cli.opts.ReconnectPolicy for cli.needReconnect(sess) && policy.Retry() { + logrus.WithField("sessionId", sess.id).WithField("remoteAddr", sess.RemoteAddr().String()).Debugln("session reconnect") + if s, err := cli.Dial(addr.Network(), addr.String()); err == nil { s.data = sess.data s.user = sess.user