forked from valyala/fasthttp
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support AIX SO_REUSEADDR and SO_REUSEPORT (valyala#1328)
* Update reuseport.go * Create reuseport_aix.go
- Loading branch information
1 parent
8c3146a
commit 2ea4526
Showing
2 changed files
with
27 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package reuseport | ||
|
||
import ( | ||
"context" | ||
"net" | ||
"syscall" | ||
|
||
"golang.org/x/sys/unix" | ||
) | ||
|
||
var listenConfig = net.ListenConfig{ | ||
Control: func(network, address string, c syscall.RawConn) (err error) { | ||
return c.Control(func(fd uintptr) { | ||
err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEADDR, 1) | ||
if err == nil { | ||
err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1) | ||
} | ||
}) | ||
}, | ||
} | ||
|
||
// Listen returns TCP listener with SO_REUSEADDR and SO_REUSEPORT option set, so it uses | ||
func Listen(network, addr string) (net.Listener, error) { | ||
return listenConfig.Listen(context.Background(), network, addr) | ||
} |