Commit 7a10af48 authored by wei.xuan's avatar wei.xuan

feat: update timeout

parent 6a967689
......@@ -5,6 +5,7 @@ import (
"fmt"
"net"
"strings"
"sync"
"time"
"github.com/adamweixuan/getty"
......@@ -21,9 +22,9 @@ var (
func (client *Client) handleHeartbeat(session getty.Session) {
go func() {
if _, _, err := session.WritePkg(HeartbeatPacket, time.Second*3); err != nil {
getty.GetLogger().Errorf("handleHeartbeat error %+v %v->%v", err, session.IsClosed(), session.GetActive())
getty.GetLogger().Errorf("handleHeartbeat error %+v %v", err, session.IsClosed())
} else {
getty.GetLogger().Infof("handleHeartbeat success %v->%v", session.IsClosed(), session.GetActive())
getty.GetLogger().Infof("handleHeartbeat success %v", session.IsClosed())
}
}()
}
......@@ -188,8 +189,9 @@ func (client *Client) CloseAll(session getty.Session) {
client.connStore.Range(func(key, value interface{}) bool {
serialNumber := key.(int64)
conn, _ := value.(net.Conn)
getty.GetLogger().Infof("close serialNumber -> %d", serialNumber)
getty.GetLogger().Infof("[CloseAll] close serialNumber -> %d", serialNumber)
client.OnClose(session, conn, serialNumber)
return true
})
client.connStore = sync.Map{}
}
package client
import (
"errors"
"runtime"
"time"
......@@ -14,7 +15,7 @@ type MajoraEventListener struct {
}
func (m *MajoraEventListener) OnOpen(session getty.Session) error {
getty.GetLogger().Info("==================OnOpen==================")
getty.GetLogger().Infof("connect to nathost %s success ...", m.client.config.TunnelAddr)
packet := protocol.TypeRegister.CreatePacket()
packet.Extra = m.client.config.ClientID
extraMap := make(map[string]string, 1)
......@@ -35,8 +36,11 @@ func (m *MajoraEventListener) OnClose(session getty.Session) {
func (m *MajoraEventListener) OnError(session getty.Session, err error) {
getty.GetLogger().Errorf("OnError %s", err.Error())
if errors.Is(err, common.ErrInvalidMagic) {
session.Close()
}
m.client.CloseAll(session)
session.Close()
}
func (m *MajoraEventListener) OnCron(session getty.Session) {
......
......@@ -29,7 +29,6 @@ func (client *Client) connect() {
getty.WithClientTaskPool(taskPool))
gettyCli.RunEventLoop(NewClientSession(client))
client.natTunnel = gettyCli
getty.GetLogger().Infof("connect to nathost %s success ...", hostPort)
}
func NewClientSession(client *Client) func(getty.Session) error {
......@@ -81,7 +80,6 @@ func InitialSession(session getty.Session, client *Client) (err error) {
func (client *Client) Redial(session getty.Session) {
if !client.config.Redial.Valid() {
getty.GetLogger().Warnf("Redial invalid")
return
}
client.CloseAll(session)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment