[Gambas-user] Pipe doesn't receive contents

Benoît Minisini gambas at ...1...
Sat May 8 21:06:56 CEST 2010


> Benoît Minisini ha scritto:
> > Well, in a few words, don't mix the behaviour of Gambas, the C library
> > and the Linux kernel!
> 
> So you are true. If someone says that tail(1) does not work with pipes,
> because eof has no meaning, he is right. If someone else demonstrates
> that it works, is wrong. Eof ("End-Of-File": E.nd O.f F.ile) in gambas
> does not mean the same thing as the rest of the world - in gambas it
> means "I can not read right now, you fool!". Who cares about C library
> and kernel, gambas does not use them, right? Anyway, in the system (and
> I bet in most languages), Eof means the same thing, always, no matter if
> coping with files, pipes, sockets, serial terminals and so on. This is
> the beauty of unix. 
> In Gambas, Eof is good for true files; but not for
> pipes. For sockets, let me see a moment. For stdin, it depends: if it is
> a file, one thing; if it is a pipe, another thing; if it is a terminal,
> let me take a look (just a moment, you see, I use buffered non-blocking
> asynchronous sparse multi-line I/O and this is a complicated matter, it
> is not so simple like those stupid unix commands which, I don't know
> how, can run every aspect of a big unix system).
> 
> Sorry for the irony - 

Actually the irony is that you are writing the truth without noticing.

The beauty of unix is that everything is a file. Cool, but that really works 
only with files. For every other kind of file descriptor, the semantic is 
different. So don't expect Gambas to be more coherent that the underlying OS.

In Unix, there is no system call that tells you that are you are at the end of 
a file. But you have a system error instead, and that error really means "end 
of file" for files. For every other kind of file descriptor, it does not mean 
that. It depends.

For example, for pipes, that error is returned when the other end of the pipe 
is closed.

"End of file" in Gambas means "I cannot read right now", because I didn't find 
a better meaning that is coherent between all different kind of file 
descriptors. 

As we can't read the future, there is no way to know that we are at the end of 
file for descriptor that are not true files.

I told you not to mix the behaviour of Gambas, the C library and the Linux 
kernel, because by using feof() from the C library, you thought that you are 
doing the same thing than using Eof() in Gambas.

Then I admit that Eof() is not useful for pipes (and other special streams), 
so maybe I should make Eof() more clever:

- If the stream is in non-blocking mode, do as before, i.e. check that 
something can be read.

- If the stream is in blocking mode, try to just read a byte, and remember it. 
That way, if we were really at the "end of file" (or pipe closed for pipes, 
etc.), we get a system error that we can transform in gambas "end of file". 
Otherwise we block until a character arrives.

I will try that and see if then Eof() will behave a bit like feof().

Regards,

-- 
Benoît Minisini




More information about the User mailing list