// This works just like http.ListenAndServeTLS but certificates are loaded into
// a wrapper struct that reloads certificates from disk when a SIGHUP is
// received.
429160
func ListenAndServeTLS(addr, certFile, keyFile string, handler http.Handler) error {
	// From http.ListenAndServeTLS:
	// https://github.com/golang/go/blob/release-branch.go1.10/src/net/http/server.go#L3000-L3003
	server := &http.Server{Addr: addr, Handler: handler}

	keypair, err := NewKeypairReloader(certFile, keyFile)
	if err != nil {
		return err
	}
	server.TLSConfig = &tls.Config{GetCertificate: keypair.GetCertificateFunc()}

	// The certFile and keyFile arguments below are ignored if the GetCertificate field is not nil.
	return server.ListenAndServeTLS("", "")
}
730640
func (srv *Server) ListenAndServeTLSConfig(config *tls.Config) error {
	addr := srv.Addr
	if addr == "" {
		addr = ":https"
	}

	conn, err := srv.newTCPListener(addr)
	if err != nil {
		return err
	}

	srv.TLSConfig = config

	tlsListener := tls.NewListener(conn, config)
	return srv.Serve(tlsListener)
}
825932
func (cmd *Command) ListenAndServeHTTP(addr string) error {
	cmd.SetIsServer(true)
	return http.ListenAndServe(addr, cmd)
}
648617
func (sys *NotificationSys) ReloadFormat(dryRun bool) []NotificationPeerErr {
	ng := WithNPeers(len(sys.peerClients))
	for idx, client := range sys.peerClients {
		if client == nil {
			continue
		}
		client := client
		ng.Go(context.Background(), func() error {
			return client.ReloadFormat(dryRun)
		}, idx, *client.host)
	}
	return ng.Wait()
}
367205
func (s *Server) TLSListener() (net.Listener, error) {
	if !s.hasListeners {
		if err := s.Listen(); err != nil {
			return nil, err
		}
	}
	return s.httpsServerL, nil
}
999850
func (srv *Server) ListenAndServe() error {
	// Create the listener so we can control their lifetime
	addr := srv.Addr
	if addr == "" {
		addr = ":http"
	}
	conn, err := srv.newTCPListener(addr)
	if err != nil {
		return err
	}

	return srv.Serve(conn)
}
1138561
func ListenAndServe(s *http.Server, hd *HTTP) error {
	if hd == nil {
		hd = &HTTP{}
	}
	hs, err := hd.ListenAndServe(s)
	if err != nil {
		return err
	}

	waiterr := make(chan error, 1)
	go func() {
		defer close(waiterr)
		waiterr <- hs.Wait()
	}()

	signals := make(chan os.Signal, 10)
	signal.Notify(signals, syscall.SIGTERM, syscall.SIGINT)

	select {
	case err := <-waiterr:
		if err != nil {
			return err
		}
	case <-signals:
		signal.Stop(signals)
		if err := hs.Stop(); err != nil {
			return err
		}
		if err := <-waiterr; err != nil {
			return err
		}
	}
	return nil
}
674640
func (s *Server) ListenAndServe() error {
	if s.Server == nil {
		return errors.New("use of http3.Server without http.Server")
	}
	return s.serveImpl(s.TLSConfig, nil)
}
792558
func (s *GracefulServer) ListenAndServe() error {
	addr := s.Addr
	if addr == "" {
		addr = ":http"
	}
	listener, err := net.Listen("tcp", addr)
	if err != nil {
		return err
	}

	return s.Serve(listener)
}
286644
func (s *HTTPScaffold) Listen(baseHandler http.Handler) error {
	err := s.StartListen(baseHandler)
	if err != nil {
		return err
	}

	return s.WaitForShutdown()
}
346716
func (app *App) ListenAndServeAutoTLS(addr string, cachePath ...string) error {
	if len(app.TLSEmails) == 0 {
		return ErrTLSNoEmails
	}

	addr, err := normalizeTLSAddr(addr)
	if err != nil {
		app.internalLog.Errorf("Bad address %q: %s", addr, err)
	}

	ln, err := net.Listen("tcp", addr)
	if err != nil {
		app.internalLog.Errorf("Can't serve %q: %s", addr, err)
		return err
	}

	letscache := getCachePath()
	if len(cachePath) > 0 {
		letscache = cachePath[0]
	}

	s := rand.NewSource(time.Now().Unix())
	r := rand.New(s)
	m := autocert.Manager{
		Prompt: autocert.AcceptTOS,
		Email:  app.TLSEmails[r.Intn(len(app.TLSEmails))],
	}

	if letscache != "" {
		m.Cache = autocert.DirCache(letscache)
	}

	tlsConfig := getDefaultTLSConfig()
	tlsConfig.GetCertificate = func(hello *tls.ClientHelloInfo) (cert *tls.Certificate, err error) {
		if len(hello.ServerName) == 0 || hello.ServerName == localhost {
			hello.ServerName = localhost
			cert, err = selfSignedCertificate(hello)
		} else {
			cert, err = m.GetCertificate(hello)
		}

		if err != nil {
			app.internalLog.Errorf("Can't get cert for %q: %s", hello.ServerName, err)
		}

		return cert, err
	}

	tlsLn := tls.NewListener(ln, tlsConfig)

	l := app.internalLog.WithField("bind", addr)
	l.Info("Starting HTTPS")

	srv := app.copyServer()
	app.runningServersMu.Lock()
	app.runningServers = append(app.runningServers, runningServerInfo{
		bind: addr,
		srv:  srv,
	})
	app.runningServersMu.Unlock()
	if err = srv.Serve(tlsLn); err != nil {
		app.internalLog.Errorf("Can't serve: %s", err)
	}

	return err
}
150323
func (c *Client) loadServerCert(cert string) error {
	certPool := x509.NewCertPool()

	asn1, err := base64.RawStdEncoding.DecodeString(cert)
	if err != nil {
		return err
	}

	x509Cert, err := x509.ParseCertificate([]byte(asn1))
	if err != nil {
		return err
	}

	certPool.AddCert(x509Cert)

	c.config.TLSConfig.RootCAs = certPool
	return nil
}
927552
func (s *Server) ListenTCPTLS(addr string, config *tls.Config) error {
	listener, err := tls.Listen("tcp", addr, config)
	if err != nil {
		return err
	}

	s.doneTcp = make(chan bool)
	s.listeners = append(s.listeners, listener)
	return nil
}
407032
func (s *Server) ListenAndServe() error {
	addr := s.Addr
	if addr == "" {
		addr = ":imap"
	}

	l, err := net.Listen("tcp", addr)
	if err != nil {
		return err
	}

	return s.Serve(l)
}
1155142
func ListenAndServe(addr string, handler Handler) (err error) {
	var conn net.PacketConn

	if conn, err = net.ListenPacket("udp", addr); err != nil {
		return
	}

	err = Serve(conn, handler)
	return
}
315617
func listenTLS(app *iris.Application) {

	const (
		testTLSCert = `-----BEGIN CERTIFICATE-----
MIIDBTCCAe2gAwIBAgIJAOYzROngkH6NMA0GCSqGSIb3DQEBBQUAMBkxFzAVBgNV
BAMMDmxvY2FsaG9zdDo4MDgwMB4XDTE3MDIxNzAzNDM1NFoXDTI3MDIxNTAzNDM1
NFowGTEXMBUGA1UEAwwObG9jYWxob3N0OjgwODAwggEiMA0GCSqGSIb3DQEBAQUA
A4IBDwAwggEKAoIBAQCfsiVHO14FpKsi0pvBv68oApQm2MO+dCvq87sDU4E0QJhG
K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jZdZawUUuoX1iYLpZgNK25D0wtp1hdvjf2Ej/dAMd8bexHjvcaBT7ncqjiq
NmDcWjofIIXspTIyLwjStXGmJnJT7N/CqoYDjtTmHGND7Shpi3mAFn/r0isjFUJm
2J5RAoGALuGXxzmSRWmkIp11F/Qr3PBFWBWkrRWaH2TRLMhrU/wO8kCsSyo4PmAZ
ltOfD7InpDiCu43hcDPQ/29FUbDnmAhvMnmIQuHXGgPF/LhqEhbKPA/o/eZdQVCK
QG+tmveBBIYMed5YbWstZu/95lIHF+u8Hl+Z6xgveozfE5yqiUA=
-----END RSA PRIVATE KEY-----

	`
	)

	// create the key and cert files on the fly, and delete them when this test finished
	certFile, ferr := ioutil.TempFile("", "cert")

	if ferr != nil {
		panic(ferr)
	}

	keyFile, ferr := ioutil.TempFile("", "key")
	if ferr != nil {
		panic(ferr)
	}

	certFile.WriteString(testTLSCert)
	keyFile.WriteString(testTLSKey)

	// https://localhost
	app.Run(iris.TLS("localhost:443", certFile.Name(), keyFile.Name()))

	certFile.Close()
	time.Sleep(50 * time.Millisecond)
	os.Remove(certFile.Name())

	keyFile.Close()
	time.Sleep(50 * time.Millisecond)
	os.Remove(keyFile.Name())
}
126938
func ListenAndServe(addr string, handler http.Handler) error {
	defaultServer = NewWithServer(&http.Server{Addr: addr, Handler: handler})
	defaultServerLock.Unlock()
	return defaultServer.ListenAndServe()
}