Annotation of libwww/Library/src/HTHost.html, revision 2.22

2.1       frystyk     1: <HTML>
                      2: <HEAD>
2.4       frystyk     3:   <!-- Changed by: Henrik Frystyk Nielsen,  2-Jul-1996 -->
2.14      frystyk     4:   <TITLE>W3C Sample Code Library libwww Host Class</TITLE>
2.1       frystyk     5: </HEAD>
                      6: <BODY>
2.3       frystyk     7: <H1>
                      8:   The Host Class
                      9: </H1>
2.1       frystyk    10: <PRE>
                     11: /*
                     12: **     (c) COPYRIGHT MIT 1995.
                     13: **     Please first read the full copyright statement in the file COPYRIGH.
                     14: */
                     15: </PRE>
2.3       frystyk    16: <P>
                     17: The Host class manages what we know about a remote host. This can for example
                     18: be what type of host it is, and what version it is using. Notice that a host
                     19: object can be used to describe both a server or a client - all information
                     20: in the Host object can be shared regardless of whether it is to be used in
                     21: a server application or a client application.
                     22: <P>
                     23: This module is implemented by <A HREF="HTHost.c">HTHost.c</A>, and it is
2.21      frystyk    24: a part of the <A HREF="http://www.w3.org/Library/"> W3C Sample Code
2.3       frystyk    25: Library</A>.
2.1       frystyk    26: <PRE>
                     27: #ifndef HTHOST_H
                     28: #define HTHOST_H
                     29: 
                     30: typedef struct _HTHost HTHost;
2.8       frystyk    31: #define HOST_HASH_SIZE         67
2.1       frystyk    32: 
                     33: #include "HTChannl.h"
                     34: #include "HTReq.h"
2.2       frystyk    35: #include "HTEvent.h"
2.8       frystyk    36: #include "HTProt.h"
2.15      frystyk    37: #include "HTTimer.h"
2.1       frystyk    38: </PRE>
2.3       frystyk    39: <P>
                     40: The Host class contains information about the remote host, for example the
                     41: type (HTTP/1.0, HTTP/1.1, FTP etc.) along with information on how the connections
                     42: can be used (if it supports persistent connections, interleaved access etc.)
                     43: <H2>
                     44:   Creation and Deletion Methods
                     45: </H2>
                     46: <P>
                     47: We keep a cache of information that we know about a remote host. This allows
2.5       frystyk    48: us to be much more detailed in generating requests. Search the host info
                     49: cache for a host object or create a new one and add it. Examples of host
                     50: names are
2.1       frystyk    51: <UL>
2.3       frystyk    52:   <LI>
                     53:     www.w3.org
                     54:   <LI>
                     55:     www.foo.com:8000
2.1       frystyk    56: </UL>
2.3       frystyk    57: <H3>
                     58:   Add a Host Object
                     59: </H3>
2.1       frystyk    60: <PRE>
2.10      eric       61: extern HTHost * HTHost_new (char * host, u_short u_port);
                     62: extern HTHost * HTHost_newWParse(HTRequest * request, char * url, u_short u_port);
2.8       frystyk    63: extern int HTHost_hash (HTHost * host);
2.1       frystyk    64: </PRE>
2.3       frystyk    65: <H3>
                     66:   Delete a Host Object
                     67: </H3>
                     68: <P>
                     69: The Host Class contains an automatic garbage collection of Host objects so
                     70: that we don't keep information around that is stale.
2.6       frystyk    71: <H3>
                     72:   Find a Host Object
                     73: </H3>
                     74: <P>
                     75: Searches the cache of known hosts to see if we already have information about
                     76: this host. If not then we return NULL.
                     77: <PRE>extern HTHost * HTHost_find (char * host);
                     78: </PRE>
2.3       frystyk    79: <H2>
2.12      frystyk    80:   Remote Host Information
2.3       frystyk    81: </H2>
                     82: <P>
2.12      frystyk    83: We keep track of the capabilities of the host in the other end so thatwe
                     84: may adjust our queries to fit it better
2.3       frystyk    85: <H3>
2.5       frystyk    86:   Remote Host Name
                     87: </H3>
                     88: <P>
                     89: Get the name of the remote host. This is set automatically when a new Host
                     90: object and can be asked for at any point in time. You can not change the
                     91: host name but must create a new Host object instead.
                     92: <PRE>
                     93: extern char * HTHost_name      (HTHost * host);
                     94: </PRE>
                     95: <H3>
                     96:   Remote Host Protocol Class and Version
