valyala/fasthttp

use tcpKeepaliveListener and reuseport together

Chiusa

#1320 aperta il 14 giu 2022

 (3 commenti) (0 reazioni) (0 assegnatari)Go (1755 fork)batch import
enhancementhelp wanted

Metriche repository

Star
 (21.741 stelle)
Metriche merge PR
 (Merge medio 3g) (44 PR mergiate in 30 g)

Descrizione

I need the functionality of both tcpKeepaliveListener and reuseport. something like this:

func ListenAndServe() error {
	s := &fasthttp.Server{
		Handler: handler,
		TCPKeepalive: true,
		TCPKeepalivePeriod: 30 * time.Second,
	}
	ln, err := reuseport.Listen("tcp4", ":8080")
	if err != nil {
		return err
	}
	if tcpln, ok := ln.(*net.TCPListener); ok {
		return s.Serve(tcpKeepaliveListener{
			TCPListener:     tcpln,
			keepalive:       s.TCPKeepalive,
			keepalivePeriod: s.TCPKeepalivePeriod,
		})
	}
	return s.Serve(ln)
}

is there a reason why tcpKeepaliveListener is private? is there another way to have both functionalities that I'm missing here? thanks a lot

Guida contributor