Annotation of libwww/Library/src/HTEvent.html, revision 2.5
2.1 eric 1: <HTML>
2: <HEAD>
2.4 frystyk 3: <TITLE>W3C Reference Library libwww Event Class</TITLE>
2.1 eric 4: </HEAD>
5: <BODY>
2.4 frystyk 6: <H1>
7: The Event Class
2.3 frystyk 8: </H1>
2.1 eric 9: <PRE>
10: /*
11: ** (c) COPYRIGHT MIT 1995.
12: ** Please first read the full copyright statement in the file COPYRIGH.
13: */
2.4 frystyk 14: </PRE>
15: <P>
16: The Event Class defines any event manager to be used by libwww for handling
17: events. An <I>event</I> is not strictly defined as it is highly platform
18: dependent and hence out of scope for the Library. If you are using the libwww
19: pseudo threads on Unix then an event is when the <I>select()</I> system
20: call returns a notification on a socket descriptor, but it may as well
21: be an asynchronous event from the windows manager etc. If your application
22: is not using anything but traditional blocking sockets then you do not need
23: an event manager at all. In that case, libwww will block on any socket or
24: system call until the process can proceed.
25: <P>
26: The libwww interface to an event manager is very simple as it consists of
27: <B>registering</B> a <I>socket descriptor</I>, the <I>location</I> in the
28: program, and the <I>current state</I> when an operation (for example
29: <CODE>read</CODE>) would block. When the event manager at a later point in
30: time gets a notification that the socket has become ready, it can then call
31: libwww with the state saved from the registration and libwww can continue.
32: Second, libwww must be able to <B>unregister</B> a socket when it is not
33: anymore in a state where it can block. <I>Only</I> in case the application
34: wishes to use <I>non-blocking</I> sockets it should register methods for
35: handling the <B>registration</B> process as described below.
36: <P>
37: <B>Note</B>: The library <B>core</B> does <I>not</I> define any event manager
38: - it is considered part of the application. The library comes with a
39: <A HREF="HTEvntrg.html">default event manager</A> which can be initiated
2.5 ! eric 40: using the function
! 41: <CODE>HTEventInit()</CODE> in the
! 42: <A HREF="HTEvntrg.html">HTEvntrg module</A>.
2.4 frystyk 43: <P>
44: This module is implemented by <A HREF="HTEvent.c">HTEvent.c</A>, and it is
45: a part of the <A HREF="http://www.w3.org/pub/WWW/Library/">W3C Reference
46: Library</A>.
47: <PRE>
2.1 eric 48: #ifndef HTEVENT_H
49: #define HTEVENT_H
2.2 frystyk 50: #include "sysdep.h"
51:
2.4 frystyk 52: #define FD_NONE 0
53: #define FD_ALL (FD_READ | FD_WRITE | FD_OOB | FD_ACCEPT | FD_CONNECT |FD_CLOSE)
54: #define FD_UNREGISTER (((FD_ALL) << 1) & (~(FD_ALL)))
55:
2.2 frystyk 56: typedef enum _HTPriority {
57: HT_PRIORITY_INV = -1,
58: HT_PRIORITY_OFF = 0,
59: HT_PRIORITY_MIN = 1,
60: HT_PRIORITY_MAX = 20
61: } HTPriority;
62:
63: typedef u_long SockOps;
2.1 eric 64:
65: #include "HTReq.h"
66: </PRE>
2.3 frystyk 67: <H2>
68: Event Handlers
69: </H2>
70: <P>
2.4 frystyk 71: A <I>location</I> is a function that can be registered by the event manager
72: and called at a later point in time in order to continue an operation. All
73: locations must be of type <CODE>HTEventCallback</CODE> as defined here:
2.2 frystyk 74: <PRE>
75: typedef int HTEventCallback (SOCKET, HTRequest *, SockOps);
76: </PRE>
2.4 frystyk 77: <P>
78: There are many default event handlers provided with the Library. For example,
79: all the protocol modules such as the <A HREF="HTTP.html">HTTP client module</A>
80: are implemented as event handlers. In stead of using blocking sockets, this
81: allows a protocol module to register itself when performing an operation
82: that would block. When the sockets becomes ready the handler is called with
83: th socket in question, the request object, and the socket operation
2.3 frystyk 84: <H2>
2.4 frystyk 85: Registering and Unregistering Event Handlers
2.3 frystyk 86: </H2>
87: <P>
2.4 frystyk 88: As mentioned above, the only interface libwww requires from an event manager
89: is a method to <I>register</I> an event handler when an operation would block
90: and <I>unregister</I> it when the operation has completed The library registers
91: and unregisters event handlers by calling the following two functions:
92: <PRE>extern int HTEvent_register (SOCKET, HTRequest *,
93: SockOps, HTEventCallback *,
94: HTPriority);
95: extern int HTEvent_unregister (SOCKET, SockOps);
96: </PRE>
97: <P>
98: The register function contains information about which socket we are waiting
99: on to get ready and which operation we are waiting for (read, write, etc.),
100: the request object containing the current request, the event handler that
101: we want to be called when the socket becomes reasy, and finally the priority
102: by which we want the thread to be processed by the event manager. Likewise,
103: libwww can unregister a operation on a socket which means that libwww is
104: no longer waiting for this actiion to become ready.
105: <H2>
106: Registering an Event Manager
107: </H2>
108: <P>
109: The Library core does not contain any event manager as it depends on whether
110: you want to use pseudo threads no threads, or real threads. Instead, libwww
111: comes with a <A HREF="HTEvntrg.html">default implementation</A> that you
112: may register, but you may as well implement and register your own. The register
113: and unregister functions above actually does nothing than looking for a
114: registered event manager and then passes the call on to that. You register
115: your own event manager by using the methods below:
2.1 eric 116: <PRE>
117: typedef int HTEvent_registerCallback(SOCKET, HTRequest *,
118: SockOps, HTEventCallback *,
119: HTPriority);
120: typedef int HTEvent_unregisterCallback(SOCKET, SockOps);
121:
122: extern void HTEvent_setRegisterCallback(HTEvent_registerCallback *);
123: extern void HTEvent_setUnregisterCallback(HTEvent_unregisterCallback *);
124: </PRE>
2.3 frystyk 125: <P>
2.4 frystyk 126: You can register the event manager provided together with libwww by using
2.5 ! eric 127: <CODE>HTEventInit()</CODE> in the
! 128: <A HREF="HTEvntrg.html">HTEvntrg module</A>.
2.1 eric 129: <PRE>
130: #endif /* HTEVENT_H */
131: </PRE>
2.3 frystyk 132: <P>
133: <HR>
2.1 eric 134: <ADDRESS>
2.5 ! eric 135: @(#) $Id: HTEvent.html,v 2.4 1996/05/20 15:06:33 frystyk Exp $
2.1 eric 136: </ADDRESS>
2.3 frystyk 137: </BODY></HTML>
Webmaster