After creating and binding to a UDP socket, I'd like to later call setsockopt
for SO_MAX_PACING_RATE
.
What I tried to do:
- Attempt #1: I tried simply running
setsockopt
after thebind
call, but this seems to silently fail - Attempt #2: My next idea was to call
close
and thenbind
on the socket fd. But that didn't work because the socket is no longer bindable after theclose
. - Attempt #3: Call
close
, then create a new socket, then callbind
on that. Oddly, it says that the socket is still "bound". - Attempt #4: Call
close
, wait 100ms, then create a new socket, then callbind
on that. This works. What's going on here? - Attempt #5: Also use
SO_REUSEADDR
=> This works as well.
So my question is -- what is the canonical way create a UDP socket at a particular port, then close that socket and bind a new UDP socket on that same port?