Added support for connection reaping.
This commit is contained in:
parent
ff3e63da8d
commit
dbfccc4a0c
|
@ -44,9 +44,6 @@ type Connection struct {
|
||||||
// bytes out
|
// bytes out
|
||||||
bytesOut int64
|
bytesOut int64
|
||||||
|
|
||||||
// communications channel between go routines
|
|
||||||
commCh chan bool
|
|
||||||
|
|
||||||
// Connect Time
|
// Connect Time
|
||||||
connectTime time.Time
|
connectTime time.Time
|
||||||
|
|
||||||
|
@ -70,7 +67,6 @@ func NewConnection(connectionTable *Table, conn *websocket.Conn, remoteAddress s
|
||||||
p.bytesIn = 0
|
p.bytesIn = 0
|
||||||
p.bytesOut = 0
|
p.bytesOut = 0
|
||||||
p.send = make(chan *SendTrack)
|
p.send = make(chan *SendTrack)
|
||||||
p.commCh = make(chan bool)
|
|
||||||
p.connectTime = time.Now()
|
p.connectTime = time.Now()
|
||||||
p.initialDomains = initialDomains
|
p.initialDomains = initialDomains
|
||||||
p.DomainTrack = make(map[string]*DomainTrack)
|
p.DomainTrack = make(map[string]*DomainTrack)
|
||||||
|
@ -133,11 +129,6 @@ func (c *Connection) ConnectionTable() (table *Table) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//CommCh -- Property
|
|
||||||
func (c *Connection) CommCh() chan bool {
|
|
||||||
return c.commCh
|
|
||||||
}
|
|
||||||
|
|
||||||
//GetState -- Get state of Socket...this is a high level state.
|
//GetState -- Get state of Socket...this is a high level state.
|
||||||
func (c *Connection) GetState() bool {
|
func (c *Connection) GetState() bool {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package connection
|
package connection
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
import "time"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
initialDomains = 0
|
initialDomains = 0
|
||||||
|
@ -41,9 +42,30 @@ func (c *Table) ConnByDomain(domain string) (conn *Connection, ok bool) {
|
||||||
return
|
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
|
//Run -- Execute
|
||||||
func (c *Table) Run() {
|
func (c *Table) Run() {
|
||||||
loginfo.Println("ConnectionTable starting")
|
loginfo.Println("ConnectionTable starting")
|
||||||
|
|
||||||
|
go c.reaper(10, 20)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case registration := <-c.register:
|
case registration := <-c.register:
|
||||||
|
|
Loading…
Reference in New Issue