Esempio n. 1
0
func (l *LookupServer) Main() {
	l.logf("lookup server start")

	tcpListener, err := net.Listen("tcp", l.Opts.TcpAddress)
	if err != nil {
		l.logf("error, Listen(%s) failed - %s", l.Opts.TcpAddress, err)
		os.Exit(1)
	}
	l.Lock()
	l.tcpListener = tcpListener
	l.Unlock()

	ctx := &context{s: l}
	tcpSrv := &tcpServer{ctx: ctx}
	l.wg.Wrap(func() {
		proto.TCPServer(l.tcpListener, tcpSrv, l.Opts.Logger)
	})

	httpListener, err := net.Listen("tcp", l.Opts.HttpAddress)
	if err != nil {
		l.logf("error, Listen(%s) failed - %s", l.Opts.HttpAddress, err)
		os.Exit(1)
	}
	l.Lock()
	l.httpListener = httpListener
	l.Unlock()
	hServer := &httpServer{ctx: ctx}
	l.wg.Wrap(func() {
		http_wrap.ServeHttp(l.httpListener, hServer, l.Opts.Logger)
	})

}
Esempio n. 2
0
func (s *Server) Main() {

	ctx := &context{s}
	//listener
	tcpListener, err := net.Listen("tcp", s.Opts.TCPAddress)
	if err != nil {
		s.logf("FATAL: listen: %s failed - %s", s.Opts.TCPAddress, err)
		os.Exit(1)
	}

	s.Lock()
	s.tcpListener = tcpListener
	s.Unlock()

	//start tcp server
	tcpServer := &tcpServer{ctx: ctx}
	s.wg.Wrap(func() {
		proto.TCPServer(tcpListener, tcpServer, s.Opts.Logger)
	})

	httpListener, err := net.Listen("tcp", s.Opts.HTTPAddress)
	if err != nil {
		s.logf("FATAL: listen %s failed - %s", s.Opts.HTTPAddress, err)
		os.Exit(1)
	}
	s.Lock()
	s.httpListener = httpListener
	s.Unlock()
	hServer := &httpServer{ctx: ctx}
	s.wg.Wrap(func() {
		http_wrap.ServeHttp(s.httpListener, hServer, s.Opts.Logger)
	})
	//cache
	s.wg.Wrap(func() {
		s.cacheLoop()
	})
	//stat
	s.wg.Wrap(func() {
		s.statLoop()
	})

	//watch file, to change the cache
	s.wg.Wrap(func() {
		s.watchLoop()
	})

	//lookup server
	s.wg.Wrap(func() {
		s.lookupLoop()
	})
}