示例#1
0
func (c *Core) Start() {
	//TODO(kevlar)

	// Listen on each port
	c.listener = conn.NewListener()
	for _, port := range []int{6666, 6667} {
		c.listener.AddPort(port)
		c.ports[port] = true
	}
	go func() {
		for conn := range c.listener.Incoming {
			conn.Subscribe(c.messages)
		}
	}()

	go c.run()
}
示例#2
0
func Start() {
	// Make sure the configuration is good before we do anything
	if !CheckConfig() {
		log.Error.Fatalf("Could not start: invalid configuration")
	}

	listener := conn.NewListener()
	defer listener.Close()
	for _, ports := range Config.Ports {
		portlist, err := ports.GetPortList()
		if err != nil {
			log.Warn.Print(err)
		}
		for _, port := range portlist {
			listener.AddPort(port)
		}
	}

	s := &IRCd{
		Incoming:      listener.Incoming,
		newClient:     make(chan *conn.Conn),
		newServer:     make(chan *conn.Conn),
		clientClosing: make(chan string),
		serverClosing: make(chan string),

		ToClient:   make(chan *parser.Message, SendQ),
		ToServer:   make(chan *parser.Message, SendQ),
		fromClient: make(chan *parser.Message, SendQ),
		fromServer: make(chan *parser.Message, SendQ),

		running: new(sync.WaitGroup),
	}

	s.running.Add(1)
	go s.manageClients()

	s.running.Add(1)
	go s.manageServers()

	s.running.Add(1)
	go s.manageIncoming()

	s.running.Wait()
}