fix(stream): use platform-specific socket options for Windows cross-compilation
This commit is contained in:
parent
55fb74c814
commit
264be4e309
3 changed files with 19 additions and 1 deletions
9
internal/engine/sockopt_unix.go
Normal file
9
internal/engine/sockopt_unix.go
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
//go:build !windows
|
||||
|
||||
package engine
|
||||
|
||||
import "syscall"
|
||||
|
||||
func setReuseAddr(fd uintptr) error {
|
||||
return syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1)
|
||||
}
|
||||
9
internal/engine/sockopt_windows.go
Normal file
9
internal/engine/sockopt_windows.go
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
//go:build windows
|
||||
|
||||
package engine
|
||||
|
||||
import "syscall"
|
||||
|
||||
func setReuseAddr(fd uintptr) error {
|
||||
return syscall.SetsockoptInt(syscall.Handle(fd), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1)
|
||||
}
|
||||
|
|
@ -72,7 +72,7 @@ func (ss *StreamServer) Listen(ctx context.Context) error {
|
|||
lc := net.ListenConfig{
|
||||
Control: func(network, address string, c syscall.RawConn) error {
|
||||
return c.Control(func(fd uintptr) {
|
||||
_ = syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1)
|
||||
_ = setReuseAddr(fd)
|
||||
})
|
||||
},
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue