Skip to content

Commit

Permalink
opt: don't disable SO_REUSEPORT on DragonFlyBSD (panjf2000#583)
Browse files Browse the repository at this point in the history
  • Loading branch information
panjf2000 authored and andyl committed Apr 22, 2024
1 parent 7717171 commit 0e982e4
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions gnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,15 +474,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

0 comments on commit 0e982e4

Please sign in to comment.