forked from gliderlabs/ssh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
timeouts.go
41 lines (36 loc) · 779 Bytes
/
timeouts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"log"
"time"
"github.com/gliderlabs/ssh"
)
var (
DeadlineTimeout = 30 * time.Second
IdleTimeout = 10 * time.Second
)
func main() {
ssh.Handle(func(s ssh.Session) {
log.Println("new connection")
i := 0
for {
i += 1
log.Println("active seconds:", i)
select {
case <-time.After(time.Second):
continue
case <-s.Context().Done():
log.Println("connection closed")
return
}
}
})
log.Println("starting ssh server on port 2222...")
log.Printf("connections will only last %s\n", DeadlineTimeout)
log.Printf("and timeout after %s of no activity\n", IdleTimeout)
server := &ssh.Server{
Addr: ":2222",
MaxTimeout: DeadlineTimeout,
IdleTimeout: IdleTimeout,
}
log.Fatal(server.ListenAndServe())
}