Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opt: don't disable SO_REUSEPORT on DragonFlyBSD #583

Merged
merged 2 commits into from
Apr 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions gnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,15 +469,18 @@ func createListeners(addrs []string, opts ...Option) ([]*listener, *Options, err
// Linux implemented SO_REUSEPORT with load balancing for incoming connections
// while *BSD implemented it for only binding to the same address and port, which
// makes it pointless to enable SO_REUSEPORT on *BSD and Darwin for gnet with
// multiple event-loops because only the first event-loop will be constantly woken
// up to accept incoming connections and handle I/O events while the rest of event
// loops remain idle.
// multiple event-loops because only the first or last event-loop will be constantly
// woken up to accept incoming connections and handle I/O events while the rest of
// event-loops remain idle.
// Thus, we disable SO_REUSEPORT on *BSD and Darwin by default.
//
// Note that FreeBSD 12 introduced a new socket option named SO_REUSEPORT_LB
// with the capability of load balancing, it's the equivalent of Linux's SO_REUSEPORT.
// Also note that DragonFlyBSD 3.6.0 extended SO_REUSEPORT to distribute workload to
// available sockets, which make it the same as Linux's SO_REUSEPORT.
goos := runtime.GOOS
if (options.Multicore || options.NumEventLoop > 1) && options.ReusePort && goos != "linux" && goos != "freebsd" {
if (options.Multicore || options.NumEventLoop > 1) && options.ReusePort &&
goos != "linux" && goos != "dragonfly" && goos != "freebsd" {
options.ReusePort = false
}

Expand Down
Loading