1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2024-12-09 09:56:01 +02:00
imgproxy/listen_reuseport.go

34 lines
603 B
Go
Raw Normal View History

2019-06-27 10:00:39 +02:00
// +build linux darwin
// +build go1.11
package main
import (
"context"
"net"
"syscall"
"golang.org/x/sys/unix"
)
func listenReuseport(network, address string) (net.Listener, error) {
if !conf.SoReuseport {
return net.Listen(network, address)
}
lc := net.ListenConfig{
Control: func(_, _ string, c syscall.RawConn) error {
var cerr error
err := c.Control(func(fd uintptr) {
cerr = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1)
})
if err != nil {
return err
}
return cerr
},
}
return lc.Listen(context.Background(), network, address)
}