mirror of
https://github.com/libp2p/go-reuseport.git
synced 2025-09-26 19:01:11 +08:00

Both sockopt and control errors can't exist at the same time, but control errors should occur first, and so are given precedence. Fixes #101
18 lines
341 B
Go
18 lines
341 B
Go
package reuseport
|
|
|
|
import (
|
|
"syscall"
|
|
|
|
"golang.org/x/sys/windows"
|
|
)
|
|
|
|
func Control(network, address string, c syscall.RawConn) (err error) {
|
|
controlErr := c.Control(func(fd uintptr) {
|
|
err = windows.SetsockoptInt(windows.Handle(fd), windows.SOL_SOCKET, windows.SO_REUSEADDR, 1)
|
|
})
|
|
if controlErr != nil {
|
|
err = controlErr
|
|
}
|
|
return
|
|
}
|