UDP re-bind / reset a socket

270 views Asked by At

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 the bind call, but this seems to silently fail
  • Attempt #2: My next idea was to call close and then bind on the socket fd. But that didn't work because the socket is no longer bindable after the close.
  • Attempt #3: Call close, then create a new socket, then call bind on that. Oddly, it says that the socket is still "bound".
  • Attempt #4: Call close, wait 100ms, then create a new socket, then call bind 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?

0

There are 0 answers