Annotation of libwww/Library/src/HTNet.html, revision 2.35

2.1       frystyk     1: <HTML>
                      2: <HEAD>
2.32      frystyk     3: <TITLE>W3C Reference Library libwww NET OBJECT</TITLE>
2.35    ! frystyk     4: <!-- Changed by: Henrik Frystyk Nielsen, 13-Apr-1996 -->
2.1       frystyk     5: </HEAD>
                      6: <BODY>
2.2       frystyk     7: 
2.17      frystyk     8: <H1>Asyncronous Socket Management</H1>
2.1       frystyk     9: 
2.5       frystyk    10: <PRE>
                     11: /*
2.8       frystyk    12: **     (c) COPYRIGHT MIT 1995.
2.5       frystyk    13: **     Please first read the full copyright statement in the file COPYRIGH.
                     14: */
                     15: </PRE>
                     16: 
2.1       frystyk    17: This module contains the routines for handling the set of active
2.2       frystyk    18: sockets currently in use by the multithreaded clients. It is an
                     19: internal module to the Library, the application interface is
2.15      frystyk    20: implemented in the <A HREF="HTEvntrg.html">Event Module</A>. Look for
2.2       frystyk    21: more information in the <A
2.17      frystyk    22: HREF="http://www.w3.org/pub/WWW/Library/User/Architecture/">
2.2       frystyk    23: Multithread Specifications</A>. <P>
2.1       frystyk    24: 
2.17      frystyk    25: This module is implemented by <A HREF="HTNet.c">HTNet.c</A>, and it is
                     26: a part of the <A HREF="http://www.w3.org/pub/WWW/Library/">W3C
                     27: Reference Library</A>.
2.1       frystyk    28: 
                     29: <PRE>
2.17      frystyk    30: #ifndef HTNET_H
                     31: #define HTNET_H
2.1       frystyk    32: </PRE>
                     33: 
2.17      frystyk    34: <H2>The HTNet Object</H2>
2.1       frystyk    35: 
2.17      frystyk    36: The <CODE>HTNet</CODE> object is the core of the request queue
                     37: management. This object contains information about the socket
                     38: descriptor, the input read buffer etc. required to identify and
                     39: service a request. <P>
2.1       frystyk    40: 
                     41: <PRE>
2.18      frystyk    42: typedef struct _HTNet HTNet;
2.34      frystyk    43: 
                     44: #include "HTEvntrg.h"
                     45: #include "HTReq.h"
                     46: #include "HTTrans.h"
                     47: #include "HTHost.h"
                     48: #include "HTChannl.h"
                     49: #include "HTDNS.h"
2.1       frystyk    50: </PRE>
                     51: 
2.24      frystyk    52: <H2>Request Call Back Functions</H2>
2.17      frystyk    53: 
2.24      frystyk    54: Callback functions can be registered to be called <EM>before</EM> and
                     55: <EM>after</EM> a request has either been started or has
                     56: terminated. The following functions are the generic registration
                     57: mechanisms where we use lists as the basic data container. Then there
                     58: is two methods for binding a list of callback functions to the set
                     59: which is called <EM>before</EM> and to the set set which is called
                     60: <EM>after</EM> <P>
                     61: 
                     62: In both cases there can be more than one callback function which are
2.17      frystyk    63: called on turn and each callback function can be associated with a
                     64: status code of the request. For example one callback function can be
                     65: registered for HT_LOADED, another for HT_ERROR etc.
                     66: 
                     67: <H3>Register a Request Callback</H3>
2.2       frystyk    68: 
2.17      frystyk    69: Register a call back function that is to be called on every
                     70: termination of a request. Several call back functions can be
                     71: registered in which case all of them are called in the reverse order
2.24      frystyk    72: of which they were registered (last one first). We name the calling
                     73: mechansm of calling the functions for the <EM>before</EM> loop and the
                     74: <EM>after</EM> loop.<P>
                     75: 
                     76: In case the callback function is registered as being called
                     77: <EM>after</EM> the request has terminated the result of the request is
                     78: passed to the fucntion. The status signifies which call back function
                     79: to call depending of the result of the request. This can be
