⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hthost.h

📁 www工具包. 这是W3C官方支持的www支撑库. 其中提供通用目的的客户端的WebAPI: complete HTTP/1.1 (with caching, pipelining, PUT, POS
💻 H
📖 第 1 页 / 共 2 页
字号:
/*  					W3C Sample Code Library libwww Host Class!  The Host Class!*//***	(c) COPYRIGHT MIT 1995.**	Please first read the full copyright statement in the file COPYRIGH.*//*The Host class manages what we know about a remote host. This can for examplebe what type of host it is, and what version it is using. Notice that a hostobject can be used to describe both a server or a client - all informationin the Host object can be shared regardless of whether it is to be used ina server application or a client application.This module is implemented by HTHost.c, and it isa part of the  W3C Sample CodeLibrary.*/#ifndef HTHOST_H#define HTHOST_Htypedef struct _HTHost HTHost;#define HOST_HASH_SIZE		HT_M_HASH_SIZE#include "HTChannl.h"#include "HTReq.h"#include "HTEvent.h"#include "HTProt.h"#include "HTTimer.h"/*The Host class contains information about the remote host, for example thetype (HTTP/1.0, HTTP/1.1, FTP etc.) along with information on how the connectionscan be used (if it supports persistent connections, interleaved access etc.).  Creation and Deletion Methods.We keep a cache of information that we know about a remote host. This allowsus to be much more detailed in generating requests. Search the host infocache for a host object or create a new one and add it. Examples of hostnames are	 	   o 	     www.w3.org	   o 	     www.foo.com:8000	 	 (  Add a Host Object)*/extern HTHost * HTHost_new (char * host, u_short u_port);extern HTHost * HTHost_newWParse(HTRequest * request, char * url, u_short u_port);extern int HTHost_hash (HTHost * host);/*(  Delete a Host Object)The Host Class contains an automatic garbage collection of Host objects sothat we don't keep information around that is stale.(  Find a Host Object)Searches the cache of known hosts to see if we already have information aboutthis host. If not then we return NULL.*/extern HTHost * HTHost_find (char * host);/*(  Delete the Host table)Cleanup and delete the host table.*/extern void HTHost_deleteAll (void);/*(  Is Host Idle?)You can use this function to see whether a host object is idle or in use.We have several modes describing how and when a host is idle. This is a functionof the Transport Object*/extern BOOL HTHost_isIdle (HTHost * host);/*.  Remote Host Information.We keep track of the capabilities of the host in the other end so thatwemay adjust our queries to fit it better(  Remote Host Name)Get the name of the remote host. This is set automatically when a new Hostobject and can be asked for at any point in time. You can not change thehost name but must create a new Host object instead.*/extern char * HTHost_name	(HTHost * host);/*(  Remote Host Protocol Class and Version)Define the host class of the host at the other end. A class is ageneric description of the protocol which is exactly like the access methodin a URL, for example "http" etc. The host version is a finerdistinction (sub-class) between various versions of the host class, for exampleHTTP/0.9, HTTP/1.1 etc. The host version is a bit flag that the protocolmodule can define on its own. That way we don't have to change this modulewhen registering a new protocol module. The host type is a descriptionof whether we can keep the connection persistent or not.*/extern char * HTHost_class	(HTHost * host);extern void HTHost_setClass	(HTHost * host, char * s_class);extern int  HTHost_version	(HTHost * host);extern void HTHost_setVersion	(HTHost * host, int version);/*(  Public Methods accessible on This Host)A server can inform a client about the supported methods using thePublic header.*/extern HTMethod HTHost_publicMethods 	(HTHost * me);extern void HTHost_setPublicMethods 	(HTHost * me, HTMethod methodset);extern void HTHost_appendPublicMethods	(HTHost * me, HTMethod methodset);/*(  Server Name of Remote Host)A server can send its server application name and version in a HTTP response.We pick up this information and add it to the Host object*/extern char * HTHost_server	(HTHost * host);extern BOOL HTHost_setServer	(HTHost * host, const char * server);/*(  User Agent Name of Remote Host)A client can send the name of the client application in a HTTP request. Wepick up this information and add it to the Host Object*/extern char * HTHost_userAgent 	(HTHost * host);extern BOOL HTHost_setUserAgent	(HTHost * host, const char * userAgent);/*(  Range Units Accepted by this Host)Since all HTTP entities are represented in HTTP messages as sequences ofbytes, the concept of a byte range is meaningful for any HTTP entity. (However,not all clients and servers need to support byte-range operations.) Byterange specifications in HTTP apply to the sequence of bytes in the entity-body(not necessarily the same as the message-body). A byte range operation mayspecify a single range of bytes, or a set of ranges within a single entity.You can also check whether a specific range unit is OK. We always sayYES except if we have a specific statement from the server thatit doesn't understand byte ranges - that is - it has sent "none" in a"Accept-Range" response header*/extern char * HTHost_rangeUnits  (HTHost * host);extern BOOL HTHost_setRangeUnits (HTHost * host, const char * units);extern BOOL HTHost_isRangeUnitAcceptable (HTHost * host, const char * unit);/*(  User Defined Contexts)This can be used for anything that the application would like to keep tabson.*/extern void HTHost_setContext (HTHost * me, void * context);extern void * HTHost_context  (HTHost * me);/*.  Register a Request on a Host Object.Requests are queued in the Host object until we haveresources to start them. The request is in the formof a Net object as we may have multiple socket requestsper Request object. This is for example the casewith FTP which uses two connections.*/extern int  HTHost_addNet    (HTHost * host, HTNet * net);extern BOOL HTHost_deleteNet (HTHost * host, HTNet * net, int status);extern HTList * HTHost_net   (HTHost * host);/*.  Channels.A Channel object is an abstraction for a transport,like a TCP connection, for example. Each host object can have at most onechannel object associated with it.(  Create a Channel to a Host)As a Net Object doesn't necessarily know whetherthere is a channel up and running and whether that channel can be reused,it must do an explicit connect the the host.*/extern int HTHost_connect (HTHost * host, HTNet * net, char * url);extern int HTHost_accept  (HTHost * host, HTNet * net, char * url);extern int HTHost_listen  (HTHost * host, HTNet * net, char * url);/*(  Is Channel About to Close?)As soon as we know that a channel is about to close (for example becausethe server sends us a Connection: close header field) then we registerthis informtation in the Host object:*/extern BOOL HTHost_setCloseNotification (HTHost * host, BOOL mode);extern BOOL HTHost_closeNotification (HTHost * host);/*(  Find Channel Associated with a Host Object)Here you can find an already associated channel with a host object or youcan explicitly associate a channel with a host object.*/extern BOOL HTHost_setChannel (HTHost * host, HTChannel * channel);extern HTChannel * HTHost_channel (HTHost * host);/*(  Delete a Channel)When a channel is deleted, it must be unregistered from the host object whichis done by this operation:*/extern BOOL HTHost_clearChannel (HTHost * host, int status);/*.  Transport Mode.The way a channel can be used depends on thetransport and what mode the channel is in. Themode (whether we can use persistent connections, pipeline, etc.) may changemode in the middle of a connection If the new mode is lower than the oldmode then adjust the pipeline accordingly. That is, if we are going intosingle mode then move all entries in the pipeline and move the rest to thepending queue. They will get launched at a later point in time.*/extern HTTransportMode HTHost_mode (HTHost * host, BOOL * active);extern BOOL HTHost_setMode (HTHost * host, HTTransportMode mode);/*.  Handling Pending Requests.There are two ways we can end up with pending requests:  o 	     If we are out of sockets then register new host objects as pending.	   o 	     If we are pending on a connection then register new net objects as pending	 This set of functions handles pending host objects and can start new requestsas resources get available. The first function checks the host object for

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -