1 /* 2 3 W3C Sample Code Library libwww Channel Interface 4 5 6 ! 7 The Channel Class 8 ! 9 */ 10 11 /* 12 ** (c) COPYRIGHT MIT 1995. 13 ** Please first read the full copyright statement in the file COPYRIGH. 14 */ 15 16 /* 17 18 A channel contains information about sockets and their input and output streams. 19 A channel represents the front end for receiving data towards 20 the underlying transport. The definition of a channel describes how we are 21 to read the data coming in on a socket, for example. In other words - a channel 22 represents the first part of how to get handle incoming data in the Library: 23 24 25 o 26 Reading data on a channel 27 o 28 Defining a target for incoming data 29 o 30 Defining a protocol state machine that can handle the data 31 32 33 This module is implemented by HTChannl.c, and it 34 is a part of the W3C Sample Code 35 Library. 36 */ 37 38 #ifndef HTCHANNL_H 39 #define HTCHANNL_H 40 41 #ifdef __cplusplus 42 extern "C" { 43 #endif 44 45 typedef struct _HTChannel HTChannel; 46 47 #include "HTHost.h" 48 #include "HTIOStream.h" 49 50 /* 51 . 52 The Channel Object 53 . 54 55 The channel object contains an input and an output stream for a particular 56 connection. 57 ( 58 Creation and Deletion of Channel Objects 59 ) 60 61 Either the socket can be invalid (INVSOC) or the file descriptor can 62 be NULL but not both. 63 64 */ 65 66 extern HTChannel * HTChannel_new (SOCKET sockfd, FILE * fp, BOOL active); 67 68 /* 69 ( 70 Deleting a Channel Object 71 ) 72 */ 73 74 extern BOOL HTChannel_delete (HTChannel * channel, int status); 75 extern BOOL HTChannel_deleteAll (void); 76 extern BOOL HTChannel_safeDeleteAll (void); 77 78 /* 79 ( 80 Search for a Channel 81 ) 82 83 Look for a channel object if we for some reason should have lost it 84 */ 85 86 extern HTChannel * HTChannel_find (SOCKET sockfd); 87 88 /* 89 ( 90 Get Transport Descriptor for Channel 91 ) 92 93 A transport descriptor can be either a ANSI C file descriptor or a BSD socket. 94 As it is difficult for the channel to know which one is used by a specific 95 transport, we leave this to the caller to figure out. This is probably not 96 the best way of doing it. 97 */ 98 99 extern SOCKET HTChannel_socket (HTChannel * channel); 100 extern BOOL HTChannel_setSocket (HTChannel * channel, SOCKET socket); 101 102 extern FILE * HTChannel_file (HTChannel * channel); 103 extern BOOL HTChannel_setFile (HTChannel * channel, FILE * fp); 104 105 /* 106 ( 107 The Host Object 108 ) 109 110 The Channel object also keeps a link to the host 111 object so that we have a link to the persistent connection repository. 112 */ 113 extern BOOL HTChannel_setHost (HTChannel * ch, HTHost * host); 114 extern HTHost * HTChannel_host (HTChannel * ch); 115 116 /* 117 ( 118 Semaphores 119 ) 120 121 Adjust the semaphore on a channel. As many Net objects 122 can point to the same channel we need to keep count of them so that we 123 know if we can delete a channel or if it is still in use. We do this by having 124 a simple semaphore associated with each channel object 125 */ 126 127 extern void HTChannel_upSemaphore (HTChannel * channel); 128 extern void HTChannel_downSemaphore (HTChannel * channel); 129 extern void HTChannel_setSemaphore (HTChannel * channel, int semaphore); 130 131 /* 132 ( 133 Create Input and Output Streams 134 ) 135 136 You create the input stream and bind it to the channel using the following 137 methods. Please read the description in the 138 HTIOStream module on the parameters 139 target, param, and mode. The input and output 140 stream are instances created by the Transport 141 object. The Transport Object defines the creation methods for the inout 142 and output streams and the Channel object contains the actualy stream objects. 143 */ 144 145 extern BOOL HTChannel_setInput (HTChannel * ch, HTInputStream * input); 146 extern HTInputStream * HTChannel_input (HTChannel * ch); 147 extern BOOL HTChannel_deleteInput (HTChannel * channel, int status); 148 149 extern BOOL HTChannel_setOutput (HTChannel * ch, HTOutputStream * output); 150 extern HTOutputStream * HTChannel_output (HTChannel * ch); 151 extern BOOL HTChannel_deleteOutput (HTChannel * channel, int status); 152 153 extern HTInputStream * HTChannel_getChannelIStream (HTChannel * ch); 154 extern HTOutputStream * HTChannel_getChannelOStream (HTChannel * ch); 155 156 /* 157 */ 158 159 #ifdef __cplusplus 160 } 161 #endif 162 163 #endif /* HTCHANNL */ 164 165 /* 166 167 168 169 @(#) $Id$ 170 171 */ 172