Sleep to close fd

This commit is contained in:
Jason A. Donenfeld 2017-09-26 15:24:18 +02:00
parent 6fa65bded4
commit 32d8932d1b

View file

@ -3,6 +3,7 @@ package main
import ( import (
"errors" "errors"
"net" "net"
"time"
) )
func parseEndpoint(s string) (*net.UDPAddr, error) { func parseEndpoint(s string) (*net.UDPAddr, error) {
@ -36,6 +37,10 @@ func updateUDPConn(device *Device) error {
if netc.conn != nil { if netc.conn != nil {
netc.conn.Close() netc.conn.Close()
netc.conn = nil netc.conn = nil
// We need for that fd to be closed in all other go routines, which
// means we have to wait. TODO: find less horrible way of doing this.
time.Sleep(time.Second / 2)
} }
// open new connection // open new connection