1
0
mirror of https://github.com/gofiber/fiber.git synced 2025-02-19 14:07:53 +00:00

🔌 Support TCP6 in Prefork mode

This commit is contained in:
Fenny 2020-07-18 00:57:43 +02:00 committed by ReneWerner87
parent caf98efddf
commit c46e0379e3
2 changed files with 7 additions and 5 deletions

3
app.go
View File

@ -490,9 +490,6 @@ func (app *App) Listen(address interface{}, tlsconfig ...*tls.Config) error {
app.init()
// Start prefork
if app.Settings.Prefork {
if app.Settings.Network == "tcp6" || isIPv6(addr) {
return fmt.Errorf("listen: tcp6 is not supported when prefork is enabled")
}
return app.prefork(addr, tlsconfig...)
}
// Setup listener

View File

@ -35,8 +35,13 @@ func (app *App) prefork(addr string, tlsconfig ...*tls.Config) (err error) {
// use 1 cpu core per child process
runtime.GOMAXPROCS(1)
var ln net.Listener
// SO_REUSEPORT is not supported on Windows, use SO_REUSEADDR instead
if ln, err = reuseport.Listen("tcp4", addr); err != nil {
network := "tcp4"
if app.Settings.Network == "tcp6" {
network = app.Settings.Network
}
// 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 {
if !app.Settings.DisableStartupMessage {
time.Sleep(100 * time.Millisecond) // avoid colliding with startup message
}