• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: BSD socket oddity with SO_REUSEADDR
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: BSD socket oddity with SO_REUSEADDR


  • Subject: Re: BSD socket oddity with SO_REUSEADDR
  • From: Aaron Ballman <email@hidden>
  • Date: Tue, 15 Jul 2003 14:17:34 -0500

1) Does this problem occur all the time?

All the time meaning reproducibly? Yes... I can bind the first time just fine. Then I close the socket down, and try to rebind (same run of the application), and I get the error (48 to be exact). Now, here's an odd thing though. If I terminate the application (gracefully or abortively) and then restart the entire application, I can bind again the first time (and subsequent close/rebinds fail). If that needs more explaining, just ask.. I'm sure I can word it better. :-P

2) Is gdb in the picture (i.e., are you debugging; if so, does the problem
show up without gdb)?

I am using CodeWarrior (8.0) to debug, and that uses gdb under the hood. But I see the problem without running under the debugger as well.

3) Do you see the problem if you kill the server before connecting to it?

Hmm... I'm not certain I follow you here... If the application quits, upon immediate restart, things behave for the first bind. Subsequent binds fail.

4) Has this code run on other BSDs? Winsock was close to BSD at one point,
but I suspect that's no longer the case; and the others bear no relation
to the BSD heritage.

The code was originally written on Linux (Redhat 9.0) and tested on there (albeit, not extensively tested) and worked fine. Some things have changed since the Linux incarnation, but that was more related to the accept process than the bind process.

If you haven't looked at it, you might consider Stevens's "Unix Network Programming", V1, 2nd Ed (Prentice Hall). He covers the use of SO_REUSEADDR and SO_REUSEPORT in some detail (typically, the latter is for multicast apps).

Also, his website (http://www.kohala.com) has a tarball of network code from this book. If I run some of the client/server examples from that collection, it works just fine, over and over.

I've seen it, read over it a bunch.. I've done _plenty_ of network programming before (mostly using WinSock and OpenTransport), and so the process all makes sense to me. I just feel like I am missing out on something.

It was my understanding that SO_REUSEADDR should be called before bind and it would allow you to bind to a socket that is in the TIME_WAIT state. The only way your call to bind would then fail is if the port (and address, but in this case it's INADDR_ANY) was in some state other than TIME_WAIT. Am I correct in this?

The only thing that I can think of is that before we get the chance to call bind, something else is snagging that port out from under me... but that seems rather far-fetched to me.

The application of this (in case this makes things a little more clear) is as a debugger for an IDE. When the debugger starts up, it listens on a port and the debugged application connects to it. That's why there are multiple listens on the same port within the same run of the application (since the port is only being listened on during the startup of a debug session). This allows (currently) for local debugging and (in the future) remote debugging.

Thanks!

~Aaron
--
Handy UNIX Commands:

sudo grep -e "My mind" -H -r /
mv /mnt/fuji /mnt/everest
mv "Ignorance" /dev/null
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: BSD socket oddity with SO_REUSEADDR
  • Next by Date: Re: BSD socket oddity with SO_REUSEADDR
  • Previous by thread: Re: BSD socket oddity with SO_REUSEADDR
  • Next by thread: A Dilemma about synchronous blocking and SSL
  • Index(es):
    • Date
    • Thread