mirror of
https://github.com/rwinkhart/rcw.git
synced 2026-09-05 16:47:24 -04:00
Implement inactivity timer on Windows
This commit is contained in:
@@ -47,6 +47,7 @@ func Run() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
if err.(net.Error).Timeout() {
|
if err.(net.Error).Timeout() {
|
||||||
log.Println("Three minutes have passed without any connections. Exiting...")
|
log.Println("Three minutes have passed without any connections. Exiting...")
|
||||||
|
listener.Close()
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
log.Printf("Accept error: %v", err)
|
log.Printf("Accept error: %v", err)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/rpc"
|
"net/rpc"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/Microsoft/go-winio" // For Windows named pipes
|
"github.com/Microsoft/go-winio" // For Windows named pipes
|
||||||
"github.com/rwinkhart/peercred-mini"
|
"github.com/rwinkhart/peercred-mini"
|
||||||
@@ -44,21 +45,32 @@ func Run() {
|
|||||||
defer listener.Close()
|
defer listener.Close()
|
||||||
log.Printf("RPC daemon listening on %s", socketPath)
|
log.Printf("RPC daemon listening on %s", socketPath)
|
||||||
|
|
||||||
// accept connections (timeout after 3 minutes of inactivity)
|
// create 3-minute inactivity timer
|
||||||
for {
|
timer := time.NewTimer(3 * time.Minute)
|
||||||
// set deadline for accepting new connections
|
killTimer := make(chan struct{})
|
||||||
//listener.SetDeadline(time.Now().Add(3 * time.Minute)) TODO FIX
|
go func() {
|
||||||
|
select {
|
||||||
|
case <-timer.C:
|
||||||
|
log.Println("Three minutes have passed without any connections. Exiting...")
|
||||||
|
listener.Close()
|
||||||
|
os.Exit(0)
|
||||||
|
case <-killTimer:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
// accept connections
|
||||||
|
for {
|
||||||
conn, err := listener.Accept()
|
conn, err := listener.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsTimeout(err) {
|
|
||||||
log.Println("Three minutes have passed without any connections. Exiting...")
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
log.Printf("Accept error: %v", err)
|
log.Printf("Accept error: %v", err)
|
||||||
|
close(killTimer)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reset timer after connection is accepted
|
||||||
|
timer.Reset(3 * time.Minute)
|
||||||
|
|
||||||
// use a goroutine to check the client's identity
|
// use a goroutine to check the client's identity
|
||||||
go handleConn(conn)
|
go handleConn(conn)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user