Exemple #1
0
func ServeHttp(listener net.Listener, handler http.Handler, l common.Logger) {
	l.Output(2, fmt.Sprintf("HTTP: listening on: %s", listener.Addr()))
	s := &http.Server{
		Handler: handler,
	}

	err := s.Serve(listener)
	if err != nil {
		l.Output(2, fmt.Sprintf("HTTP: error %s ", err))
	}
}
Exemple #2
0
func TCPServer(listener net.Listener, handler TCPHandler, l common.Logger) {
	l.Output(2, fmt.Sprintf("TCP: listening on %s", listener.Addr()))

	for {
		clientConn, err := listener.Accept()
		if err != nil {
			if nerr, ok := err.(net.Error); ok && nerr.Temporary() {
				l.Output(2, fmt.Sprintf("Notice: temporary accept failure - %s", err.Error()))
				runtime.Gosched()
				continue
			}
			//not closed
			if !strings.Contains(err.Error(), "use of closed network connection") {
				l.Output(2, fmt.Sprintf("Error: listener.Accpet() - %s", listener.Addr()))
			}
			break
		}

		go handler.Handle(clientConn)
	}
}