Re: DO over network
Re: DO over network
- Subject: Re: DO over network
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Sat, 23 Oct 2004 23:13:36 +0200
On 23.10.2004, at 19:27, Wade Tregaskis wrote:
1. tell all clients about my imminent demise (which prompts them to
cut and invalidate their connection)
2. usleep( 33333 )
3. [ connection invalidate]
4. [ receivePort invalidate]
When I omit step 2, a subsequent re-start of the server via:
[ [ NSSocketPort alloc] initWithTCPPort: portNbr ]
will return nil for the next minute. After this it will work ok.
When I sleep for less than 0.03 seconds the re-start sometimes fails.
What is going on here? What am I doing wrong?
Nothing... this sounds like the port is locking up, which is a result
of what happens when you let security people go crazy. Basically,
under most *nixes there is by default a period after a port is unbound
in which it cannot be rebound - this is what you're seeing with
initWithTCPPort returning nil.
Yes, but why do I *not* see this 60 seconds of not being able to rebind
when I sleep 0.03 seconds before doing invalidate?
I think you're supposed to be able to turn this "feature" *cough BS
cough* off by setting the SO_REUSEADDR [or whatever] option on the
socket, but I've never seen this actually work - presumably I'm doing
something wrong though; many others have fixed the problem by doing
this. Anyway, see man setsockopt for details. You will have to
create your sockets manually (using socket(), I would assume), set
SO_REUSEADDR, and then initialise your NSSocketPort's from that using
initWithProtocolFamily:socketType:protocol:socket:.
This looks like more work than my current workaround of sleeping for
1/30 second.
By the way: I used getsockopt() and found for the port created by
initWithTCPPort: SO_REUSEPORT = SO_REUSEADDR = SO_LINGER = off;
SO_RCVTIMEO = SO_SNDTIMEO = 0.
Looks all quite normal to me.
Gerriet.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden