diff --git a/daemon/2server.go b/daemon/2server.go index be19b9b..d4dfc09 100644 --- a/daemon/2server.go +++ b/daemon/2server.go @@ -8,6 +8,8 @@ import ( "github.com/rwinkhart/rcw/wrappers" ) +var Timeout = 300 // seconds for RPC server timeout; configurable + var daemonHash []byte var globalPassphrase []byte diff --git a/daemon/2serverUNIXGeneric.go b/daemon/2serverUNIXGeneric.go index d01f178..a94bbfa 100644 --- a/daemon/2serverUNIXGeneric.go +++ b/daemon/2serverUNIXGeneric.go @@ -47,14 +47,14 @@ func Start(passphrase []byte) { os.Exit(0) }() - // accept connections (timeout after 3 minutes of inactivity) + // accept connections until Timeout takes effect for { - listener.(*net.UnixListener).SetDeadline(time.Now().Add(3 * time.Minute)) + listener.(*net.UnixListener).SetDeadline(time.Now().Add(time.Duration(Timeout) * time.Second)) conn, err := listener.Accept() if err != nil { if err.(net.Error).Timeout() { - log.Println("Three minutes have passed without any connections. Exiting...") + log.Println(strconv.Itoa(Timeout) + " seconds have passed without any connections. Exiting...") listener.Close() os.Exit(0) } diff --git a/daemon/2serverWindows.go b/daemon/2serverWindows.go index 622892d..13223bb 100644 --- a/daemon/2serverWindows.go +++ b/daemon/2serverWindows.go @@ -9,6 +9,7 @@ import ( "net/rpc" "os" "os/signal" + "strconv" "syscall" "time" @@ -54,13 +55,13 @@ func Start(passphrase []byte) { // capture sigterms to ensure listener is closed sigChan := make(chan os.Signal, 1) signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM) - // create 3-minute inactivity timer - timer := time.NewTimer(3 * time.Minute) + // create inactivity timer + timer := time.NewTimer(time.Duration(Timeout) * time.Second) killTimer := make(chan struct{}) go func() { select { case <-timer.C: - log.Println("Three minutes have passed without any connections. Exiting...") + log.Println(strconv.Itoa(Timeout) + " seconds have passed without any connections. Exiting...") listener.Close() os.Exit(0) case <-killTimer: