File tree Expand file tree Collapse file tree 1 file changed +12
-8
lines changed Expand file tree Collapse file tree 1 file changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,6 @@ package sshlib
6
6
7
7
import (
8
8
"context"
9
- "errors"
10
9
"io"
11
10
"log"
12
11
"net"
@@ -194,25 +193,30 @@ func (c *Connect) SendKeepAlive(session *ssh.Session) {
194
193
interval = c .SendKeepAliveInterval
195
194
}
196
195
196
+ max := 3
197
+ if c .SendKeepAliveMax > 0 {
198
+ max = c .SendKeepAliveMax
199
+ }
200
+
197
201
t := time .NewTicker (time .Duration (c .ConnectTimeout ) * time .Second )
198
202
defer t .Stop ()
199
203
204
+ count := 0
200
205
for {
201
206
select {
202
207
case <- t .C :
203
208
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
211
211
} else {
212
212
// err is nil.
213
213
time .Sleep (time .Duration (interval ) * time .Second )
214
214
}
215
215
}
216
+
217
+ if count > max {
218
+ return
219
+ }
216
220
}
217
221
}
218
222
You can’t perform that action at this time.
0 commit comments