0

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?

theicfire
  • 2,719
  • 2
  • 26
  • 29
  • For **1** what is your return value from `setsockopt()`? **2** Once you close, the socket isn't valid. **3** Calling close, the kernel doesn't "finish" closing before your call exists. Think of it as adding to a kernel todo list, no need to keep you waiting. **4** See my reply to 3 <-. **5** Works, but that asks kernel to duplicate it to all listeners (new and pending close one). – James Risner Sep 23 '22 at 19:23
  • I'll answer once I get a reply to #1. – James Risner Sep 23 '22 at 19:24
  • I'm prettty sure it returned zero. That is, no errors. My follow up question -- what documentation/code agrees with this async nature you describe? That's quite curious to me! – theicfire Sep 25 '22 at 23:59
  • Two examples off the top of my head: sendfile returns before the file is transferred **and** bhyve vm create/destroy returns before the vm operation is done. – James Risner Sep 26 '22 at 00:07
  • Ok if zero. Can you code that I can reproduce the error? – James Risner Sep 26 '22 at 00:09
  • Here you go -- usage is in the comments at the top: https://gist.github.com/theicfire/bd0f490df2442d90741b8b75f40edaaf – theicfire Oct 11 '22 at 01:42

0 Answers0