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: Frédéric Testuz <email@hidden>
- Date: Tue, 11 Aug 2009 08:56:44 +0200
Le 10 août 09 à 14:14, Alastair Houghton a écrit :
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.
Yes. Sorry if it was implicite on my part because I was talking about
a pipe communicating with a task.
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?
Yes, I still can quit gnuplot after each plot, but I don't know if it
will be very efficient (too early optimisation :-)
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.
I will not have the similar problem ? When I can be sure that the file
is written.
If you can live with invoking gnuplot separately every time, you
could just tell it to quit after generating the data that you want.
See above.
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.
Well thanks. Actually I'm doing it by coupling ioctl with checking the
data for the presence of "%%Trailer", but I'm not sure it will be ok
for future version of gnuplot.
Note : if there was an easy way to get a NSImage from svg I would have
choose this format. Finding the end svg data is easy (</svg>)
Frédéric_______________________________________________
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