2.1       frystyk    80: 
2.17      frystyk    81: <DL>
                     82: <DT>HT_ERROR
                     83: <DD>An error occured
                     84: <DT>HT_LOADED
                     85: <DD>The document was loaded
                     86: <DT>HT_NO_DATA
                     87: <DD>OK, but no data
                     88: <DT>HT_RETRY
                     89: <DD>Retry request after at a later time
2.24      frystyk    90: <DT>HT_REDIRECT
                     91: <DD>The request has been redirected and we send back the new URL
2.17      frystyk    92: <DT>HT_ALL
                     93: <DD>All of above
                     94: </DL>
2.1       frystyk    95: 
2.24      frystyk    96: Any callback function any code it likes, but <B>IF NOT</B> the code is
                     97: <EM>HT_OK</EM>, then the callback loop is stopped. If we are in the
                     98: <EM>before</EM> loop and a function returns anything else than
                     99: <EM>HT_OK</EM> then we immediately jump to the <EM>after</EM> loop
                    100: <B>passing</B> the last return code from the <EM>before</EM> loop.
                    101: 
2.1       frystyk   102: <PRE>
2.35    ! frystyk   103: typedef int HTNetCallback (HTRequest * request, void * param, int status);
2.17      frystyk   104: 
2.35    ! frystyk   105: extern BOOL HTNetCall_add (HTList * list, HTNetCallback *cbf,
        !           106:                          void * param, int status);
2.9       frystyk   107: </PRE>
                    108: 
2.24      frystyk   109: <H3>Delete a single Callbak</H3>
2.9       frystyk   110: 
2.24      frystyk   111: Removes a callback function from a list
2.9       frystyk   112: 
                    113: <PRE>
2.24      frystyk   114: extern BOOL HTNetCall_delete (HTList * list, HTNetCallback *cbf);
2.1       frystyk   115: </PRE>
                    116: 
2.24      frystyk   117: <H3>Delete a list of Callbacks</H3>
                    118: 
                    119: Unregisters all call back functions in the list
                    120: 
                    121: <PRE>
                    122: extern BOOL HTNetCall_deleteAll (HTList * list);
                    123: </PRE>
                    124: 
                    125: <H3>Call List of Registered Callback Functions</H3>
2.10      frystyk   126: 
2.17      frystyk   127: Call all the call back functions registered in the list IF not the
2.24      frystyk   128: status is HT_IGNORE.  The callback functions are called in the order
                    129: of which they were registered. At the moment an application callback
                    130: function is called, it can free the request object - it is no longer
                    131: used by the Library. Returns what the last callback function returns
                    132: 
                    133: <PRE>
                    134: extern int HTNetCall_execute (HTList * list, HTRequest * request, int status);
                    135: </PRE>
                    136: 
                    137: <H3>BEFORE Callbacks</H3>
                    138: 
                    139: Global set of callback functions BEFORE the request is issued. The
                    140: list can be NULL.
                    141: 
                    142: <PRE>
2.35    ! frystyk   143: extern BOOL HTNetCall_addBefore        (HTNetCallback *cbf, void * param, int status);
2.24      frystyk   144: extern BOOL HTNet_setBefore    (HTList * list);
                    145: extern HTList * HTNet_before   (void);
                    146: extern int HTNet_callBefore    (HTRequest *request, int status);
                    147: </PRE>
                    148: 
                    149: <H3>AFTER Callbacks</H3>
                    150: 
                    151: Global set of callback functions AFTER the request is issued. The list can be NULL
2.10      frystyk   152: 
                    153: <PRE>
2.35    ! frystyk   154: extern BOOL HTNetCall_addAfter (HTNetCallback *cbf, void * param, int status);
2.24      frystyk   155: extern BOOL HTNet_setAfter     (HTList * list);
                    156: extern HTList * HTNet_after    (void);
                    157: extern int HTNet_callAfter     (HTRequest *request, int status);
2.10      frystyk   158: </PRE>
                    159: 
