?? htnet.h
字號(hào):
/* W3C Sample Code Library libwww HTNet Class! The Net Class!*//*** (c) COPYRIGHT MIT 1995.** Please first read the full copyright statement in the file COPYRIGH.*//*The Net class manages information related to a "thread" in libwww. As libwwwthreads are not really threads but a notion of using interleaved, non-blockingI/O for accessing data objects from the network (or local file system), theycan be used on any platform with or without support for native threads. Inthe case where you have an application using real threads the Net class issimply a object maintaining links to all other objects involved in servingthe request. If you are using the libwww pseudo threads then the Net objectcontains enough information to stop and start a request based on which BSDsockets are ready. In practise this is of course transparent to the application- this is just to explain the difference.When a Request object is passed to the Library ,the core creates a new HTNet object per channelused by the request. In many cases a request only uses a singlechannel object but, for example, FTP requests useat least two - one for the control connection and one for the data connection.You can find more information about the libwww pseudo thread model in the Multithread Specifications.This module is implemented by HTNet.c, and it is apart of the W3C Sample Code Library.*/#ifndef HTNET_H#define HTNET_H/*The HTNet object is the core of the request queue management.This object contains information about the socket descriptor, the input readbuffer etc. required to identify and service a request.*/typedef struct _HTNet HTNet;#include "HTEvent.h"#include "HTReq.h"#include "HTResponse.h"#include "HTTrans.h"#include "HTHost.h"#include "HTProt.h"#include "HTChannl.h"#include "HTDNS.h"/*. Generic BEFORE and AFTER Filter Management.Filter functions can be registered to be called before andafter a request has either been started or has terminated. Theconditions for BEFORE and AFTER filters are not the same, and sowe maintain them independently. Filters can be registered globally or locally.The global filters are registered directly by the Net Object (this module)and the local filters are registered by theHTRequest Object. However, both local andglobal filters use the same regisration mechanism which we provide here.( Filter Ordering)Filters can be registered by anyone and as they are an often used mechanismfor introducing extensions in libwww, they are videly used to handleauthentication, redirection, etc. Many filters can be registered at onceand not all of the filters may know about the other filters. Therefore, itis difficult to specify an absolute ordering by which the filters shouldbe called. Instead you can decide a relative order by which the filters shouldbe called. The order works pretty much like the Unix priority mechanism runningfrom HT_FILTER_FIRST to HT_FILTER_LAST havingHT_FILTER_MIDDLE being the "normal" case.*/typedef enum _HTFilterOrder { HT_FILTER_FIRST = 0x0, /* 0 */ HT_FILTER_EARLY = 0x3FFF, /* 16383 */ HT_FILTER_MIDDLE = 0x7FFF, /* 32767 */ HT_FILTER_LATE = 0xBFFE, /* 49150 */ HT_FILTER_LAST = 0xFFFF /* 65535 */} HTFilterOrder;/*In case multiple filters are registered with the same order then they arecalled in the inverse order they were registered. ( Filter URL Templates)Both BEFORE and AFTER filters can be registered with a URLtemplate in which case they are only called when the Request URLmatches the template. A template is simply a string which is matched againstthe Request URL. The string can be terminated by a single"*" in which case all strings matching the template up til the"*" is considered a match. A template can be as short as the access schemewhich enmables a filter for a specific access method only, for example"http//<star>".( BEFORE Filters)A BEFORE filter is called whenever we issue a request and they havebeen selected by the execution procedure. BEFORE filters are registeredwith a context and a filter order by which they are to be calledand a URL template which may be NULL. In this case, the filter iscalled on every request. The mode can be used by anybody to pass an extraparameter to a filter. This is not really OO thinking - but hey - this isC ;-)*/typedef int HTNetBefore (HTRequest * request, void * param, int mode);/*You can add a BEFORE filter in the list provided by the caller. Severalfilters can be registered in which case they are called with the filter orderingin mind.*/extern BOOL HTNetCall_addBefore (HTList * list, HTNetBefore * before, const char * tmplate, void * param, HTFilterOrder order);/*You can also unregister all instances of a BEFORE filter from a list usingthe following function*/extern BOOL HTNetCall_deleteBefore (HTList * list, HTNetBefore * before);/*You get rid of all BEFORE filters using this function*/extern BOOL HTNetCall_deleteBeforeAll (HTList * list);/*The BEFORE filters are expected and called if appropriate every time we issuea new request. Libwww calls the BEFORE filters in the order specified atregistration time. If a filter returns other than HT_OK then stop and returnimmediately. Otherwise return what the last filter returns.*/extern int HTNetCall_executeBefore (HTList * list, HTRequest * request);/*( AFTER Filters)An AFTER filter is called whenever we have terminated a request. Thatis, on the way out from the protocol module andback to the application. AFTER filters are registered with acontext, a status, a filter order by which they areto be called and a URL template which may be NULL. The status of therequest may determine which filter to call. The set of possible values aregiven below. An AFTER filter can be registered to handle one or moreof the codes. HT_ERROR An error occured HT_LOADED The document was loaded HT_NO_DATA OK, but no data HT_NO_ACCESS The request could not be succeeded due to lack of credentials HT_NO_PROXY_ACCESS The request could not be succeeded due to lack of credentials for accessing an intermediate proxy HT_RETRY Retry request after at a later time HT_PERM_REDIRECT The request has been permanently redirected and we send back the new URL HT_TEMP_REDIRECT The request has been temporarily redirected and we send back the new URL HT_ALL All of aboveA Protocol module can also, in certain cases, return a HT_IGNOREin which case no filters are called*/typedef int HTNetAfter (HTRequest * request, HTResponse * response, void * param, int status);/*You can register a AFTER filter in the list provided by the caller. Severalfilters can be registered in which case they are called with the filter orderingin mind.*/extern BOOL HTNetCall_addAfter (HTList * list, HTNetAfter * after, const char * tmplate, void * param, int status, HTFilterOrder order);/*You can either unregister all filters registered for a given status usingthis function or the filter for all status codes.*/extern BOOL HTNetCall_deleteAfter (HTList * list, HTNetAfter * after);extern BOOL HTNetCall_deleteAfterStatus (HTList * list, int status);/*You can also delete all AFTER filters in list*/extern BOOL HTNetCall_deleteAfterAll (HTList * list);/*This function calls all the AFTER filters in the order specified at registrationtime and if it has the right status code and it's not HT_IGNORE.We also check for any template and whether it matches or not. If a filterreturns other than HT_OK then stop and return immediately. Otherwise returnwhat the last filter returns.*/extern int HTNetCall_executeAfter (HTList * list, HTRequest * request, int status);/*. Global BEFORE and AFTER Filter Management.Global filters are inspected on every request (they do not have to be called- only if the conditions match). You can also register filters locally inthe Request object. Global BEFORE FiltersThese are the methods to handle global BEFORE Filters.*/extern BOOL HTNet_setBefore (HTList * list);extern HTList * HTNet_before (void);extern BOOL HTNet_addBefore (HTNetBefore * before, const char * tmplate, void * param, HTFilterOrder order);extern BOOL HTNet_deleteBefore (HTNetBefore * before);/*You can call both the local and the global BEFORE filters (if any)*/extern int HTNet_executeBeforeAll (HTRequest * request);/* Global AFTER FiltersThese are the methods to handle global AFTER Filters.*/extern BOOL HTNet_setAfter (HTList * list);extern HTList * HTNet_after (void);extern BOOL HTNet_addAfter (HTNetAfter * after, const char * tmplate, void * param, int status, HTFilterOrder order);extern BOOL HTNet_deleteAfter (HTNetAfter * after);extern BOOL HTNet_deleteAfterStatus (int status);/*You can call both the local and the global AFTER filters (if any)*/extern int HTNet_executeAfterAll (HTRequest * request, int status);/*. Socket Resource Management.The request queue ensures that no more than a fixed number of TCP connectionsare open at the same time. If more requests are handed to the Library, theyare put into the pending queue and initiated when sockets become free.( Number of Simultanous open TCP connections)Set the max number of simultanous sockets. The default value is HT_MAX_SOCKETSwhich is 6. The number of persistent connections depend on this value asa deadlock can occur if all available sockets a persistent (see theDNS Manager for more information on setting thenumber of persistent connections). The number of persistent connections cannever be more than the max number of sockets-2, so letting newmax=2 preventspersistent sockets.*/extern BOOL HTNet_setMaxSocket (int newmax);extern int HTNet_maxSocket (void);/*( Socket Counters)*/extern void HTNet_increaseSocket (void);extern void HTNet_decreaseSocket (void);extern int HTNet_availableSockets (void);/*( Persistent Socket Counters)*/extern void HTNet_increasePersistentSocket (void);extern void HTNet_decreasePersistentSocket (void);extern int HTNet_availablePersistentSockets (void);/*( Any Ongoing Connections?)Returns whether there are active requests. Idle persistent sockets do notcount as active.*/extern BOOL HTNet_isIdle (void);/*( List Active Queue)Returns the list of active requests that are currently having an open connection.Returns list of HTNet objects or NULL if error.*/extern HTList *HTNet_activeQueue (void);extern BOOL HTNet_idle (void);/*( Are we Active?
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -