Re: CFSockets, sockets and timeouts
Re: CFSockets, sockets and timeouts
- Subject: Re: CFSockets, sockets and timeouts
- From: Dario <email@hidden>
- Date: Mon, 12 Apr 2004 01:04:35 +0200
Hello !
To set the context a bit: I'm connected to many distant peers, to
whom I regularly send a stream of
data. I need to know at the time of the sending that the peers's pipe
is full or blocked.
I've been struggling a bit with CFSockets and non-blocking I/O and
I ended up using a mix
of hand-created native tcp sockets that I feed to CFSockets (so that
they can be handled transparently
by cocoa and its socket wait-loop thread, and then call my read
callback when data is available).
I tried CFSocketSendData, then send() with message options like
MSG_DONTWAIT but I still got
blocked until data was sent (to be more precise when the tcp send
buffer was full, I guess).
So I had to set the timeout option on the sockets themselves with :
err = setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
now, here comes my question:
I tried different values for timeout, but I'm not sure what would be
the best.
I'm sending data to a list of distant peers, and I don't want to waste
any time waiting if a peers'
pipe is still full, but I don't want to set a value too low for the
TCP stack itself to handle.
I tried values ranging from 20ms to 10 microseconds.
How low can I set it so that my thread isn't blocked ?
Does the timeout take in account time to buffer it ?
If I set a very low timeout, will data still be queued in the TCP send
buffer ?
thanks for your hints ^_^
haven't you tried with fcntl to set the O_NONBLOCK flag? that should
work.
If you timeout then not all the data will be sent, it can be all as it
can be just a small part of it, but you should send all the whole data
stream, isn't it ?
_______________________________________________
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.