telebit/connection_table.go
Henry Camacho 894bd997a9 Restructured code, using module use, created logging package as a helper
- altered code to support a client bound interface
- altered code to support an admin bound interface
- added configurations and defaults.
- removed timeout function at the end of main.
- the final go routine was converted to a foreground routine.
2017-02-05 21:19:04 -06:00

40 lines
884 B
Go
Executable File

package main
// ConnectionTable maintains the set of connections
type ConnectionTable struct {
connections map[*Connection]bool
register chan *Connection
unregister chan *Connection
}
func newConnectionTable() *ConnectionTable {
return &ConnectionTable{
register: make(chan *Connection),
unregister: make(chan *Connection),
connections: make(map[*Connection]bool),
}
}
func (c *ConnectionTable) run() {
loginfo.Println("ConnectionTable starting")
for {
select {
case connection := <-c.register:
loginfo.Println("register fired")
c.connections[connection] = true
for conn := range c.connections {
loginfo.Println(conn)
}
case connection := <-c.unregister:
loginfo.Println("closing connection ", connection)
if _, ok := c.connections[connection]; ok {
delete(c.connections, connection)
close(connection.send)
}
}
}
}