2.17      frystyk   160: <H2>Request Queue</H2>
                    161: 
                    162: The request queue ensures that no more than a fixed number of TCP
                    163: connections are open at the same time. If more requests are handed to
                    164: the Library, they are put into the pending queue and initiated when
                    165: sockets become free.
                    166: 
                    167: <H3>Number of Simultanous open TCP connections</H3>
2.1       frystyk   168: 
2.17      frystyk   169: Set the max number of simultanous sockets. The default value is
2.19      frystyk   170: HT_MAX_SOCKETS which is 6. The number of persistent connections depend
                    171: on this value as a deadlock can occur if all available sockets a
                    172: persistent (see the <A HREF="HTDNS.html">DNS Manager</A> for more
                    173: information on setting the number of persistent connections). The
                    174: number of persistent connections can never be more than the max number
                    175: of sockets-2, so letting newmax=2 prevents persistent sockets.
2.1       frystyk   176: 
                    177: <PRE>
2.17      frystyk   178: extern BOOL HTNet_setMaxSocket (int newmax);
                    179: extern int  HTNet_maxSocket (void);
2.1       frystyk   180: </PRE>
                    181: 
2.23      frystyk   182: <H3>List Active Queue</H3>
2.1       frystyk   183: 
2.17      frystyk   184: Returns the list of active requests that are currently having an open
2.22      frystyk   185: connection. Returns list of HTNet objects or NULL if
2.29      frystyk   186: error. 
2.1       frystyk   187: 
                    188: <PRE>
2.17      frystyk   189: extern HTList *HTNet_activeQueue (void);
2.22      frystyk   190: extern BOOL HTNet_idle (void);
2.29      frystyk   191: </PRE>
                    192: 
                    193: <H3>Are we Active?</H3>
                    194: 
                    195: We have some small functions that tell whether there are registered
                    196: requests in the Net manager. There are tree queues: The
                    197: <EM>active</EM>, the <EM>pending</EM>, and the
                    198: <EM>persistent</EM>. The <EM>active</EM> queue is the set of requests
                    199: that are actively sending or receiving data. The <EM>pending</EM> is
                    200: the requests that we have registered but which are waiting for a free
                    201: socket. The <EM>Persistent</EM> queue are requets that are waiting to
                    202: use the same socket in order to save network resoures (if the server
                    203: understands persistent connections). <P>
                    204: 
                    205: <H4>Active Reqeusts?</H4>
                    206: 
                    207: Returns whether there are requests in the <EM>active</EM> queue or not
                    208: 
                    209: <PRE>
                    210: extern BOOL HTNet_idle (void);
                    211: </PRE>
                    212: 
                    213: <H4>Registered Requests?</H4>
                    214: 
                    215: Returns whether there are requests registered in any of the lists or
                    216: not
                    217: 
                    218: <PRE>
                    219: extern BOOL HTNet_isEmpty (void);
2.1       frystyk   220: </PRE>
2.17      frystyk   221: 
2.23      frystyk   222: <H3>List Pending Queue</H3>
2.17      frystyk   223: 
                    224: Returns the list of pending requests that are waiting to become
                    225: active. Returns list of HTNet objects or NULL if error
                    226: 
2.1       frystyk   227: <PRE>
2.17      frystyk   228: extern HTList *HTNet_pendingQueue (void);
2.1       frystyk   229: </PRE>
                    230: 
2.27      frystyk   231: <H2>Create an Object</H2>
2.17      frystyk   232: 
2.27      frystyk   233: You can create a new HTNet object as a new request to be handled. If
2.28      frystyk   234: we have more than HTMaxActive connections already then put this into
                    235: the pending queue, else start the request by calling the call back
                    236: function registered with this access method.  Returns YES if OK, else
                    237: NO
2.17      frystyk   238: 
2.27      frystyk   239: <PRE>
2.28      frystyk   240: extern BOOL HTNet_newClient (HTRequest * request);
2.27      frystyk   241: </PRE>
2.17      frystyk   242: 
2.27      frystyk   243: You can create a new HTNet object as a new request to be handled. If
2.28      frystyk   244: we have more than HTMaxActive connections already then return NO.
                    245: Returns YES if OK, else NO
