Re: Question about NSFileHandle for socket use
Re: Question about NSFileHandle for socket use
- Subject: Re: Question about NSFileHandle for socket use
- From: Andrew White <email@hidden>
- Date: Fri, 19 Aug 2005 13:38:56 +1000
Brant Sears wrote:
Then it occurred to me that while this works fine on my super fast
Macintosh G4 system, it might not work so great when I am communicating
with a different device that might be slower or have less memory - even
an older Mac. So, here's my question. Is there a good way for the sender
to know how slow it should write the data to the NSFileHandle so that it
doesn't go too fast for a given receiver?
Important question - is your underlying transport TCP or UDP?
TCP is "reliable", so will attempt to alter traffic rate to match receive
rate. UDP isn't.
However, your problem could well be local. You might be filling up the
data buffer. I notice that NSFileHandle writeData: says "Raises an
exception if the file descriptor is closed or is not valid, if the receiver
represents an unconnected pipe or socket endpoint, if no free space is left
on the file system, or if any other writing error occurs.". It's quite
possible that you are blasting data into your socket faster than it can
handle it, your buffer is filling, and you are not catching the exception
so never find out. See the NSFileHandle documentation and "man 2 write"
for more details.
The low-level way of dealing with this is to use 'select', checking to make
sure the buffer has space available before writing. I'm not sure what the
equivalent NSFileHandle abstraction is, or whether it contains glue code to
protect against send buffer overflow errors.
--
Andrew White
--------------------------------------------------------------------------
This email and any attachments may be confidential. They may contain legally
privileged information or copyright material. You should not read, copy,
use or disclose them without authorisation. If you are not an intended
recipient, please contact us at once by return email and then delete both
messages. We do not accept liability in connection with computer virus,
data corruption, delay, interruption, unauthorised access or unauthorised
amendment. This notice should not be removed.
_______________________________________________
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