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

2.1       frystyk     1: <HTML>
                      2: <HEAD>
2.2       frystyk     3: <TITLE>Multithreaded Management</TITLE>
2.1       frystyk     4: </HEAD>
                      5: <BODY>
2.2       frystyk     6: 
                      7: <H1>Multithreaded Management of Sockets</H1>
2.1       frystyk     8: 
2.5       frystyk     9: <PRE>
                     10: /*
2.8       frystyk    11: **     (c) COPYRIGHT MIT 1995.
2.5       frystyk    12: **     Please first read the full copyright statement in the file COPYRIGH.
                     13: */
                     14: </PRE>
                     15: 
2.1       frystyk    16: This module contains the routines for handling the set of active
2.2       frystyk    17: sockets currently in use by the multithreaded clients. It is an
                     18: internal module to the Library, the application interface is
                     19: implemented in the <A HREF="HTEvent.html">Event Module</A>. Look for
                     20: more information in the <A
2.7       frystyk    21: HREF="http://www.w3.org/hypertext/WWW/Library/User/Features/multithread.html">
2.2       frystyk    22: Multithread Specifications</A>. <P>
2.1       frystyk    23: 
                     24: This module is implemented by <A HREF="HTThread.c">HTThread.c</A>, and
                     25: it is a part of the <A NAME="z10"
2.7       frystyk    26: HREF="http://www.w3.org/hypertext/WWW/Library/User/Guide/Guide.html">Library
2.1       frystyk    27: of Common Code</A>.
                     28: 
                     29: <PRE>
                     30: #ifndef HTTHREAD_H
                     31: #define HTTHREAD_H
2.7       frystyk    32: #include "HTAccess.h"
2.1       frystyk    33: </PRE>
                     34: 
                     35: <A NAME="Init"><H2>Initiation</H2></A>
                     36: 
                     37: This function initiates the arrays of socket descriptors used in the
                     38: Library. It is currently done in the private <A
                     39: HREF="HTAccess.html#ProtReg">HTAccessInit</A> function. <P>
                     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.7       frystyk    46: SRC="http://www.w3.org/hypertext/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.1       frystyk   110:     THD_CLOSE
                    111: } HTThreadAction;
                    112: </PRE>
                    113: 
                    114: <PRE>
2.9       frystyk   115: extern void HTThreadState      PARAMS((SOCKFD sockfd, HTThreadAction action));
2.1       frystyk   116: </PRE>
                    117: 
                    118: This function makes life easier if you want to mark all sockets as
                    119: interrupted.
                    120: 
                    121: <PRE>
2.9       frystyk   122: extern BOOL HTThreadMarkIntrAll        PARAMS((CONST fd_set * fd_user));
2.1       frystyk   123: </PRE>
                    124: 
                    125: <H2>Is a Thread Interrupted?</H2>
                    126: 
                    127: This function returns YES if the socket is registered as interrupted
                    128: 
                    129: <PRE>
2.6       frystyk   130: extern BOOL HTThreadIntr       PARAMS((SOCKFD sockfd));
2.1       frystyk   131: </PRE>
                    132: 
                    133: <H2>Any Threads Registered?</H2>
                    134: 
                    135: This function returns YES if any HTTP sockets are still registered in the
                    136: set of active sockets. Otherwise it returns NO.
                    137: 
                    138: <PRE>
2.4       frystyk   139: extern BOOL HTThreadActive     NOPARAMS;
2.1       frystyk   140: </PRE>
                    141: 
                    142: <H2>Select an Active Thread</H2>
                    143: 
                    144: When the <CODE>select</CODE> function has returned a set of pending
                    145: sockets this functions selects one of them and finds the
                    146: correseponding request structure.
                    147: 
                    148: <PRE>
2.3       frystyk   149: extern HTRequest *HTThread_getRequest  PARAMS((CONST fd_set * fd_read,
2.1       frystyk   150:                                                CONST fd_set * fd_write));
                    151: 
                    152: #endif
                    153: </PRE>
                    154: 
                    155: End of HTThread module
                    156: </BODY>
                    157: </HTML>
                    158: 
                    159: 

Webmaster