예제 #1
0
파일: net.go 프로젝트: codeslinger/Go25
func RunTCP(t TCPService) {
	l, err := net.ListenTCP("tcp", t.Addr())
	if err != nil {
		log.Error("failed to bind to local address %s", t.Addr())
		t.Shutdown()
		return
	}
	defer l.Close()

	log.Info("listening for connections on %s", t.Addr())
	for {
		conn, err := l.AcceptTCP()
		if err != nil {
			log.Error("failed to accept connection: %v", err)
			continue
		}
		if err := t.SetClientOptions(conn); err != nil {
			conn.Close()
			continue
		}
		log.Trace(func() string {
			return fmt.Sprintf("%s: client connected to %s", conn.RemoteAddr(), t.Addr())
		})
		go t.Handle(conn)
	}
}
예제 #2
0
파일: admin.go 프로젝트: codeslinger/Go25
// Process an incoming admin service connection.
func (a *AdminService) Handle(conn *net.TCPConn) {
	defer func() {
		log.Trace(func() string {
			return fmt.Sprintf("%s: client disconnected", conn.RemoteAddr())
		})
		conn.Close()
	}()
	if a.draining {
		return
	}
}
예제 #3
0
파일: smtp.go 프로젝트: codeslinger/Go25
// Process an incoming SMTP connection.
func (s *SMTPService) Handle(conn *net.TCPConn) {
	defer func() {
		log.Trace(func() string {
			return fmt.Sprintf("%s: client disconnected", conn.RemoteAddr())
		})
		conn.Close()
	}()

	// Send a 421 error response if the server is in the process of shutting
	// down when the client connects.
	if s.draining {
		conn.Write(ResponseMap[421])
		return
	}
	session := NewSMTPSession(conn, s.cfg)
	if verdict := session.Greet(); verdict == Terminate {
		return
	}
	for {
		if verdict := session.Process(); verdict == Terminate {
			return
		}
	}
}