Re: DO over network
Re: DO over network
- Subject: Re: DO over network
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Sun, 24 Oct 2004 11:53:27 +0200
On 24.10.2004, at 04:56, Wade Tregaskis wrote:
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?
Because if you close your side before the other does, the connection
is put into the TIME_WAIT state (or somesuch)... as such, the port is
still in use, technically. If you wait a brief time (which is
entirely dependant on network latency; there's no magic number) then
the other side will close the connection and it will not be left in
this TIME_WAIT state. At least, that's the gist of it.
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.
But your workaround will probably not work reliably, since it's
dependant on network latency.
Ok, I tried to set SO_REUSEADDR (and checked with getsockopt() that it
really is non-zero) and removed the sleep( 1/30 second ).
But again I had to wait a minute before I could re-use the port.
To be more precise:
The server does:
port = ... initWithTCPPort:
socket = [ port socket ]
int optval = YES ;
int optlen = sizeof(optval);
int yy = setsockopt( socket, SOL_SOCKET, SO_REUSEADDR, &optval, optlen);
The client gets a few addresses from netServiceDidResolveAddress: and
does:
adr = [ addresses lastObject ]
port = ... initRemoteWithProtocolFamily: AF_INET, SOCK_STREAM, tcp, adr
[ port socket ] returns -1 , so no flag-setting on client's send port.
connection = ... initWithReceivePort: nil sendPort: port
socket = [ [ connection receivePort ] socket ]
then set SO_REUSEADDR as above.
So: setting SO_REUSEADDR is the correct way, but I cannot get it to
work (maybe (or probably) I am doing something wrong), whereas my
workaround might not work reliably. What is to be prefered?
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