Ejemplo n.º 1
0
func (s *Service) listen(addr skynet.BindAddr, bindWait *sync.WaitGroup) {
	var err error
	s.rpcListener, err = addr.Listen()
	if err != nil {
		log.Fatal(err)
	}

	log.Printf(log.INFO, "%+v\n", ServiceListening{
		Addr:        &addr,
		ServiceInfo: s.ServiceInfo,
	})

	// We may have changed port due to conflict, ensure config has the correct port now
	a, _ := skynet.BindAddrFromString(addr.String())
	s.ServiceAddr.IPAddress = a.IPAddress
	s.ServiceAddr.Port = a.Port

	bindWait.Done()

	for {
		conn, err := s.rpcListener.AcceptTCP()

		if s.shuttingDown {
			break
		}

		if err != nil && !s.shuttingDown {
			log.Println(log.ERROR, "AcceptTCP failed", err)
			continue
		}
		s.connectionChan <- conn
	}
}
Ejemplo n.º 2
0
func (s *Service) cleanupDoozerEntriesForAddr(addr *skynet.BindAddr) {
	if addr == nil {
		return
	}
	q := skynet.Query{
		Host:       addr.IPAddress,
		Port:       strconv.Itoa(addr.Port),
		DoozerConn: s.doozer(),
	}

	instances := q.FindInstances()

	for _, i := range instances {
		s.Log.Trace("Cleaning up old doozer entry with conflicting addr " +
			addr.String() + "(" + i.GetConfigPath() + ")")
		s.doozer().Del(i.GetConfigPath(), s.doozer().GetCurrentRevision())
		s.doozer().Del(i.GetStatsPath(), s.doozer().GetCurrentRevision())
	}
}