tun2: pingloop

This commit is contained in:
Cadey Ratio 2017-03-26 15:14:13 -07:00
parent 65f99d052b
commit 1d5c58e22d
1 changed files with 26 additions and 0 deletions

View File

@ -11,6 +11,7 @@ import (
"net"
"net/http"
"sync"
"time"
"git.xeserv.us/xena/route/database"
"github.com/Xe/ln"
@ -139,6 +140,31 @@ func (s *Server) ListenAndServe() error {
}()
}
go func() {
for {
time.Sleep(5 * time.Second)
s.connlock.Lock()
for conn, c := range s.conns {
conn.SetDeadline(time.Now().Add(1 * time.Second))
req, err := http.NewRequest("GET", "http://backend/health", nil)
if err != nil {
panic(err)
}
_, err = s.RoundTrip(req)
if err != nil {
ln.Error(err)
c.cancel()
}
}
s.connlock.Unlock()
}
}()
return nil
}