[Gambas-user] Watching File and Pipe

Tobias Boege taboege at ...626...
Sun Jan 6 11:32:01 CET 2013


On Sun, 06 Jan 2013, Beno?t Minisini wrote:
> Le 06/01/2013 02:20, Tobias Boege a ?crit :
> > Hi Benoit,
> >
> > here's the story: I originally wanted to redirect the Error
> > instruction's default stream to a pipe which I could then read from
> > in the same application. For some reason I got a "Bad file
> > descriptor" (must be EBADF?) error when using
> >
> > Error "test"
> >
> > after having redirected
> >
> > Error To #File.In
> 
> File.In is associated with a file descriptor opened for reading, so this
> is a non-sense.
> 
> The only thing you can do is Error To #File.Out.
> 
> >
> > I am used to stdin being open and writable but maybe things are
> > different in graphical applications - would be logical; I don't
> > know...
> 
> Where did you read that? Did you notice the "in" in "stdin"?
> 

I kind of read that in the "kbd" source code. It holds at least for the
Linux console that you can freely write to fd 0 if this in turn is
connected to a tty. This does _not_ work, however, for FILE *stdin, quite
true.

> >
> > However, it didn't work so I tried with a temporary file - I simply
> > needed a stream with one read and one write end.
> >
> > The problem now is, when I try to watch a File or Pipe created using
> > either
> >
> > hFile = Open sPath For Input Output Create Watch
> >
> > or
> >
> > hPipe = Pipe sPath For Read Write Watch
> >
> > that the File_Read() event is called without end
> 
> Logical, as a normal file is always ready to be read.
> 

The doc says: "If at least one byte can be read". This statement is IMHO
ambiguous. I expected the Read() event to be raised when Lof(hFile) > 0.
Do you think this sentence needs clarification?

> > and Pipe_Read() is never called.
> >
> > Moreover, the Pipe seems to raise the File_Read() event and not the
> > Pipe_Read() one and the file does not raise either event. The
> > combination of the creation flags does _not_ seem to be the reason. I
> > got the same results when using distinct read and write streams for
> > both of them.
> 
> All streams use "File_" as event handler prefix, even pipes.
> 

I went and fixed the documentation for PIPE accordingly.

Regards,
Tobi




More information about the User mailing list