2.3       frystyk    97: </H3>
                     98: <P>
                     99: Define the <EM>host class</EM> of the host at the other end. A class is a
                    100: generic description of the protocol which is exactly like the access method
                    101: in a URL, for example "http" etc. The <EM>host version</EM> is a finer
                    102: distinction (sub-class) between various versions of the host class, for example
                    103: HTTP/0.9, HTTP/1.1 etc. The host version is a bit flag that the protocol
                    104: module can define on its own. That way we don't have to change this module
                    105: when registering a new protocol module. The <EM>host type</EM> is a description
                    106: of whether we can keep the connection persistent or not.
2.1       frystyk   107: <PRE>
                    108: extern char * HTHost_class     (HTHost * host);
                    109: extern void HTHost_setClass    (HTHost * host, char * s_class);
                    110: 
                    111: extern int  HTHost_version     (HTHost * host);
                    112: extern void HTHost_setVersion  (HTHost * host, int version);
                    113: </PRE>
2.3       frystyk   114: <H3>
2.12      frystyk   115:   Public Methods accessible on This Host
2.4       frystyk   116: </H3>
                    117: <P>
                    118: A server can inform a client about the supported methods using the
                    119: <CODE>Public</CODE> header.
                    120: <PRE>extern HTMethod HTHost_publicMethods      (HTHost * me);
                    121: extern void HTHost_setPublicMethods    (HTHost * me, HTMethod methodset);
                    122: extern void HTHost_appendPublicMethods (HTHost * me, HTMethod methodset);
                    123: </PRE>
2.12      frystyk   124: <H3>
2.4       frystyk   125:   Server Name of Remote Host
2.12      frystyk   126: </H3>
2.4       frystyk   127: <P>
                    128: A server can send its server application name and version in a HTTP response.
                    129: We pick up this information and add it to the Host object
                    130: <PRE>extern char * HTHost_server       (HTHost * host);
                    131: extern BOOL HTHost_setServer   (HTHost * host, const char * server);
                    132: </PRE>
2.12      frystyk   133: <H3>
2.4       frystyk   134:   User Agent Name of Remote Host
2.12      frystyk   135: </H3>
2.4       frystyk   136: <P>
                    137: A client can send the name of the client application in a HTTP request. We
2.5       frystyk   138: pick up this information and add it to the Host Object
2.4       frystyk   139: <PRE>extern char * HTHost_userAgent    (HTHost * host);
                    140: extern BOOL HTHost_setUserAgent        (HTHost * host, const char * userAgent);
                    141: </PRE>
2.12      frystyk   142: <H3>
2.7       frystyk   143:   Range Units Accepted by this Host
2.12      frystyk   144: </H3>
2.7       frystyk   145: <P>
                    146: Since all HTTP entities are represented in HTTP messages as sequences of
                    147: bytes, the concept of a byte range is meaningful for any HTTP entity. (However,
                    148: not all clients and servers need to support byte-range operations.) Byte
                    149: range specifications in HTTP apply to the sequence of bytes in the entity-body
                    150: (not necessarily the same as the message-body). A byte range operation may
                    151: specify a single range of bytes, or a set of ranges within a single entity.
                    152: <P>
                    153: You can also check whether a specific range unit is OK. We always say
                    154: <CODE>YES</CODE> except if we have a specific statement from the server that
                    155: it doesn't understand byte ranges - that is - it has sent "none" in a
                    156: "Accept-Range" response header
                    157: <PRE>
                    158: extern char * HTHost_rangeUnits  (HTHost * host);
                    159: extern BOOL HTHost_setRangeUnits (HTHost * host, const char * units);
                    160: extern BOOL HTHost_isRangeUnitAcceptable (HTHost * host, const char * unit);
                    161: </PRE>
2.18      frystyk   162: 
2.19      kahan     163: 
2.18      frystyk   164: <H3>
2.19      kahan     165: User Defined Contexts
2.18      frystyk   166: </H3>
2.19      kahan     167:      
2.18      frystyk   168: This can be used for anything that the application would like to keep tabs on.
2.19      kahan     169:     
2.18      frystyk   170: <PRE>
                    171: extern void HTHost_setContext (HTHost * me, void * context);
                    172: extern void * HTHost_context  (HTHost * me);
                    173: </PRE>
                    174: 
2.12      frystyk   175: <H2>
                    176:   Persistent Connections
                    177: </H2>
2.3       frystyk   178: <P>
                    179: We don't want more than MaxSockets-2 connections to be persistent in order
                    180: to avoid deadlock.
2.1       frystyk   181: <PRE>
2.19      kahan     182: extern int HTHost_catchClose (SOCKET soc, void * context, HTEventType type);
2.8       frystyk   183: extern BOOL HTHost_setPersistent (HTHost * host, BOOL persistent,
                    184:                                   HTTransportMode mode);
2.5       frystyk   185: extern BOOL HTHost_clearChannel (HTHost * host, int status);
2.1       frystyk   186: 
                    187: extern HTChannel * HTHost_channel (HTHost * host);
                    188: </PRE>
2.3       frystyk   189: <H3>
                    190:   Is this host Persistent?
                    191: </H3>
                    192: <P>
2.1       frystyk   193: Check whether we have a persistent channel or not
                    194: <PRE>
                    195: extern BOOL HTHost_isPersistent (HTHost * host);
2.15      frystyk   196: extern BOOL HTHost_setCloseNotification (HTHost * host, BOOL mode);
                    197: extern BOOL HTHost_closeNotification (HTHost * host);
2.1       frystyk   198: </PRE>
2.3       frystyk   199: <H3>
                    200:   Timing Persistent Channels
                    201: </H3>
                    202: <P>
                    203: Normally we wait for the peer process to close persistent connections but
                    204: in order not to use up our own resources, we have a timeout on our own. The
                    205: default value is 1 hour, but you can modify the value using the following
                    206: methods:
2.1       frystyk   207: <PRE>
                    208: extern time_t HTHost_persistTimeout (time_t timeout);
                    209: extern void HTHost_setPersistTimeout (time_t timeout);
                    210: </PRE>
2.3       frystyk   211: <P>
                    212: Each persistent connection has an absolute value of when this connection
                    213: most likely will expire. If the peer process does not inform us, we use our
                    214: own timeout.
2.1       frystyk   215: <PRE>
                    216: extern void HTHost_setPersistExpires (HTHost * host, time_t expires);
                    217: extern time_t HTHost_persistExpires (HTHost * host);
2.11      eric      218: extern void HTHost_setReqsPerConnection (HTHost * host, int reqs);
                    219: extern int HTHost_reqsPerConnection (HTHost * host);
                    220: extern void HTHost_setReqsMade (HTHost * host, int reqs);
                    221: extern int HTHost_reqsMade (HTHost * host);
2.1       frystyk   222: </PRE>
2.5       frystyk   223: <H2>
2.12      frystyk   224:   Transport Mode
                    225: </H2>
                    226: <P>
                    227: Handle the connection mode. The mode may change mode in the middle of a
                    228: connection If the new mode is lower than the old mode then adjust the pipeline
                    229: accordingly. That is, if we are going into single mode then move all entries
                    230: in the pipeline and move the rest to the pending queue. They will get launched
                    231: at a later point in time.
                    232: <PRE>extern HTTransportMode HTHost_mode (HTHost * host, BOOL * active);
                    233: extern BOOL HTHost_setMode (HTHost * host, HTTransportMode mode);
                    234: </PRE>
                    235: <H2>
2.5       frystyk   236:   Queuing Requests
                    237: </H2>
                    238: <P>
                    239: Requests are queued in the Host object until we have resources to start them.
                    240: The request is in the form of a Net object as we may have multiple socket
                    241: requests per <A HREF="HTReq.html">Request object</A>. This is for example
                    242: the case with <A HREF="WWWFTp.html">FTP</A> which uses two connections.
                    243: <PRE>extern int HTHost_addNet     (HTHost * host, HTNet * net);
2.8       frystyk   244: extern BOOL HTHost_free      (HTHost * host, int status);
2.5       frystyk   245: extern BOOL HTHost_deleteNet (HTHost * host, HTNet * net);
                    246: extern HTList * HTHost_net   (HTHost * host);
                    247: </PRE>
                    248: <H3>
2.12      frystyk   249:   Is the Host Idle?
2.5       frystyk   250: </H3>
                    251: <P>
                    252: Before we can start a new connection to the host we must be sure that the
                    253: host is idle. That is, if it can accept a new connection. We have several
                    254: modes describing how and when a host is idle. This is a function of the
                    255: <A HREF="HTTrans.html">Transport Object</A>
                    256: <PRE>extern BOOL HTHost_isIdle (HTHost * host);
                    257: </PRE>
2.3       frystyk   258: <H3>
2.5       frystyk   259:   Handling Pending Requests
2.3       frystyk   260: </H3>
                    261: <P>
