1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
|
<HEADER>
<TITLE>/Net/dxcern/userd/timbl/hypertext/WWW/Library/src/HTTCP.html</TITLE></HEADER>
<BODY>
<H1>Generic Network Communication</H1>
This module has the common code for handling TCP/IP and DECnet connections
etc. The module is a part of the <A HREF="Overview.html">CERN Common WWW
Library</A>.
<PRE>
#ifndef HTTCP_H
#define HTTCP_H
#include "HTUtils.h"
#include "HTAccess.h"
#ifdef SHORT_NAMES
#define HTInetStatus HTInStat
#define HTInetString HTInStri
#define HTParseInet HTPaInet
#endif
</PRE>
<H2>Connection Management</H2>
All connections are established through these two functions.
<H3>Active Connection Establishment</H3>
This makes an active connect to the specified host. The <A HREF="HTAccess.html#HTNetInfo">HTNetInfo structure</A> is
parsed in order to handle errors. Default port might be overwritten by any
port indication in the <A HREF="http://info.cern.ch/hypertext/WWW/Addressing/URL/Overview.html">URL</A> specified as <host>:<port> If it is
a multihomed host then HTDoConnect measures the time to do the connection and
updates the calculated weights in the cache of visited hosts.
<PRE>
PUBLIC int HTDoConnect PARAMS(( HTNetInfo *net,
char *url,
u_short default_port,
u_long *addr,
BOOL use_cur));
</PRE>
<H3>Passive Connection Establishment</H3>
This function makes a non-blocking accept on a port and polls every second
until MAX_ACCEPT_POLL is reached.
<PRE>
PUBLIC int HTDoAccept PARAMS((HTNetInfo *net));
</PRE>
<H2>Caching Hosts Names</H2>
This part of the HTTCP module maintains a cache of all visited hosts so that
subsequent connects to the same host doesn't imply a new request to the DNS
every time. <P>
Multihomed hosts are treated specially in that the time spend on every connect
is measured and kept in the cache. On the next request to the same host, the
IP-address with the lowest average connect time is chosen. If one IP-address
fails completely, e.g. <EM>connection refused</EM> then it disabled and
HTDoConnect tries one of the other IP-addresses to the same host.<P>
If the connect fails in the case of at single-homed host then the entry is
removed from the cache and HTDoConnect tries again asking the DNS.
<H3>Recalculating the Time-Weights on Multihomed Hosts</H3>
On every connect to a multihomed host, the average connect time is updated
exponentially for all the entries.
<PRE>
PUBLIC void HTTCPAddrWeights PARAMS((char * host, time_t deltatime));
</PRE>
<H3>Control Variables</H3>
This parameter determines the maximum number of hosts in the cache. The
default number is 500.
<PRE>
extern unsigned int HTConCacheSize;
</PRE>
<H2>Errors and status indications</H2>
Theese functions return an explanation if an error has occured.
<H3>Errno Message</H3>
Return error message corresponding to current errno, just like strerror().
<PRE>
PUBLIC CONST char * HTErrnoString NOPARAMS;
</PRE>
<H3>Description of what Caused the Error</H3>
The parameter `where' gives a description of what caused the error, often
the name of a system call. <P>
This function should only rarely be called directly. Instead the common error
function HTErrorAdd() should be used as then the error is parsed all the way
to the user. The function returns a negative status in the unix way.
<PRE>
PUBLIC int HTInetStatus PARAMS((char * where));
</PRE>
<H3>Parse a Cardinal Value</H3>
<PRE>
/* Parse a cardinal value parse_cardinal()
** ----------------------
**
** On entry:
** *pp points to first character to be interpreted, terminated by
** non 0..9 character.
** *pstatus points to status already valid,
** maxvalue gives the largest allowable value.
**
** On exit:
** *pp points to first unread character,
** *pstatus points to status updated iff bad
*/
PUBLIC unsigned int HTCardinal PARAMS((int * pstatus,
char ** pp,
unsigned int max_value));
</PRE>
<H2>Internet Name Server Functions</H2>
The following functions are available to get information about a
specified host.
<H3>Produce a string for an internet address</H3>
This function is equivalent to the BSD system call <B>inet_ntoa</B> in that it
converts a numeric 32-bit IP-address to a dotted-notation decimal string. The
pointer returned points to static memory which must be copied if it is to be
kept.
<PRE>
PUBLIC CONST char * HTInetString PARAMS((struct sockaddr_in * sin));
</PRE>
<H3>Parse an internet node address and port</H3>
This function finds the address of a specified host and fills out the sockaddr
structure. str points to a string with a node name or number, with optional
trailing colon and port number. sin points to the binary internet or decnet
address field. <P>
On exit *sin is filled in. If no port is specified in str, that field is left
unchanged in *sin. On success, the number of homes on the host is returned.
<PRE>
PUBLIC int HTParseInet PARAMS(( struct sockaddr_in * sin,
CONST char * str,
BOOL use_cur));
</PRE>
<H3>Name of a Machine on the Other Side of a Socket</H3>
This function should have been called HTGetHostByAddr but for historical
reasons this is not the case. <P>
<EM><NOTE>Note:</NOTE>This function used to be called HTGetHostName but
this is now used to find you own host name, see <A HREF="HTTCP.html#HTGetHostName">HTGetHostName()</A></EM>
<PRE>
PUBLIC char * HTGetHostBySock PARAMS((int soc));
</PRE>
<H3>Host address retuned for specified host name</H3>
This function gets the address of the host and puts it in to the socket
structure. It maintains its own cache of connections so that the communication
to the Domain Name Server is minimized. If OK and single homed host then
it returns 0 but if it is a multi-homed host then 1 is returned.
<PRE>
PUBLIC int HTGetHostByName PARAMS((char *host, SockA *sin, BOOL use_cur));
</PRE>
<A NAME="HTGetHostName"><H3>Get Name of This Machine</H3></A>
This function returns a CONET char pointer to a static location containing
the name of this host or NULL if not available.
<PRE>
PUBLIC CONST char * HTGetHostName NOPARAMS;
</PRE>
<H3>Set Name of This Machine</H3>
This function overwrites any other value of current host name. This might
be set by the user to change the value in the ID value parsed to a news host
when posting. The change doesn't influence the <A HREF="HTTCP.html#Mailaddress">Mail Address</A> as they are stored in two different locations. If, however,
the change is done before the first call to HTGetMailAddress() then this
function will use the new host and domain name.
<PRE>
PUBLIC void HTSetHostName PARAMS((char * host));
</PRE>
<H3>Get Domain Name of This Machine</H3>
This function rerturns the domain name part of the host name as returned by
HTGetHostName() function. Changing the domain name requires a call to
HTSetHostname().
<PRE>
PUBLIC CONST char *HTGetDomainName NOPARAMS;
</PRE>
<A NAME="Mailaddress"><H3>Get User Mail Address</H3></A>
This functions returns a char pointer to a static location containing the
mail address of the current user. The static location is different from the
one of the current host name so different values can be assigned. The default
value is <USER>@hostname where hostname is as returned by HTGetHostName().
<PRE>
PUBLIC CONST char * HTGetMailAddress NOPARAMS;
</PRE>
<H3>Set User Mail Address</H3>
This function overwrites any other value of current mail address. This might
be set by the user to change the value in the <A HREF="http://info.cern.ch/hypertext/WWW/Protocols/HTTP/HTRQ_Headers.html#from">From field</A> in the <A HREF="http://info.cern.ch/hypertext/WWW/Protocols/HTTP/HTTP2.html">HTTP Protocol</A>.
<PRE>
PUBLIC void HTSetMailAddress PARAMS((char * address));
</PRE>
<PRE>
#endif /* HTTCP_H */
</PRE>
End of file
</BODY>
</HTML>
|