Skip to content

Commit 1b4de0c

Browse files
committed
update.
1 parent 45ad91d commit 1b4de0c

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

connect.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package sshlib
66

77
import (
88
"context"
9-
"errors"
109
"io"
1110
"log"
1211
"net"
@@ -194,25 +193,30 @@ func (c *Connect) SendKeepAlive(session *ssh.Session) {
194193
interval = c.SendKeepAliveInterval
195194
}
196195

196+
max := 3
197+
if c.SendKeepAliveMax > 0 {
198+
max = c.SendKeepAliveMax
199+
}
200+
197201
t := time.NewTicker(time.Duration(c.ConnectTimeout) * time.Second)
198202
defer t.Stop()
199203

204+
count := 0
200205
for {
201206
select {
202207
case <-t.C:
203208
if _, err := session.SendRequest("[email protected]", true, nil); err != nil {
204-
if !errors.Is(err, io.EOF) {
205-
log.Println("Failed to send keepalive packet:", err)
206-
} else {
207-
// err is io.EOF
208-
log.Println("Session io.EOF. exit keepalive.")
209-
}
210-
return
209+
log.Println("Failed to send keepalive packet:", err)
210+
count += 1
211211
} else {
212212
// err is nil.
213213
time.Sleep(time.Duration(interval) * time.Second)
214214
}
215215
}
216+
217+
if count > max {
218+
return
219+
}
216220
}
217221
}
218222

0 commit comments

Comments
 (0)