> Benoît Minisini ha scritto:
> >> First you used buffered I/O, whereas PIPE in Gambas use non-buffered
> >> I/O. Then you use fgetc(), which reads one character, whereas in Gambas
> >> the code uses LINE INPUT, which is far more complex. So you are not
> >> comparing the two same programs...
> >> 
> >> Regards,
> > 
> > And the same program as you written in Gambas works too:
> >   Dim hFile As File
> >   Dim iChar As Byte
> >   
> >   hFile = Pipe "/tmp/FIFO1" For Input
> >   
> >   Print "Now let's start:";; Eof(hFile)
> >   
> >   Do
> >   
> >     Try iChar = Read #hFile As Byte
> >     If Error Then
> >     
> >       ' Normally the error is "End of file"
> >       Print Error.Text
> >       Break
> >     
> >     Endif
> >     Print Chr$(iChar);
> >   
> >   Loop
> >   
> >   Print "That's it."
> 
> I promise that this is my last email on this subject.
> 
> I did some research about eof() & pipes just because not only one, but
> two persons on this list said that eof() has no sense with pipes. It was
> not to say that gambas has glitches. Now, you are saying that the gambas
> code above runs just fine - and this, together with previous proofs,
> shows that eof works even with pipes.
> 
> About comparing two different programs: I chose to make a test in C
> because that way I was closer to the system, not knowing what cat(1)
> does, and not knowing what gambas does. Remember, I wanted to
> demonstrate that eof works.
> 
> I find a little surprising that you start to talk about buffered and
> unbuffered I/O, or things like reading one char at a time. Do you really
> think that this does matter? If so, thousands of unix program should be
> revised - but I don't think. It is also strange that in this last
> program you don't test for eof(), but for an error. Eof and errors are
> different. If you really want to demonstrate that your program works,
> use the normal eof(), like I did. Lastly, your explanation about eof in
> a previous email was misleading: "eof checks if the pipe is empty"; EOF
> should not do that, pipes and sockets can be empty (no data ready), but
> this is not an eof condition. Even when reading in unblocking mode, the
> return code for an eof is different from an EAGAIN.
> 
> Anyway, I am happy that the above program works: our friend Rolf can
> rely on it.
> 
> Regards,
> Doriano
> 

The Gambas Eof() function has nothing related to the feof() C library 
function, even if they have almost the same name. So you can't make 
comparison.

To simulate what feof() does, I have to check if reading a byte on the stream 
raises an error on Gambas. This what happens when you use fgetc(): it finally 
reads a byte on the file descriptor associated with the C buffered stream, and 
set an internal flag on end of file, this flag being returned by feof().

In Gambas, Eof() really checks if something can be read on the internal file 
descriptor at the moment you call it. So you cannot use it to read a pipe. You 
have to explicitely read it in blocking mode (this is the default for a pipe 
in Gambas). Then either the read will wait for the data, either it will fail 
as soon as the pipe is closed.

Well, in a few words, don't mix the behaviour of Gambas, the C library and the 
Linux kernel!

Regards,

-- 
Benoît Minisini

------------------------------------------------------------------------------

_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to