// run listens for incoming net.Conn connections and starts an electron.Connection for each one. func (b *broker) run() error { listener, err := net.Listen("tcp", *addr) if err != nil { return err } defer listener.Close() fmt.Printf("Listening on %v\n", listener.Addr()) go b.acknowledgements() // Handles acknowledgements for all connections. // Start a goroutine for each new connections for { conn, err := listener.Accept() if err != nil { util.Debugf("Accept error: %v", err) continue } c, err := b.container.Connection(conn, electron.Server(), electron.AllowIncoming()) if err != nil { util.Debugf("Connection error: %v", err) continue } cc := &connection{b, c} go cc.run() // Handle the connection util.Debugf("Accepted %v", c) } }
// Listens for connections and starts an electron.Connection for each one. func (b *broker) run() error { listener, err := net.Listen("tcp", *addr) if err != nil { return err } defer listener.Close() fmt.Printf("Listening on %s\n", listener.Addr()) for { conn, err := listener.Accept() if err != nil { util.Debugf("Accept error: %v", err) continue } c, err := b.container.Connection(conn, electron.Server(), electron.Accepter(b.accept)) if err != nil { util.Debugf("Connection error: %v", err) continue } util.Debugf("Accepted %v", c) } }