mirror of
https://github.com/gofiber/fiber.git
synced 2025-02-21 07:52:53 +00:00
🔌 Support TCP6 in Prefork mode
This commit is contained in:
parent
caf98efddf
commit
c46e0379e3
3
app.go
3
app.go
@ -490,9 +490,6 @@ func (app *App) Listen(address interface{}, tlsconfig ...*tls.Config) error {
|
|||||||
app.init()
|
app.init()
|
||||||
// Start prefork
|
// Start prefork
|
||||||
if app.Settings.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...)
|
return app.prefork(addr, tlsconfig...)
|
||||||
}
|
}
|
||||||
// Setup listener
|
// Setup listener
|
||||||
|
@ -35,8 +35,13 @@ func (app *App) prefork(addr string, tlsconfig ...*tls.Config) (err error) {
|
|||||||
// use 1 cpu core per child process
|
// use 1 cpu core per child process
|
||||||
runtime.GOMAXPROCS(1)
|
runtime.GOMAXPROCS(1)
|
||||||
var ln net.Listener
|
var ln net.Listener
|
||||||
// SO_REUSEPORT is not supported on Windows, use SO_REUSEADDR instead
|
network := "tcp4"
|
||||||
if ln, err = reuseport.Listen("tcp4", addr); err != nil {
|
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 {
|
if !app.Settings.DisableStartupMessage {
|
||||||
time.Sleep(100 * time.Millisecond) // avoid colliding with startup message
|
time.Sleep(100 * time.Millisecond) // avoid colliding with startup message
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user