2.17      frystyk   246: 
                    247: <PRE>
2.31      frystyk   248: extern BOOL HTNet_newServer (HTRequest * request, SOCKET sockfd, char *access);
2.26      frystyk   249: </PRE>
                    250: 
2.27      frystyk   251: And you can create a plain new HTNet object using the following method:
2.26      frystyk   252: 
                    253: <PRE>
2.27      frystyk   254: extern HTNet * HTNet_new (HTRequest * request, SOCKET sockfd);
2.20      frystyk   255: </PRE>
                    256: 
                    257: <H3>Duplicate an Existing Object</H3>
                    258: 
                    259: Creates a new HTNet object as a duplicate of the same request.
                    260: Returns YES if OK, else NO.
                    261: 
                    262: <PRE>
2.30      frystyk   263: extern HTNet * HTNet_dup (HTNet * src);
2.17      frystyk   264: </PRE>
2.27      frystyk   265: 
                    266: <H2>HTNet Object Methods</H2>
2.17      frystyk   267: 
2.23      frystyk   268: <H3>Make an Object Wait</H3>
2.19      frystyk   269: 
                    270: Let a net object wait for a persistent socket. It will be launched
                    271: from the HTNet_delete() function when the socket gets free.
                    272: 
                    273: <PRE>
                    274: extern BOOL HTNet_wait (HTNet *net);
                    275: </PRE>
                    276: 
2.23      frystyk   277: <H3>Priority Management</H3>
                    278: 
                    279: Each HTNet object is created with a priority which it inherits from
                    280: the <A HREF="HTReq.html">Request manager</A>. However, in some
                    281: stuations it is useful to be to change the current priority after the
                    282: request has been started. These two functions allow you to do
                    283: this. The effect will show up the first time (which might be
                    284: imidiately) the socket blocks and control returns to the event loop.
                    285: Also have a look at how you can do this before the request is issued
                    286: in the <A HREF="HTReq.html">request manager</A>.
                    287: 
                    288: <PRE>
                    289: extern HTPriority HTNet_priority (HTNet * net);
                    290: extern BOOL HTNet_setPriority (HTNet * net, HTPriority priority);
                    291: </PRE>
                    292: 
2.33      frystyk   293: <H3>Persistent Connections</H3>
                    294: 
                    295: You can set a Net object to handle persistent connections for example
                    296: using HTTP, NNTP, or FTP. You can control whether a Net object
                    297: supports persistent connections or not using this function.
                    298: 
                    299: <PRE>
                    300: extern BOOL HTNet_persistent (HTNet * net);
                    301: </PRE>
                    302: 
                    303: You can set or disable a Net object supporting persistent connections
                    304: using this function:
                    305: 
                    306: <PRE>
                    307: extern BOOL HTNet_setPersistent (HTNet * net, BOOL persistent);
                    308: </PRE>
                    309: 
2.17      frystyk   310: <H3>Delete an Object</H3>
                    311: 
                    312: Deletes the HTNet object from the list of active requests and calls
                    313: any registered call back functions IF not the status is HT_IGNORE.
                    314: This is used if we have internal requests that the app doesn't know
                    315: about. We also see if we have pending requests that can be started up
                    316: now when we have a socket free. The callback functions are called in
2.24      frystyk   317: the reverse order of which they were registered (last one first);
2.1       frystyk   318: 
                    319: <PRE>
2.17      frystyk   320: extern BOOL HTNet_delete (HTNet * me, int status);
2.1       frystyk   321: </PRE>
                    322: 
2.17      frystyk   323: <H3>Delete ALL HTNet Objects</H3>
2.1       frystyk   324: 
2.17      frystyk   325: Deletes all HTNet object that might either be active or pending We DO
2.19      frystyk   326: NOT call the call back functions - A crude way of saying goodbye!
2.1       frystyk   327: 
                    328: <PRE>
2.17      frystyk   329: extern BOOL HTNet_deleteAll (void);
2.1       frystyk   330: </PRE>
2.17      frystyk   331: 
                    332: <H3>Kill a Request</H3>
