Re: Advice, please, on creating a new channel type (I think)
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.tcl archive

Re: Advice, please, on creating a new channel type (I think)

From: Christopher Nelson <cnelson@nycap.rr.com>
Date: Wed May 25 2005 - 14:29:28 CEST

Christopher Nelson wrote:
> > > Christopher Nelson wrote:
> > > > I need to create a Tcl extension to access ethernet ports that
> > > > have some unusual hardware managing them. ... If someone
> > > > here who's familiar with the code could give me a pointer ...
> > > > I'd sure appreciate it.
> > > >
> ..
> OK. I've got a very rough implementation that seems to kind of do
> something. It creates a channel that I can pass to [fileevent] and
> have it call the handler. However, the channel seems to be constantly
> readable with 0 bytes available most of the time. Can someone help me
> understand how the readable attribute is set? ...

I think I've got this licked. Feedback on whether this is the "right"
thing to do is appreciated:

  // Call Tcl_NotifyChannel only if it's our data.
  static void my_NotifyChannel(Tcl_Channel channel, int mask)
  {
      if (myPeekChannel(channel) != TCL_ERROR) {
          Tcl_NotifyChannel(channel, mask);
      }
  }

  static void mspWatch(ClientData instanceData, int mask)
  {
      MspState *fsPtr = (MspState*)instanceData;
      if (mask) {
          Tcl_CreateFileHandler(fsPtr->sock, mask,
                                (Tcl_FileProc *)my_NotifyChannel,
                                (ClientData) fsPtr->channel);
      } else {
          Tcl_DeleteFileHandler(fsPtr->sock);
      }
  }

where myPeekChannel() looks at the channel to see if the next message
is mine. If it is, it returns TCL_OK. If it's not, it reads and
discards it and returns TCL_ERROR.

                                       Chris
Received on Thu Sep 29 14:18:57 2005