Skip to content

Commit

Permalink
feat: add some log
Browse files Browse the repository at this point in the history
  • Loading branch information
chenqinghe committed Oct 18, 2022
1 parent d67b9c4 commit 5531442
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
},
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5531442

Please sign in to comment.