mirror of
https://github.com/yudai/gotty.git
synced 2026-01-20 16:26:10 +01:00
Add timeout option
This commit is contained in:
parent
c91fef051b
commit
8c9433ff21
5 changed files with 60 additions and 16 deletions
|
|
@ -10,6 +10,7 @@ import (
|
|||
"os/exec"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
|
|
@ -69,6 +70,21 @@ func (context *clientContext) goHandleClient() {
|
|||
|
||||
go func() {
|
||||
defer context.app.server.FinishRoutine()
|
||||
defer func() {
|
||||
connections := atomic.AddInt64(context.app.connections, -1)
|
||||
|
||||
if context.app.options.MaxConnection != 0 {
|
||||
log.Printf("Connection closed: %s, connections: %d/%d",
|
||||
context.request.RemoteAddr, connections, context.app.options.MaxConnection)
|
||||
} else {
|
||||
log.Printf("Connection closed: %s, connections: %d",
|
||||
context.request.RemoteAddr, connections)
|
||||
}
|
||||
|
||||
if connections == 0 {
|
||||
context.app.restartTimer()
|
||||
}
|
||||
}()
|
||||
|
||||
<-exit
|
||||
context.pty.Close()
|
||||
|
|
@ -79,14 +95,6 @@ func (context *clientContext) goHandleClient() {
|
|||
|
||||
context.command.Wait()
|
||||
context.connection.Close()
|
||||
context.app.connections--
|
||||
if context.app.options.MaxConnection != 0 {
|
||||
log.Printf("Connection closed: %s, connections: %d/%d",
|
||||
context.request.RemoteAddr, context.app.connections, context.app.options.MaxConnection)
|
||||
} else {
|
||||
log.Printf("Connection closed: %s, connections: %d",
|
||||
context.request.RemoteAddr, context.app.connections)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue