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

2.1       frystyk     1: <HTML>
                      2: <HEAD>
2.2       frystyk     3: <TITLE>Multithreaded Management</TITLE>
2.15      frystyk     4: <!-- Changed by: Henrik Frystyk Nielsen, 12-Jul-1995 -->
2.1       frystyk     5: </HEAD>
                      6: <BODY>
2.2       frystyk     7: 
                      8: <H1>Multithreaded Management of Sockets</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.16    ! frystyk    22: HREF="http://www.w3.org/pub/WWW/Library/User/Architecture/Threads.html">
2.2       frystyk    23: Multithread Specifications</A>. <P>
2.1       frystyk    24: 
                     25: This module is implemented by <A HREF="HTThread.c">HTThread.c</A>, and
                     26: it is a part of the <A NAME="z10"
2.16    ! frystyk    27: HREF="http://www.w3.org/pub/WWW/Library/">
2.14      frystyk    28: W3C Reference Library</A>.
2.1       frystyk    29: 
                     30: <PRE>
                     31: #ifndef HTTHREAD_H
                     32: #define HTTHREAD_H
2.7       frystyk    33: #include "HTAccess.h"
2.1       frystyk    34: </PRE>
                     35: 
                     36: <A NAME="Init"><H2>Initiation</H2></A>
                     37: 
                     38: This function initiates the arrays of socket descriptors used in the
2.13      frystyk    39: Library. It's called in <A HREF="HTAccess.html#Library">HTLibInit()</A>.
2.1       frystyk    40: 
                     41: <PRE>
2.3       frystyk    42: extern BOOL HTThreadInit       NOPARAMS;
2.1       frystyk    43: </PRE>
                     44: 
2.2       frystyk    45: <IMG ALT="NOTE"
2.16    ! frystyk    46: SRC="http://www.w3.org/pub/WWW/Icons/32x32/caution.gif"> It is
2.2       frystyk    47: <B>VERY</B> important that this one is called before the first
                     48: request, as otherwise the socket bit arrays are uninitialized.
                     49: 
2.1       frystyk    50: <H2>Registration of a Thread</H2>
                     51: 
                     52: These two functions put a <A HREF="HTAccess.html#HTNetInfo">HTNetInfo
                     53: object</A> into the list of threads and takes it out again
                     54: respectively. A normal place to call these functions would be on
2.2       frystyk    55: creation and deletion of the <CODE>HTNetInfo</CODE> data structure.
2.1       frystyk    56: 
                     57: <PRE>
2.9       frystyk    58: extern BOOL HTThread_new       PARAMS((HTNetInfo * new_net));
                     59: extern BOOL HTThread_clear     PARAMS((HTNetInfo * old_net));
                     60: </PRE>
                     61: 
                     62: <H2>Kill a Thread</H2>
                     63: 
                     64: This function forces a call to the load function and resets the state
                     65: machine. It also removes the thread from the list of active threads.
                     66: 
                     67: <PRE>
                     68: extern BOOL HTThread_kill      PARAMS((HTNetInfo * net));
2.1       frystyk    69: </PRE>
                     70: 
2.10      frystyk    71: <H2>Is Thread Alive?</H2>
                     72: 
                     73: Checks whether a thread is still registered and if so returns the
                     74: corresponding <A HREF="HTAccess.html#z1">HTRequest structure</A>, else
                     75: return NULL.
                     76: 
                     77: <PRE>
                     78: extern HTRequest *HTThread_isAlive     PARAMS((HTNetInfo * net));
                     79: </PRE>
                     80: 
2.7       frystyk    81: <H2>Get Copy of Registered Bit-arrays</H2>
2.1       frystyk    82: 
                     83: This function returns a copy of the current bit-arrays contaning the
                     84: active sockets registered for <CODE>READ</CODE> and
                     85: <CODE>WRITE</CODE>.
                     86: 
                     87: <PRE>
2.3       frystyk    88: extern int HTThreadGetFDInfo   PARAMS((fd_set * read, fd_set * write));
2.1       frystyk    89: </PRE>
                     90: 
                     91: <H2>Registration of the State of a Socket</H2>
                     92: 
                     93: When a new request is initiated from the client and a socket has been
                     94: created, is gets registered in a linked list of <A
                     95: HREF="HTAccess.html#HTNetInfo">HTNetInfo objects</A>. The object stays
                     96: in this list until the request has ended (either having an error or
                     97: success as result). Every time the program execution gets to a point
                     98: where a socket operation would normally block the program, this
                     99: function is called in order to register the socket as waiting for the
                    100: actual operation.
                    101: 
                    102: <PRE>
                    103: typedef enum _HTThreadAction {
2.5       frystyk   104:     THD_SET_WRITE=0,
2.1       frystyk   105:     THD_CLR_WRITE,
                    106:     THD_SET_READ,
                    107:     THD_CLR_READ,
2.4       frystyk   108:     THD_SET_INTR,
                    109:     THD_CLR_INTR,
2.15      frystyk   110:     THD_CLOSE,
                    111:     THD_SET_CONNECT,
                    112:     THD_CLR_CONNECT
2.1       frystyk   113: } HTThreadAction;
                    114: </PRE>
                    115: 
                    116: <PRE>
2.12      frystyk   117: extern void HTThreadState              PARAMS((SOCKFD sockfd,
                    118:                                        HTThreadAction action));
                    119: extern void HTThreadStateByRequest     PARAMS((HTRequest * request,
                    120:                                        HTThreadAction action));
2.1       frystyk   121: </PRE>
                    122: 
                    123: This function makes life easier if you want to mark all sockets as
                    124: interrupted.
                    125: 
                    126: <PRE>
2.9       frystyk   127: extern BOOL HTThreadMarkIntrAll        PARAMS((CONST fd_set * fd_user));
2.1       frystyk   128: </PRE>
                    129: 
                    130: <H2>Is a Thread Interrupted?</H2>
                    131: 
                    132: This function returns YES if the socket is registered as interrupted
                    133: 
                    134: <PRE>
2.6       frystyk   135: extern BOOL HTThreadIntr       PARAMS((SOCKFD sockfd));
2.1       frystyk   136: </PRE>
                    137: 
                    138: <H2>Any Threads Registered?</H2>
                    139: 
                    140: This function returns YES if any HTTP sockets are still registered in the
                    141: set of active sockets. Otherwise it returns NO.
                    142: 
                    143: <PRE>
2.4       frystyk   144: extern BOOL HTThreadActive     NOPARAMS;
2.1       frystyk   145: </PRE>
                    146: 
                    147: <H2>Select an Active Thread</H2>
                    148: 
                    149: When the <CODE>select</CODE> function has returned a set of pending
                    150: sockets this functions selects one of them and finds the
                    151: correseponding request structure.
                    152: 
                    153: <PRE>
2.3       frystyk   154: extern HTRequest *HTThread_getRequest  PARAMS((CONST fd_set * fd_read,
2.1       frystyk   155:                                                CONST fd_set * fd_write));
                    156: 
                    157: #endif
                    158: </PRE>
                    159: 
                    160: End of HTThread module
                    161: </BODY>
                    162: </HTML>
                    163: 
                    164: 

Webmaster