Add keepalive message to port forwarder
This commit is contained in:
parent
913f70a2af
commit
2f105fa6b5
9
net.go
9
net.go
@ -11,6 +11,7 @@ import (
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -35,12 +36,18 @@ func portForward(wanConn *net.TCPConn, lanIp, port string, connStatus chan ConnS
|
||||
go forwardConn(wanConn, lanConn, done)
|
||||
go forwardConn(lanConn, wanConn, done)
|
||||
|
||||
ticker := time.NewTicker(time.Minute * 1)
|
||||
for i := 0; i < 2; i++ {
|
||||
err = <-done
|
||||
select {
|
||||
case err = <-done:
|
||||
if err != nil {
|
||||
log.Print("Proxy:", err)
|
||||
}
|
||||
case <-ticker.C:
|
||||
connStatus <- ConnStatus{Status: CONN_ACTIVE}
|
||||
}
|
||||
}
|
||||
ticker.Stop()
|
||||
|
||||
wanConn.Close()
|
||||
lanConn.Close()
|
||||
|
@ -38,7 +38,6 @@ type ServerManager struct {
|
||||
done chan interface{}
|
||||
connStatus chan ConnStatus
|
||||
lastKeepAliveTime time.Time
|
||||
usageScore int // spin down server when this reaches 0
|
||||
server ServerHandler
|
||||
}
|
||||
|
||||
@ -49,7 +48,6 @@ func NewServerManager(name string, server ServerHandler, settings Settings) *Ser
|
||||
sm.ports = settings.Servers[name].Ports
|
||||
sm.in = make(chan serverManagerEvent)
|
||||
sm.done = make(chan interface{})
|
||||
sm.usageScore = 5
|
||||
sm.server = server
|
||||
|
||||
return sm
|
||||
@ -80,6 +78,8 @@ func (me *ServerManager) Serve() {
|
||||
}
|
||||
}
|
||||
|
||||
ticker.Stop()
|
||||
|
||||
// notify done
|
||||
me.done <- 42
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user