Example #1
0
func (s *Mta) Stop() {
	log.Printf("Received stop command. Sending shutdown event...")
	close(s.shutDownC)
	// Give existing connections some time to finish.
	t := time.Duration(10)
	log.Printf("Waiting for a maximum of %d seconds...", t)
	time.Sleep(t * time.Second)
	log.Printf("Sending force quit event...")
	close(s.quitC)
}
Example #2
0
func (p *MtaProtocol) GetIP() net.IP {
	ip, _, err := net.SplitHostPort(p.c.RemoteAddr().String())
	if err != nil {
		log.Printf("Could not get ip: %v", p.c.RemoteAddr().String())
		return nil
	}

	return net.ParseIP(ip)
}
Example #3
0
func (s *DefaultMta) listen(ln net.Listener) error {
	defer ln.Close()
	for {
		c, err := ln.Accept()
		if err != nil {
			if ne, ok := err.(net.Error); ok && ne.Temporary() {
				log.Printf("Accept error: %v", err)
				continue
			}
			// Assume this means listener was closed.
			if noe, ok := err.(*net.OpError); ok && !noe.Temporary() {
				log.Printf("Listener is closed, stopping listen loop...")
				return nil
			}
			return err
		}

		s.mta.wg.Add(1)
		go s.serve(c)
	}

}
Example #4
0
func (s *DefaultMta) ListenAndServe() error {
	ln, err := net.Listen("tcp", fmt.Sprintf("%s:%d", s.mta.config.Ip, s.mta.config.Port))
	if err != nil {
		log.Errorln("Could not start listening: %v", err)
		return err
	}

	// Close the listener so that listen well return from ln.Accept().
	go func() {
		_, ok := <-s.mta.shutDownC
		if !ok {
			ln.Close()
		}
	}()

	err = s.listen(ln)
	log.Printf("Waiting for connections to close...")
	s.mta.wg.Wait()
	return err
}
Example #5
0
func (p *MtaProtocol) Close() {
	err := p.c.Close()
	if err != nil {
		log.Printf("Error while closing protocol: %v", err)
	}
}