Re: Rolling your own event handler

"gunnarr@ifi.uio.no" writes:

> > Rather than handing event control to HT and telling HT to listen for X
> > input, perhaps one could use the normal X event/input control and tell
> > X/Xt to listen for HT input. A program can use XtAppAddInput (' not sure
> 
> I too think that would be nice. What we need then is 1) a method to get
> the file descriptor associated with an request and 2) a method to call when
> there is data pending on the socket. 

The event model is currently built so that is possible. When a socket blocks 
in the middle of a request, the load module calls the event module with the 
socket in question and the request object. These two are then be registered 
together so that the request object associated with a socket can be found 
again.

However, in some situations you have more than one socket pr request and/or a 
socket can last for more than one socket. This is for example the case with 
FTP and HTTP using persistent connections. The HTNet object is used to handle 
this and also to be the glue between the socket descriptor and the request 
object. The HTNet object represents a "library thread" as it has a socket 
_and_ and request object associated with it.

It also has a pointer to the right callback function (that is, the load 
module) so that when a socket is ready for action, both the request object, 
the load module and the socket descriptor can be found again and the request 
continued. The relations between the objects look something like this:

	REQUEST	______	 NET	_______	SOCKET
	 OBJECT		OBJECT

but you can find a better description in the Library architecture document at

	http://www.w3.org/pub/WWW/Library/User/Architecture/Threads.html

Therefore, all the Library needs is some kind of event loop that can accept 
the registration requests of a socket and then call the event call back 
function when the socket is ready. The interface that the eventloop must be 
able to provide is exactly the same as the obne currently implemented by the 
event manager. You can find this in the source code of the Library in 
HTEvntrg.c or at

	http://www.w3.org/pub/WWW/Library/Implementation/HTEvntrg.html

> 
> > that file descriptor. Alternatively, and this is what I've done for the time
> > being, one can modify HTEvent_loop to return after some number of iterations
> > through the loop. The loop can be invoked at whatever frequency is needed, in
> > response to Xt timer or work-proc callbacks.

I think that the method above will result in a more integrated application 
with less glue code.


-- 

Henrik Frystyk Nielsen, <frystyk@w3.org>
World-Wide Web Consortium, MIT/LCS NE43-356
545 Technology Square, Cambridge MA 02139, USA

Received on Friday, 12 January 1996 12:32:00 UTC