valyala/fasthttp

use tcpKeepaliveListener and reuseport together

Closed

#1,320 opened on Jun 14, 2022

 (3 comments) (0 reactions) (0 assignees)Go (1,755 forks)batch import
enhancementhelp wanted

Repository metrics

Stars
 (21,741 stars)
PR merge metrics
 (Avg merge 3d) (44 merged PRs in 30d)

Description

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

Contributor guide