2.1       frystyk   333: 
2.17      frystyk   334: Kill the request by calling the call back function with a request for
                    335: closing the connection. Does not remove the object. This is done by
                    336: HTNet_delete() function which is called by the load routine.  Returns
                    337: OK if success, NO on error
2.1       frystyk   338: 
                    339: <PRE>
2.17      frystyk   340: extern BOOL HTNet_kill (HTNet * me);
2.1       frystyk   341: </PRE>
                    342: 
2.17      frystyk   343: <H3>Kill ALL requests</H3>
2.1       frystyk   344: 
2.17      frystyk   345: Kills all registered (active+pending) requests by calling the call
                    346: back function with a request for closing the connection. We do not
                    347: remove the HTNet object as it is done by HTNet_delete().  Returns OK
                    348: if success, NO on error
2.1       frystyk   349: 
                    350: <PRE>
2.17      frystyk   351: extern BOOL HTNet_killAll (void);
2.28      frystyk   352: </PRE>
                    353: 
2.34      frystyk   354: <H3>Create Input and Output Streams</H3>
                    355: 
                    356: You create the input stream and bind it to the channel using the
                    357: following methods. Please read the description in the <A
                    358: HREF="HTIOStream.html">HTIOStream module</A> on the parameters
                    359: <EM>target</EM>, <EM>param</EM>, and <EM>mode</EM>. Both methods
                    360: return YES if OK, else NO.
                    361: 
                    362: <PRE>
                    363: extern HTInputStream * HTNet_getInput (HTNet * net, HTStream * target,
                    364:                                       void * param, int mode);
                    365: 
                    366: extern HTOutputStream * HTNet_getOutput (HTNet * net, void * param, int mode);
                    367: </PRE>
                    368: 
2.28      frystyk   369: <H2>Data Access Methods</H2>
                    370: 
2.34      frystyk   371: We have some methods for accessing the internals of the Net object
                    372: 
2.28      frystyk   373: <H3>Socket Descriptor</H3>
                    374: 
                    375: <PRE>
                    376: extern BOOL HTNet_setSocket (HTNet * net, SOCKET sockfd);
                    377: extern SOCKET HTNet_socket (HTNet * net);
2.17      frystyk   378: </PRE>
2.1       frystyk   379: 
2.34      frystyk   380: <H3>The Transport Object</H3>
                    381: 
                    382: The <A HREF="HTTransport.html">transport object</A> is normally set up
                    383: automatically but can be changed at a later time.
                    384: 
2.17      frystyk   385: <PRE>
2.34      frystyk   386: extern BOOL HTNet_setTransport (HTNet * net, HTTransport * tp);
                    387: extern HTTransport * HTNet_transport (HTNet * net);
                    388: </PRE>
                    389: 
                    390: <H3>The Channel Object</H3>
                    391: 
                    392: <PRE>
                    393: extern BOOL HTNet_setChannel (HTNet * net, HTChannel * channel);
                    394: extern HTChannel * HTNet_channel (HTNet * net);
                    395: </PRE>
                    396: 
                    397: <H3>The Host Object</H3>
                    398: 
                    399: <PRE>
                    400: extern BOOL HTNet_setHost (HTNet * net, HTHost * host);
                    401: extern HTHost * HTNet_host (HTNet * net);
                    402: </PRE>
                    403: 
                    404: <H3>The DNS Object</H3>
                    405: 
                    406: <PRE>
                    407: extern BOOL HTNet_setDns (HTNet * net, HTdns * dns);
                    408: extern HTdns * HTNet_dns (HTNet * net);
                    409: </PRE>
                    410: 
                    411: <PRE>
2.17      frystyk   412: #endif /* HTNET_H */
2.1       frystyk   413: </PRE>
                    414: 
2.34      frystyk   415: <HR>
                    416: <ADDRESS>
2.35    ! frystyk   417: @(#) $Id: HTNet.html,v 2.34 1996/04/12 17:48:11 frystyk Exp $
2.34      frystyk   418: </ADDRESS>
2.1       frystyk   419: </BODY>
                    420: </HTML>

Webmaster