Annotation of libwww/Library/src/HTEvent.html, revision 2.10
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.6 frystyk 40: using the function <CODE>HTEventInit()</CODE> in <A HREF="HTInit.html">HTInit
41: module</A>
2.4 frystyk 42: <P>
43: This module is implemented by <A HREF="HTEvent.c">HTEvent.c</A>, and it is
44: a part of the <A HREF="http://www.w3.org/pub/WWW/Library/">W3C Reference
45: Library</A>.
46: <PRE>
2.1 eric 47: #ifndef HTEVENT_H
48: #define HTEVENT_H
2.2 frystyk 49: #include "sysdep.h"
50:
2.8 frystyk 51: #if 0
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)))
2.8 frystyk 55: #endif
2.4 frystyk 56:
2.2 frystyk 57: typedef enum _HTPriority {
58: HT_PRIORITY_INV = -1,
59: HT_PRIORITY_OFF = 0,
60: HT_PRIORITY_MIN = 1,
61: HT_PRIORITY_MAX = 20
62: } HTPriority;
63:
2.10 ! eric 64: #define HTEVENT_INDEX 0x10
2.8 frystyk 65: typedef enum {
2.9 eric 66: #ifdef WWW_WIN_ASYNC
2.10 ! eric 67: HTEvent_READ = (0x001 | 0 << HTEVENT_INDEX),
! 68: HTEvent_WRITE = (0x002 | 1 << HTEVENT_INDEX),
! 69: HTEvent_OOB = (0x004 | 2 << HTEVENT_INDEX),
! 70: HTEvent_ACCEPT = (0x008 | 3 << HTEVENT_INDEX),
! 71: HTEvent_CONNECT = (0x010 | 4 << HTEVENT_INDEX),
! 72: HTEvent_CLOSE = (0x020 | 5 << HTEVENT_INDEX),
2.9 eric 73: HTEvent_TYPES = 6, /* winsock has seperate events for all of these */
2.10 ! eric 74: #define HTEVENT_TYPES 6 /* use in constructing the fake event below */
2.9 eric 75: #else /* WWW_WIN_ASYNC */
2.10 ! eric 76: HTEvent_READ = (0x001 | 0 << HTEVENT_INDEX),
! 77: HTEvent_ACCEPT = (0x002 | 0 << HTEVENT_INDEX),
! 78: HTEvent_CLOSE = (0x004 | 0 << HTEVENT_INDEX),
! 79: HTEvent_WRITE = (0x008 | 1 << HTEVENT_INDEX),
! 80: HTEvent_CONNECT = (0x010 | 1 << HTEVENT_INDEX),
! 81: HTEvent_OOB = (0x020 | 2 << HTEVENT_INDEX),
2.9 eric 82: HTEvent_TYPES = 3, /* only READ, WRITE, and OOB are real types */
2.10 ! eric 83: #define HTEVENT_TYPES 3 /* use in constructing the fake event below */
2.9 eric 84: #endif /* !WWW_WIN_ASYNC */
2.10 ! eric 85: /*
! 86: ** fake events - these don't correspond to event manager events, but they
! 87: ** are usefull for communicating with the protocol modules
! 88: */
! 89: HTEvent_TIMEOUT = (0x040 | HTEVENT_TYPES << HTEVENT_INDEX),
! 90: HTEvent_BEGIN = (0x000 | HTEVENT_TYPES << HTEVENT_INDEX),
! 91: HTEvent_END = (0x080 | HTEVENT_TYPES << HTEVENT_INDEX),
! 92: HTEvent_FLUSH = (0x100 | HTEVENT_TYPES << HTEVENT_INDEX),
! 93: HTEvent_RESET = (0x200 | HTEVENT_TYPES << HTEVENT_INDEX),
2.9 eric 94: HTEvent_ALL = 0xFFFF
2.8 frystyk 95: } HTEventType;
2.1 eric 96:
2.8 frystyk 97: #define HTEvent_BITS(type) (type & 0xFFFF)
2.10 ! eric 98: #define HTEvent_INDEX(type) (type >> HTEVENT_INDEX)
2.8 frystyk 99:
100: /* Avoid circular include for HTReq->HTNet->HTHost: HTEvent blah */
101: typedef struct _HTEvent HTEvent;
2.1 eric 102: #include "HTReq.h"
103: </PRE>
2.3 frystyk 104: <H2>
2.7 eric 105: <A NAME="eventHandlers">Event Handlers</A>
2.3 frystyk 106: </H2>
107: <P>
2.4 frystyk 108: A <I>location</I> is a function that can be registered by the event manager
109: and called at a later point in time in order to continue an operation. All
110: locations must be of type <CODE>HTEventCallback</CODE> as defined here:
2.2 frystyk 111: <PRE>
2.8 frystyk 112: typedef int HTEventCallback (SOCKET, void *, HTEventType);
2.2 frystyk 113: </PRE>
2.4 frystyk 114: <P>
115: There are many default event handlers provided with the Library. For example,
116: all the protocol modules such as the <A HREF="HTTP.html">HTTP client module</A>
117: are implemented as event handlers. In stead of using blocking sockets, this
118: allows a protocol module to register itself when performing an operation
119: that would block. When the sockets becomes ready the handler is called with
120: th socket in question, the request object, and the socket operation
2.3 frystyk 121: <H2>
2.4 frystyk 122: Registering and Unregistering Event Handlers
2.3 frystyk 123: </H2>
124: <P>
2.4 frystyk 125: As mentioned above, the only interface libwww requires from an event manager
126: is a method to <I>register</I> an event handler when an operation would block
127: and <I>unregister</I> it when the operation has completed The library registers
128: and unregisters event handlers by calling the following two functions:
2.8 frystyk 129: <PRE>
130: extern int HTEvent_register (SOCKET, HTEventType, HTEvent *);
131: extern int HTEvent_unregister (SOCKET, HTEventType);
2.4 frystyk 132: </PRE>
133: <P>
134: The register function contains information about which socket we are waiting
135: on to get ready and which operation we are waiting for (read, write, etc.),
136: the request object containing the current request, the event handler that
137: we want to be called when the socket becomes reasy, and finally the priority
138: by which we want the thread to be processed by the event manager. Likewise,
139: libwww can unregister a operation on a socket which means that libwww is
140: no longer waiting for this actiion to become ready.
141: <H2>
142: Registering an Event Manager
143: </H2>
144: <P>
145: The Library core does not contain any event manager as it depends on whether
146: you want to use pseudo threads no threads, or real threads. Instead, libwww
147: comes with a <A HREF="HTEvntrg.html">default implementation</A> that you
148: may register, but you may as well implement and register your own. The register
149: and unregister functions above actually does nothing than looking for a
150: registered event manager and then passes the call on to that. You register
151: your own event manager by using the methods below:
2.1 eric 152: <PRE>
2.8 frystyk 153: struct _HTEvent {
154: HTPriority priority; /* Priority of this request (event) */
155: int millis; /* Timeout in ms for this event */
156: HTEventCallback * cbf; /* Protocol state machine */
157: void * param; /* HTEvent_register parameter */
158: HTRequest * request;
159: };
160:
161: typedef int HTEvent_registerCallback(SOCKET, HTEventType, HTEvent *);
162: typedef int HTEvent_unregisterCallback(SOCKET, HTEventType);
2.1 eric 163:
164: extern void HTEvent_setRegisterCallback(HTEvent_registerCallback *);
165: extern void HTEvent_setUnregisterCallback(HTEvent_unregisterCallback *);
2.8 frystyk 166: extern BOOL HTEvent_setCallback(HTEvent * event, HTEventCallback * cbf);
167:
168: extern HTEvent * HTEvent_new (HTEventCallback * cbf, void * context,
169: HTPriority pritority, int timeoutInMillis);
170: extern BOOL HTEvent_delete (HTEvent * event);
171:
172: extern BOOL HTEvent_setParam(HTEvent * event, void * param);
173: extern BOOL HTEvent_setPriority(HTEvent * event, HTPriority priority);
174: extern BOOL HTEvent_setTimeout(HTEvent * event, int timeoutInMillis);
2.1 eric 175: </PRE>
2.3 frystyk 176: <P>
2.4 frystyk 177: You can register the event manager provided together with libwww by using
2.6 frystyk 178: the <CODE>HTEventInit()</CODE> in the <A HREF="HTInit.html">HTInit module</A>
2.1 eric 179: <PRE>
180: #endif /* HTEVENT_H */
181: </PRE>
2.3 frystyk 182: <P>
183: <HR>
2.1 eric 184: <ADDRESS>
2.10 ! eric 185: @(#) $Id: HTEvent.html,v 2.9 1996/12/05 23:19:56 eric Exp $
2.1 eric 186: </ADDRESS>
2.3 frystyk 187: </BODY></HTML>
Webmaster