2.5       frystyk   262: There are two ways we can end up with pending reqyests:
                    263: <OL>
                    264:   <LI>
                    265:     If we are out of sockets then register new host objects as pending.
                    266:   <LI>
                    267:     If we are pending on a connection then register new net objects as pending
                    268: </OL>
                    269: <P>
                    270: This set of functions handles pending host objects and can start new requests
                    271: as resources get available. The first function checks the host object for
                    272: any pending <A HREF="HTNet.html">Net objects</A> and return the first of
                    273: these Net objects.
2.3       frystyk   274: <PRE>
2.5       frystyk   275: extern HTNet * HTHost_nextPendingNet (HTHost * host);
                    276: </PRE>
                    277: <P>
                    278: The second checks the list of pending host objects waiting for a socket and
                    279: returns the first of these Host objects.
                    280: <PRE>
                    281: extern HTHost * HTHost_nextPendingHost (void);
                    282: </PRE>
                    283: <P>
                    284: Start the next pending request if any. First we look for pending requests
                    285: for the same host and then we check for any other pending hosts. If nothing
                    286: pending then register a catch close event handler to have something catching
                    287: the socket if the remote server closes the connection, for example due to
                    288: timeout.
2.8       frystyk   289: <PRE>
                    290: extern BOOL HTHost_launchPending (HTHost * host);
                    291: 
                    292: extern int HTHost_connect (HTHost * host, HTNet * net, char * url,
                    293:                            HTProtocolId port);
                    294: </PRE>
                    295: <P>
                    296: HTHost clients can use the host for all IO and take advantage of host
                    297: multiplexing and pipelining.
2.22    ! frystyk   298: 
        !           299: <H3>
        !           300:   How many Requests can we Pipeline onto the same Connection?
        !           301: </H3>
        !           302: 
        !           303: Use these functions to set the max number of requests that can be
        !           304: pipelined at any one time on a single, persistent connection. The
        !           305: higher the number, the more we have to recover if the server closes
        !           306: the connection prematurely.
        !           307: 
        !           308: <PRE>
        !           309: extern BOOL HTHost_setMaxPipelinedRequests (int max);
        !           310: extern int HTHost_maxPipelinedRequests (void);
        !           311: </PRE>
        !           312: 
2.12      frystyk   313: <H2>
2.8       frystyk   314:   Event Management
2.12      frystyk   315: </H2>
2.8       frystyk   316: <PRE>
                    317: extern int HTHost_register(HTHost * host, HTNet * net, HTEventType type);
                    318: extern int HTHost_unregister(HTHost * host, HTNet * net, HTEventType type);
                    319: extern int HTHost_tickleFirstNet(HTHost * host, HTEventType type);
2.16      frystyk   320: 
2.8       frystyk   321: extern BOOL HTHost_setRemainingRead(HTHost * host, size_t remainaing);
2.16      frystyk   322: extern size_t HTHost_remainingRead (HTHost * host);
                    323: 
2.8       frystyk   324: extern SockA * HTHost_getSockAddr(HTHost * host);
                    325: </PRE>
                    326: <H3>
2.12      frystyk   327:   Control the Delayed Flush Timer
2.8       frystyk   328: </H3>
2.12      frystyk   329: <P>
                    330: These methods can control how long we want to wait for a flush on a given
                    331: host.
2.8       frystyk   332: <PRE>
2.12      frystyk   333: extern BOOL HTHost_setWriteDelay (HTHost * host, ms_t delay);
                    334: extern ms_t HTHost_writeDelay (HTHost * host);
                    335: extern int HTHost_findWriteDelay(HTHost * host, ms_t lastFlushTime, int buffSize);
2.8       frystyk   336: </PRE>
2.12      frystyk   337: <P>
                    338: It is also possible to explicitly require a flush using the following method
2.8       frystyk   339: <PRE>
2.12      frystyk   340: extern int HTHost_forceFlush(HTHost * host);
2.8       frystyk   341: </PRE>
2.12      frystyk   342: <P>
                    343: You can also set the global value so that all new host objects will inherit
                    344: this value instead of setting it individually.
                    345: <PRE>extern BOOL HTHost_setDefaultWriteDelay (ms_t delay);
                    346: extern ms_t HTHost_defaultWriteDelay (void);
                    347: </PRE>
