mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-11-03 18:23:38 +08:00
feat: enable listen TIME_WAIT port
This commit is contained in:
parent
076205a290
commit
5555f31961
26
pkg/common/startrpc/socket_posix.go
Normal file
26
pkg/common/startrpc/socket_posix.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
//go:build linux || darwin
|
||||||
|
|
||||||
|
package startrpc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"github.com/openimsdk/tools/log"
|
||||||
|
"net"
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
func createListener() net.ListenConfig {
|
||||||
|
lc := net.ListenConfig{
|
||||||
|
Control: func(network, address string, conn syscall.RawConn) error {
|
||||||
|
return conn.Control(func(fd uintptr) {
|
||||||
|
err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1)
|
||||||
|
if err != nil {
|
||||||
|
log.ZError(context.Background(), "Failed to set socket flag to SO_REUSEADDR", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return lc
|
||||||
|
}
|
||||||
26
pkg/common/startrpc/socket_windows.go
Normal file
26
pkg/common/startrpc/socket_windows.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
//go:build windows
|
||||||
|
|
||||||
|
package startrpc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"github.com/openimsdk/tools/log"
|
||||||
|
"net"
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
func createListener() net.ListenConfig {
|
||||||
|
lc := net.ListenConfig{
|
||||||
|
Control: func(network, address string, conn syscall.RawConn) error {
|
||||||
|
return conn.Control(func(fd uintptr) {
|
||||||
|
err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1)
|
||||||
|
if err != nil {
|
||||||
|
log.ZError(context.Background(), "Failed to set socket flag to SO_REUSEADDR", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return lc
|
||||||
|
}
|
||||||
@ -55,13 +55,7 @@ func Start[T any](ctx context.Context, discovery *config.Discovery, prometheusCo
|
|||||||
"prometheusPorts", prometheusConfig.Ports)
|
"prometheusPorts", prometheusConfig.Ports)
|
||||||
rpcTcpAddr := net.JoinHostPort(network.GetListenIP(listenIP), strconv.Itoa(rpcPort))
|
rpcTcpAddr := net.JoinHostPort(network.GetListenIP(listenIP), strconv.Itoa(rpcPort))
|
||||||
|
|
||||||
lc := net.ListenConfig{
|
lc := createListener()
|
||||||
Control: func(network, address string, conn syscall.RawConn) error {
|
|
||||||
return conn.Control(func(fd uintptr) {
|
|
||||||
_ = syscall.SetsockoptInt(syscall.Handle(fd), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
}
|
|
||||||
listener, err := lc.Listen(
|
listener, err := lc.Listen(
|
||||||
ctx,
|
ctx,
|
||||||
"tcp",
|
"tcp",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user