From help-octave-request at bevo dot che dot wisc dot edu Wed Jan 31 19:17:16 2001 Subject: Re: filesize of fifo From: Paul Kienzle To: Daniel Heiserer Cc: "help-octave at bevo dot che dot wisc dot edu" Date: Wed, 31 Jan 2001 18:14:03 +0000 Daniel, The function stat('filename') will return size information, but that is not what you want. It only tells you what the OS has buffered. If your libraries are caching reads then stat will give a smaller size than the number of bytes available to you. Octave 2.1.31 is doing this. Similarly, if your libraries are caching writes then stat will give a smaller size than the number of bytes you put into the fifo, and they will not be available on the other side. In Octave 2.1.31, fwrite seems to be caching but fputs isn't. The better way is to make the read-end of your fifo non-blocking: fid = fopen("fifo", "r"); fcntl(fid, F_SETFL, O_NONBLOCK); It appears that O_NONBLOCK must be set immediately after opening. Note that the fopen call will block until the write-end has been opened. Now you can do fread/fgets calls as normal. However, if you ever run out of input, then Octave will think that you have encountered an end of file and will refuse to try to read any more. As a workaround, you can close and reopen the file and it will work as normal (with only a 4 ms overhead on my Pentium 166), but this is ugly. Anyone know what's going on? Paul Kienzle pkienzle at kienzle dot powernet dot co dot uk On Wed, Jan 31, 2001 at 10:56:56PM +0100, Daniel Heiserer wrote: > Hi, > is there a function inside octave to find out > how large a file is, or how much data in a fifo is? > > something like fsize(fid) or fsize('filename')? > > I try to read from a fifo, but if the fifo is > empty octave's fread waits until something is in it. > I need a way to empty the fifo, which means > I read all the bytes which are in the fifo. > If there is nothing in, it mustn't block me. > If I try to read more bytes then are currently in > the fifo, octave blocks and waits > until he receives the necessary bytes. > If I leave out the number of bytes to read > he probably waits for ever. If I know how > many bytes in the fifo are (as I can see when > I know the filesize I can octave tell to read only > the specified size). > > Is there a way to read/write to fifo's in a non-blocking > mode? Linux programmers manual mentions this feature, > but doesn't tell me how non-blocking fifo's can be > realized. > > Thanks daniel > > > > ------------------------------------------------------------- > Octave is freely available under the terms of the GNU GPL. > > Octave's home on the web: http://www.octave.org > How to fund new projects: http://www.octave.org/funding.html > Subscription information: http://www.octave.org/archive.html > ------------------------------------------------------------- > > ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------