Re: Testing if a NSPipe has available data
Re: Testing if a NSPipe has available data
- Subject: Re: Testing if a NSPipe has available data
- From: Alastair Houghton <email@hidden>
- Date: Mon, 10 Aug 2009 13:14:06 +0100
On 10 Aug 2009, at 12:28, Frédéric Testuz wrote:
Le 10 août 09 à 12:40, Alastair Houghton a écrit :
So what's wrong with waiting for -[NSFileHandle availableData] to
return with zero bytes?
First : if you call availableData and there is no data and the end
of file is not reached, you are blocking your thread.
Only if (a) there is no data available and (b) you are dealing with a
communications link.
If I understand correctly, gnuplot don't send the end of file
because you can send new command to the same plot.
Ah, OK, I assume in that case that you want to keep gnuplot running so
that you can plot something else afterwards?
In that case, the cleanest approach is probably going to be to tell
gnuplot to send the data somewhere other than stdout (using "set
output"). The simplest thing would be to use a temporary file.
If you can live with invoking gnuplot separately every time, you could
just tell it to quit after generating the data that you want.
So the only way I can see is to check if there still data waiting in
the file handle buffer before calling readInBackgroundAndNotify or
availableData.
That won't work in the general case; gnuplot might generate some data,
then your app might run and take it all, in which case there would be
no data waiting in the buffer... but gnuplot might not have finished
and might subsequently generate more data.
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden