🔍 detect tcp proto by addr

pull/640/head
Fenny 2020-07-18 01:19:45 +02:00 committed by ReneWerner87
parent 4554ea135c
commit 7f44f5b017
2 changed files with 10 additions and 5 deletions

8
app.go
View File

@ -479,15 +479,15 @@ func (app *App) Listen(address interface{}, tlsconfig ...*tls.Config) error {
}
// Update fiber server settings
app.init()
// Start prefork
if app.Settings.Prefork {
return app.prefork(addr, tlsconfig...)
}
// Set correct network protocol
network := "tcp4"
if isIPv6(addr) {
network = "tcp6"
}
// Start prefork
if app.Settings.Prefork {
return app.prefork(network, addr, tlsconfig...)
}
// Setup listener
ln, err := net.Listen(network, addr)
if err != nil {

View File

@ -29,12 +29,17 @@ func (app *App) IsChild() bool {
}
// prefork manages child processes to make use of the OS REUSEPORT or REUSEADDR feature
func (app *App) prefork(network, addr string, tlsconfig ...*tls.Config) (err error) {
func (app *App) prefork(addr string, tlsconfig ...*tls.Config) (err error) {
// 👶 child process 👶
if app.IsChild() {
// use 1 cpu core per child process
runtime.GOMAXPROCS(1)
var ln net.Listener
// Set correct network protocol
network := "tcp4"
if isIPv6(addr) {
network = "tcp6"
}
// Linux will use SO_REUSEPORT and Windows falls back to SO_REUSEADDR
// Only tcp4 or tcp6 is supported when preforking, both are not supported
if ln, err = reuseport.Listen(network, addr); err != nil {