mirror of
https://github.com/rwinkhart/rcw.git
synced 2026-08-28 04:46:42 -04:00
Make server timeout configurable at compile time
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user