Added support for connection reaping.

This commit is contained in:
Henry Camacho 2017-02-19 14:32:03 -06:00
parent ff3e63da8d
commit dbfccc4a0c
2 changed files with 22 additions and 9 deletions

View File

@ -44,9 +44,6 @@ type Connection struct {
// bytes out
bytesOut int64
// communications channel between go routines
commCh chan bool
// Connect Time
connectTime time.Time
@ -70,7 +67,6 @@ func NewConnection(connectionTable *Table, conn *websocket.Conn, remoteAddress s
p.bytesIn = 0
p.bytesOut = 0
p.send = make(chan *SendTrack)
p.commCh = make(chan bool)
p.connectTime = time.Now()
p.initialDomains = initialDomains
p.DomainTrack = make(map[string]*DomainTrack)
@ -133,11 +129,6 @@ func (c *Connection) ConnectionTable() (table *Table) {
return
}
//CommCh -- Property
func (c *Connection) CommCh() chan bool {
return c.commCh
}
//GetState -- Get state of Socket...this is a high level state.
func (c *Connection) GetState() bool {
defer func() {

View File

@ -1,6 +1,7 @@
package connection
import "fmt"
import "time"
const (
initialDomains = 0
@ -41,9 +42,30 @@ func (c *Table) ConnByDomain(domain string) (conn *Connection, ok bool) {
return
}
//reaper --
func (c *Table) reaper(delay int, idle int) {
for {
loginfo.Println("Reaper waiting for ", delay, " seconds")
time.Sleep(time.Duration(delay) * time.Second)
loginfo.Println("Running scanning ", len(c.connections))
for d := range c.connections {
if d.GetState() == false {
if time.Since(d.lastUpdate).Seconds() > float64(idle) {
loginfo.Println("reaper removing ", d.lastUpdate, time.Since(d.lastUpdate).Seconds())
delete(c.connections, d)
}
}
}
}
}
//Run -- Execute
func (c *Table) Run() {
loginfo.Println("ConnectionTable starting")
go c.reaper(10, 20)
for {
select {
case registration := <-c.register: