From: pnr@innopoli.ajk.tele.fi (Pekka Nikander)
Subject: Re: Input Proc for File Handle
Organization: Telecomm Finland
	<1992Sep25.161348.2463@cis.ohio-state.edu>
	<1a56edINN4q0@agate.berkeley.edu>
Date: Sun, 4 Oct 1992 14:15:25 GMT

> In article <1992Sep25.161348.2463@cis.ohio-state.edu>, mdm@stegosaur.cis.ohio-state.edu (Michael Moore) writes:
> |> 	Ideally, John Ousterhout agrees that Tk_CreateFileHandler
> |> should be available at the tcl layer.  I cannot think of a good reason

In article <1a56edINN4q0@agate.berkeley.edu> ouster@sprite.Berkeley.EDU (John Ousterhout) writes:
> I agree that such a feature would be useful, and I'll add it to my list
> of things to do.  Unfortunately I can't promise it for the next release;
> at this point I can't even promise to define the syntax and publish it
> (doing so without the accomapanying implementation would probably be a
> mistake anyway, since there might be some implementation problem that
> I'd overlook).

> As several people have pointed out, adding this feature is really easy
> to do so I'd recommend just putting it in yourself;  when Tk starts
> supporting it I'm sure it will also be easy for you to shift over to
> using Tk's feature.

Well, there has already been "filehandler" command in my TcpConnect
package for some time.  And it has been inhereted to TclRawTcp from my
TcpConnect.  I did not had time to really thing about the interface
when I wrote it, so it might be reasonable to change the interface.
I would suggest such a change that there would be a separate Tcl proc
for each condition, and that the called Tcl proc would get just the
file as it's argument. 

Anyway, below you will find the relevant documentation.  A refecense
implementation can be found in the archive.  

NAME
     filehandler - handles open file I/O
_________________________________________________________________

     filehandler file ?mode command?
          The filehander command is only used with Tk.  The  com-
          mand  specifies a TCL command to be called whenever the
          given file can be read, written, and/or when  there  is
          an  exeptional  condition.  The mode argument indicates
          the situations when the command will be called.  It may
          be any combination of the following values:

          r    Call command whenever the there is  data  to  read
               from  the file.  The command procedure is called
               with two arguemnts: r to indicate  that  there  is
               something  to read, and a file id that can be used
               for reading.  The procedure should read  at  least
               some  data  from the file, or otherwise the pro-
               cedure will be called continuously.

          w    Call command whenever data can be written  to  the
               file.   This  option  is  rarely used since most
               files can be written most of the time.

          e    Call command whenever there is an exceptional con-
               dition  pending  on  the file.  The command pro-
               cedure is called with two arguments: an e to indi-
               cate  exception, and a file id that can be used as
               an argument to read, close etc.

          The same command may be used for several different con-
          ditions.    The  first  argument  supplied  to  command
          denotes  always  the  condition  type.   If  there  are
          several different conditions (e.g. the file can be both
          read  and  written),  the  command   will   be   called
          separately for each condition.

          Specifying a new command with filehandler  will  remove
          any  earlier  command from use.  NOTE!  Currently there
          is a small memory leak whenever a new command  replaces
          an existing one.

          When a command procedure is specified  for  the  file
          via  filehandler  command, the file will be automati-
          cally closed and the associated file handler deleted if
          there is a pending eof or error condition after execut-
          ing the user supplied command procedure.

AUTHOR
     Pekka Nikander, Telecom Finland (Pekka.Nikander@ajk.tele.fi)

--
Pekka Nikander                            Internet: pnr@ajk.tele.fi -or-
Telecom Finland                                     Pekka.Nikander@ajk.tele.fi