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