Beispiel #1
0
// Listens for connections on the given listener and puts them in the channel.
// Blocks while still receiving connections.
// Returns an error on network problem, or nil if shutdown requested
func listenForConnections(l net.Listener, c chan net.Conn) error {
	id, shutdownRequested := shutdown.AddShutdownListener("Connection listener")
	defer shutdown.RoutineDone(id)

	log.WithFields(log.Fields{
		"listening_on": fmt.Sprintf("%v", l.Addr()),
		"fqdn":         config.GetFQDN(),
	}).Info("Starting connection listener")

	// shutdown using the strategy found here http://stackoverflow.com/a/13419724
	quit := false
	go func() {
		<-shutdownRequested
		quit = true
		l.Close()
	}()

	for {
		conn, err := l.Accept()
		if err != nil {
			if quit {
				log.Info("Shutting down connection listener")
				return nil
			}
			l.Close()
			return err
		}
		c <- conn
	}
}
Beispiel #2
0
func (c *Client) notifyServiceReady() error {
	_, err := c.out.WriteString(fmt.Sprintf("220 %s ESMTP\r\n", config.GetFQDN()))
	if err != nil {
		return err
	}
	err = c.out.Flush()
	return err
}
Beispiel #3
0
func (c *Client) notifyEhlo() error {
	toWrite := fmt.Sprintf("250-%s supports ONE extension:\r\n",
		config.GetFQDN()) +
		"250-8BITMIME\r\n"
	_, err := c.out.WriteString(toWrite)
	if err != nil {
		return err
	}
	err = c.out.Flush()
	return err
}