mirror of https://github.com/gofiber/fiber.git
🔍 detect tcp proto by addr
parent
4554ea135c
commit
7f44f5b017
8
app.go
8
app.go
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue