mirror of
https://github.com/fosrl/olm.git
synced 2026-02-08 05:56:41 +00:00
Try to close the socket first
This commit is contained in:
12
olm/olm.go
12
olm/olm.go
@@ -797,17 +797,19 @@ func (o *Olm) RebindSocket() error {
|
|||||||
return fmt.Errorf("shared bind is not initialized")
|
return fmt.Errorf("shared bind is not initialized")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the current port so we can try to reuse it
|
// Close the old socket first to release the port, then try to rebind to the same port
|
||||||
currentPort := o.sharedBind.GetPort()
|
currentPort, err := o.sharedBind.CloseSocket()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to close old socket: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
logger.Info("Rebinding UDP socket (current port: %d)", currentPort)
|
logger.Info("Rebinding UDP socket (released port: %d)", currentPort)
|
||||||
|
|
||||||
// Create a new UDP socket
|
// Create a new UDP socket
|
||||||
var newConn *net.UDPConn
|
var newConn *net.UDPConn
|
||||||
var newPort uint16
|
var newPort uint16
|
||||||
var err error
|
|
||||||
|
|
||||||
// First try to bind to the same port
|
// First try to bind to the same port (now available since we closed the old socket)
|
||||||
localAddr := &net.UDPAddr{
|
localAddr := &net.UDPAddr{
|
||||||
Port: int(currentPort),
|
Port: int(currentPort),
|
||||||
IP: net.IPv4zero,
|
IP: net.IPv4zero,
|
||||||
|
|||||||
Reference in New Issue
Block a user