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: Mon, 10 Aug 2009 13:28:12 +0200
Le 10 août 09 à 12:40, Alastair Houghton a écrit :
On 10 Aug 2009, at 09:29, Frédéric Testuz wrote:
I'm using gnuplot to obtain graph of data. You can set gnuplot to
send results in various formats and to stdout
I found the way to call it and get the data with NSTask and NSPipe.
Actually, I get the image as an eps. The whole pack of data come in
several packs obtain by the pair of methods -[NSFileHandle
readInBackgroundAndNotify] and -[NSFileHandle availableData].
But I have to know when there is no more data to wait for. I have
found a solution in :
<http://www.cocoabuilder.com/archive/message/cocoa/
2000/11/21/31112> which use ioctl. This solution works, but it is a
very low api and the message is a little old now.
I just want to know if there is, today, another solution with a
higher api perhaps ?
From the documentation:
availableData
Returns the data available through the receiver.
[snip]
... Returns an empty data object if the end of file is reached. ...
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.
If I understand correctly, gnuplot don't send the end of file because
you can send new command to the same plot. And if an end of file was
sent, stdout would not be closed ? But if it's not the case I don't
think it makes a difference :
I observe the file handle for the data available notification
I call readInBackgroundAndNotify
My notification method is then called, inside it I call availableData
to read the data
It will be enough if all the data can be read in 1 time, because of
buffer, I think, the data come in several chunks. So in my
notification method I call readInBackgroundAndNotify again.
Now if I call readInBackgroundAndNotify and I have collected all the
data, I'm waiting for nothing. I can't inspect the data because there
is nothing in the EPS format to tell you that you are at the end of
the plot data (other than the end of the file). 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.
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