Пример #1
0
func (n *NSQd) Main() {
	context := &Context{n}

	n.waitGroup.Wrap(func() { n.lookupLoop() })

	tcpListener, err := net.Listen("tcp", n.tcpAddr.String())
	if err != nil {
		log.Fatalf("FATAL: listen (%s) failed - %s", n.tcpAddr, err.Error())
	}
	n.tcpListener = tcpListener
	tcpServer := &tcpServer{context: context}
	n.waitGroup.Wrap(func() { util.TCPServer(n.tcpListener, tcpServer) })

	httpListener, err := net.Listen("tcp", n.httpAddr.String())
	if err != nil {
		log.Fatalf("FATAL: listen (%s) failed - %s", n.httpAddr, err.Error())
	}
	n.httpListener = httpListener
	httpServer := &httpServer{context: context}
	n.waitGroup.Wrap(func() { util.HTTPServer(n.httpListener, httpServer) })

	if n.options.statsdAddress != "" {
		n.waitGroup.Wrap(func() { n.statsdLoop() })
	}
}
Пример #2
0
func (l *NSQLookupd) Main() {
	context := &Context{l}

	tcpListener, err := net.Listen("tcp", l.tcpAddr.String())
	if err != nil {
		log.Fatalf("FATAL: listen (%s) failed - %s", l.tcpAddr, err.Error())
	}
	l.tcpListener = tcpListener
	tcpServer := &tcpServer{context: context}
	l.waitGroup.Wrap(func() { util.TCPServer(tcpListener, tcpServer) })

	httpListener, err := net.Listen("tcp", l.httpAddr.String())
	if err != nil {
		log.Fatalf("FATAL: listen (%s) failed - %s", l.httpAddr, err.Error())
	}
	l.httpListener = httpListener
	httpServer := &httpServer{context: context}
	l.waitGroup.Wrap(func() { util.HTTPServer(httpListener, httpServer) })
}