Skip to content

Commit

Permalink
update.
Browse files Browse the repository at this point in the history
  • Loading branch information
blacknon committed Sep 8, 2024
1 parent 45ad91d commit 1b4de0c
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package sshlib

import (
"context"
"errors"
"io"
"log"
"net"
Expand Down Expand Up @@ -194,25 +193,30 @@ func (c *Connect) SendKeepAlive(session *ssh.Session) {
interval = c.SendKeepAliveInterval
}

max := 3
if c.SendKeepAliveMax > 0 {
max = c.SendKeepAliveMax
}

t := time.NewTicker(time.Duration(c.ConnectTimeout) * time.Second)
defer t.Stop()

count := 0
for {
select {
case <-t.C:
if _, err := session.SendRequest("[email protected]", true, nil); err != nil {
if !errors.Is(err, io.EOF) {
log.Println("Failed to send keepalive packet:", err)
} else {
// err is io.EOF
log.Println("Session io.EOF. exit keepalive.")
}
return
log.Println("Failed to send keepalive packet:", err)
count += 1
} else {
// err is nil.
time.Sleep(time.Duration(interval) * time.Second)
}
}

if count > max {
return
}
}
}

Expand Down

0 comments on commit 1b4de0c

Please sign in to comment.