2.8       frystyk   348: <H3>
2.12      frystyk   349:   Event Timeouts
2.8       frystyk   350: </H3>
2.12      frystyk   351: <P>
                    352: Events can be assigned a timeout which causes the event to be triggered if
                    353: the timeout happens before other action is available on the socket. You can
                    354: assign a global timeout for all host object using the following methods
2.8       frystyk   355: <PRE>
2.12      frystyk   356: extern int HTHost_eventTimeout (void);
                    357: extern void HTHost_setEventTimeout (int millis);
2.8       frystyk   358: </PRE>
                    359: <H3>
2.12      frystyk   360:   Get the Next Net object for Reading and Writing
2.8       frystyk   361: </H3>
                    362: <PRE>
                    363: extern HTNet * HTHost_firstNet     (HTHost * host);
                    364: extern HTNet * HTHost_getReadNet  (HTHost * host);
                    365: extern HTNet * HTHost_getWriteNet (HTHost * host);
                    366: </PRE>
                    367: <H3>
2.12      frystyk   368:   Automatic Connection Recovery
                    369: </H3>
                    370: <P>
                    371: In case a pipeline is broken then we have to recover it and start again.
                    372: This is handled automatically by the host object
2.17      frystyk   373: <PRE>
                    374: extern BOOL HTHost_recoverPipe (HTHost * host);
                    375: extern BOOL HTHost_doRecover (HTHost * host);
2.12      frystyk   376: </PRE>
                    377: <H3>
2.8       frystyk   378:   Get input and output Streams for this Host
                    379: </H3>
                    380: <PRE>
                    381: extern HTInputStream * HTHost_getInput (HTHost * host, HTTransport * transport,
                    382:                                        void * param, int mode);
                    383: 
                    384: extern HTOutputStream * HTHost_getOutput (HTHost * host, HTTransport * tp,
                    385:                                          void * param, int mode);
                    386: </PRE>
                    387: <H3>
2.12      frystyk   388:   The Channel Associated with this Host
                    389: </H3>
                    390: <PRE>
                    391: extern BOOL HTHost_setChannel (HTHost * host, HTChannel * channel);
                    392: extern HTChannel * HTHost_channel (HTHost * host);
                    393: </PRE>
                    394: <H3>
2.8       frystyk   395:   Read Management
                    396: </H3>
                    397: <PRE>
                    398: extern int HTHost_read(HTHost * host, HTNet * net);
                    399: extern BOOL HTHost_setConsumed(HTHost * host, size_t bytes);
2.3       frystyk   400: </PRE>
2.12      frystyk   401: <H2>
                    402:   Multi homed Host Management
                    403: </H2>
                    404: <P>
                    405: We also keep track of if a host has multiple IP addresses. If so then it
                    406: is called a <I>multi-homed host</I>. This is used for two things: finding
                    407: the fastest host with this name and as a backup if one or more of the hosts
                    408: are down.
2.1       frystyk   409: <PRE>
2.12      frystyk   410: extern BOOL HTHost_setHome (HTHost * host, int home);
                    411: extern int HTHost_home (HTHost * host);
2.13      frystyk   412: 
                    413: extern BOOL HTHost_setRetry (HTHost * host, int retry);
                    414: extern int HTHost_retry (HTHost * host);
                    415: extern BOOL HTHost_decreaseRetry (HTHost * host);
2.19      kahan     416: </PRE>
                    417: 
                    418: <P>
                    419: A new callback plugged to the activation of a request. Allows to simplify
                    420: Amaya's use of libwww.
                    421: </P>
                    422: <PRE>
                    423: typedef int HTHost_ActivateRequestCallback (HTRequest *);
                    424: extern void HTHost_setActivateRequestCallback (HTHost_ActivateRequestCallback *
                    425: cbf);
                    426: </PRE>
                    427: 
                    428: <P>
                    429: Controls whether pending requests should be automatically activated.
                    430: </P>
                    431: 
                    432: <PRE>
                    433: extern void HTHost_enable_PendingReqLaunch (void);
                    434: extern void HTHost_disable_PendingReqLaunch (void);
                    435: </PRE>
                    436: 
2.12      frystyk   437: <PRE>
2.1       frystyk   438: #endif /* HTHOST_H */
                    439: </PRE>
2.3       frystyk   440: <P>
                    441:   <HR>
2.1       frystyk   442: <ADDRESS>
2.22    ! frystyk   443:   @(#) $Id: HTHost.html,v 2.21 1998/05/14 02:10:33 frystyk Exp $
2.1       frystyk   444: </ADDRESS>
2.3       frystyk   445: </BODY></HTML>

Webmaster