Tcl question: fileevent: Does it block?

Joel Hammer joel
Mon May 17 11:57:41 PDT 2004


Here is a code snippet that works all as expected: The script runs
through all its commands, and waits for input in the pipe. No blocking.

When input arrives, the GetData proc is activated and reads what is
in the pipe, whether there is one or many lines in the pipe  Great.
However, this only happens once.  Additional input into the pipe is
ignored, the pipe seeming to be closed.

Changing fconfig to -blocking true didn't make any difference.

Any hints appreciated,

Joel


#!/etc/alternatives/wish -f
proc GetData {chan} {
    while {![eof $chan]} {
        gets $chan f
}
set  id [ open /tmp/NewPipe {RDONLY NONBLOCK} ]
fconfigure $id -blocking false
fileevent $id readable [list GetData $id ]


On Wed, Dec 31, 2003 at 01:18:06PM +0100, Roger Oberholtzer wrote:
> fileevent, by nature, should be non-blocking. That is, it is usually set
> up so that the code is only called when there is the requested activity
> on the channel However, once in the fileevent handler, you can do
> whatever you want, including trying to read more than is there or
> writing when the output channel is full. How the channel acts depends on
> you set it up with 'fconfigure'. 
> 


More information about the Linux-users mailing list