Re: Rolling your own event handler

John Cwikla writes:
> -> 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:
> 	Actually this isn't what we want.  We don't want to have an event loop
> out of our control, or one isn't the event loop of our main app.  This forces
> the WWW loop to have control and to come up with some hack to solicit
> events (say from a GUI) or to respond to events.
> 	What we want is to be given a file descriptor, a flag, something, that
> the event loop in OUR program can then solicit and decide what to do.  We
> can't have some library, that is likely to be a module in a larger program
> controlling event dispatching...

That was what I thought I wrote :-) The "something" that you are requesting is 
a call from within the Library using the function HTEvent_register. This 
function is _as_an_example_ implemented in the internal eventloop 
(HTEvntrg.c), but you can take that module out (either by overloading the 
module with your own, or take it out of your project (if on Windows), or by 
changing the code directly, or using #ifdefs - you name it!).

All your event loop has to do is then to call the event call back function 
which is passed to you in the event register function:

extern int HTEvent_Register	(SOCKET,		/* Socket descriptor */
				HTRequest *,		/* Request object */
				SockOps,		/* Read, Write, etc */ 
				HTEventCallback *,	/* What to call */
				HTPriority);		/* How important */

which is the interface designed by Charlie Brooks. Here you have both the 
socket, the request object and what function to call.


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