| Andy Green | f7ee549 | 2011-02-13 09:04:21 +0000 | [diff] [blame] | 1 | <h2>libwebsockets_hangup_on_client - Server calls to terminate client connection</h2> | 
 | 2 | <i>void</i> | 
 | 3 | <b>libwebsockets_hangup_on_client</b> | 
| Peter Hinz | 56885f3 | 2011-03-02 22:03:47 +0000 | [diff] [blame] | 4 | (<i>struct libwebsocket_context *</i> <b>context</b>, | 
| Andy Green | f7ee549 | 2011-02-13 09:04:21 +0000 | [diff] [blame] | 5 | <i>int</i> <b>fd</b>) | 
 | 6 | <h3>Arguments</h3> | 
 | 7 | <dl> | 
| Peter Hinz | 56885f3 | 2011-03-02 22:03:47 +0000 | [diff] [blame] | 8 | <dt><b>context</b> | 
| Andy Green | f7ee549 | 2011-02-13 09:04:21 +0000 | [diff] [blame] | 9 | <dd>libwebsockets context | 
 | 10 | <dt><b>fd</b> | 
 | 11 | <dd>Connection socket descriptor | 
 | 12 | </dl> | 
 | 13 | <hr> | 
| Andy Green | 0703409 | 2011-02-13 08:37:12 +0000 | [diff] [blame] | 14 | <h2>libwebsockets_get_peer_addresses - Get client address information</h2> | 
 | 15 | <i>void</i> | 
 | 16 | <b>libwebsockets_get_peer_addresses</b> | 
 | 17 | (<i>int</i> <b>fd</b>, | 
 | 18 | <i>char *</i> <b>name</b>, | 
 | 19 | <i>int</i> <b>name_len</b>, | 
 | 20 | <i>char *</i> <b>rip</b>, | 
 | 21 | <i>int</i> <b>rip_len</b>) | 
 | 22 | <h3>Arguments</h3> | 
 | 23 | <dl> | 
 | 24 | <dt><b>fd</b> | 
 | 25 | <dd>Connection socket descriptor | 
 | 26 | <dt><b>name</b> | 
 | 27 | <dd>Buffer to take client address name | 
 | 28 | <dt><b>name_len</b> | 
 | 29 | <dd>Length of client address name buffer | 
 | 30 | <dt><b>rip</b> | 
 | 31 | <dd>Buffer to take client address IP qotted quad | 
 | 32 | <dt><b>rip_len</b> | 
 | 33 | <dd>Length of client address IP buffer | 
 | 34 | </dl> | 
 | 35 | <h3>Description</h3> | 
 | 36 | <blockquote> | 
 | 37 | This function fills in <tt><b>name</b></tt> and <tt><b>rip</b></tt> with the name and IP of | 
 | 38 | the client connected with socket descriptor <tt><b>fd</b></tt>.  Names may be | 
 | 39 | truncated if there is not enough room.  If either cannot be | 
 | 40 | determined, they will be returned as valid zero-length strings. | 
 | 41 | </blockquote> | 
 | 42 | <hr> | 
| Andy Green | 9f99034 | 2011-02-12 11:57:45 +0000 | [diff] [blame] | 43 | <h2>libwebsocket_service_fd - Service polled socket with something waiting</h2> | 
 | 44 | <i>int</i> | 
 | 45 | <b>libwebsocket_service_fd</b> | 
| Peter Hinz | 56885f3 | 2011-03-02 22:03:47 +0000 | [diff] [blame] | 46 | (<i>struct libwebsocket_context *</i> <b>context</b>, | 
| Andy Green | 9f99034 | 2011-02-12 11:57:45 +0000 | [diff] [blame] | 47 | <i>struct pollfd *</i> <b>pollfd</b>) | 
 | 48 | <h3>Arguments</h3> | 
 | 49 | <dl> | 
| Peter Hinz | 56885f3 | 2011-03-02 22:03:47 +0000 | [diff] [blame] | 50 | <dt><b>context</b> | 
| Andy Green | 9f99034 | 2011-02-12 11:57:45 +0000 | [diff] [blame] | 51 | <dd>Websocket context | 
 | 52 | <dt><b>pollfd</b> | 
 | 53 | <dd>The pollfd entry describing the socket fd and which events | 
 | 54 | happened. | 
 | 55 | </dl> | 
 | 56 | <h3>Description</h3> | 
 | 57 | <blockquote> | 
 | 58 | This function closes any active connections and then frees the | 
 | 59 | context.  After calling this, any further use of the context is | 
 | 60 | undefined. | 
 | 61 | </blockquote> | 
 | 62 | <hr> | 
| Andy Green | 6964bb5 | 2011-01-23 16:50:33 +0000 | [diff] [blame] | 63 | <h2>libwebsocket_context_destroy - Destroy the websocket context</h2> | 
 | 64 | <i>void</i> | 
 | 65 | <b>libwebsocket_context_destroy</b> | 
| Peter Hinz | 56885f3 | 2011-03-02 22:03:47 +0000 | [diff] [blame] | 66 | (<i>struct libwebsocket_context *</i> <b>context</b>) | 
| Andy Green | 6964bb5 | 2011-01-23 16:50:33 +0000 | [diff] [blame] | 67 | <h3>Arguments</h3> | 
 | 68 | <dl> | 
| Peter Hinz | 56885f3 | 2011-03-02 22:03:47 +0000 | [diff] [blame] | 69 | <dt><b>context</b> | 
| Andy Green | 6964bb5 | 2011-01-23 16:50:33 +0000 | [diff] [blame] | 70 | <dd>Websocket context | 
 | 71 | </dl> | 
 | 72 | <h3>Description</h3> | 
 | 73 | <blockquote> | 
 | 74 | This function closes any active connections and then frees the | 
 | 75 | context.  After calling this, any further use of the context is | 
 | 76 | undefined. | 
 | 77 | </blockquote> | 
 | 78 | <hr> | 
 | 79 | <h2>libwebsocket_service - Service any pending websocket activity</h2> | 
 | 80 | <i>int</i> | 
 | 81 | <b>libwebsocket_service</b> | 
| Peter Hinz | 56885f3 | 2011-03-02 22:03:47 +0000 | [diff] [blame] | 82 | (<i>struct libwebsocket_context *</i> <b>context</b>, | 
| Andy Green | 6964bb5 | 2011-01-23 16:50:33 +0000 | [diff] [blame] | 83 | <i>int</i> <b>timeout_ms</b>) | 
 | 84 | <h3>Arguments</h3> | 
 | 85 | <dl> | 
| Peter Hinz | 56885f3 | 2011-03-02 22:03:47 +0000 | [diff] [blame] | 86 | <dt><b>context</b> | 
| Andy Green | 6964bb5 | 2011-01-23 16:50:33 +0000 | [diff] [blame] | 87 | <dd>Websocket context | 
 | 88 | <dt><b>timeout_ms</b> | 
 | 89 | <dd>Timeout for poll; 0 means return immediately if nothing needed | 
 | 90 | service otherwise block and service immediately, returning | 
 | 91 | after the timeout if nothing needed service. | 
 | 92 | </dl> | 
 | 93 | <h3>Description</h3> | 
 | 94 | <blockquote> | 
 | 95 | This function deals with any pending websocket traffic, for three | 
 | 96 | kinds of event.  It handles these events on both server and client | 
 | 97 | types of connection the same. | 
 | 98 | <p> | 
 | 99 | 1) Accept new connections to our context's server | 
 | 100 | <p> | 
 | 101 | 2) Perform pending broadcast writes initiated from other forked | 
 | 102 | processes (effectively serializing asynchronous broadcasts) | 
 | 103 | <p> | 
 | 104 | 3) Call the receive callback for incoming frame data received by | 
 | 105 | server or client connections. | 
 | 106 | <p> | 
 | 107 | You need to call this service function periodically to all the above | 
 | 108 | functions to happen; if your application is single-threaded you can | 
 | 109 | just call it in your main event loop. | 
 | 110 | <p> | 
 | 111 | Alternatively you can fork a new process that asynchronously handles | 
 | 112 | calling this service in a loop.  In that case you are happy if this | 
 | 113 | call blocks your thread until it needs to take care of something and | 
 | 114 | would call it with a large nonzero timeout.  Your loop then takes no | 
 | 115 | CPU while there is nothing happening. | 
 | 116 | <p> | 
 | 117 | If you are calling it in a single-threaded app, you don't want it to | 
 | 118 | wait around blocking other things in your loop from happening, so you | 
 | 119 | would call it with a timeout_ms of 0, so it returns immediately if | 
 | 120 | nothing is pending, or as soon as it services whatever was pending. | 
 | 121 | </blockquote> | 
 | 122 | <hr> | 
| Andy Green | 32375b7 | 2011-02-19 08:32:53 +0000 | [diff] [blame] | 123 | <h2>libwebsocket_callback_on_writable - Request a callback when this socket becomes able to be written to without blocking</h2> | 
| Andy Green | 90c7cbc | 2011-01-27 06:26:52 +0000 | [diff] [blame] | 124 | <i>int</i> | 
 | 125 | <b>libwebsocket_callback_on_writable</b> | 
| Peter Hinz | 56885f3 | 2011-03-02 22:03:47 +0000 | [diff] [blame] | 126 | (<i>struct libwebsocket_context *</i> <b>context</b>, | 
| Andy Green | 62c54d2 | 2011-02-14 09:14:25 +0000 | [diff] [blame] | 127 | <i>struct libwebsocket *</i> <b>wsi</b>) | 
| Andy Green | 90c7cbc | 2011-01-27 06:26:52 +0000 | [diff] [blame] | 128 | <h3>Arguments</h3> | 
 | 129 | <dl> | 
| Peter Hinz | 56885f3 | 2011-03-02 22:03:47 +0000 | [diff] [blame] | 130 | <dt><b>context</b> | 
| Andy Green | 32375b7 | 2011-02-19 08:32:53 +0000 | [diff] [blame] | 131 | <dd>libwebsockets context | 
| Andy Green | 90c7cbc | 2011-01-27 06:26:52 +0000 | [diff] [blame] | 132 | <dt><b>wsi</b> | 
 | 133 | <dd>Websocket connection instance to get callback for | 
 | 134 | </dl> | 
 | 135 | <hr> | 
 | 136 | <h2>libwebsocket_callback_on_writable_all_protocol - Request a callback for all connections using the given protocol when it becomes possible to write to each socket without blocking in turn.</h2> | 
 | 137 | <i>int</i> | 
 | 138 | <b>libwebsocket_callback_on_writable_all_protocol</b> | 
 | 139 | (<i>const struct libwebsocket_protocols *</i> <b>protocol</b>) | 
 | 140 | <h3>Arguments</h3> | 
 | 141 | <dl> | 
 | 142 | <dt><b>protocol</b> | 
 | 143 | <dd>Protocol whose connections will get callbacks | 
 | 144 | </dl> | 
 | 145 | <hr> | 
| Andy Green | be93fef | 2011-02-14 20:25:43 +0000 | [diff] [blame] | 146 | <h2>libwebsocket_set_timeout - marks the wsi as subject to a timeout</h2> | 
 | 147 | <i>void</i> | 
 | 148 | <b>libwebsocket_set_timeout</b> | 
 | 149 | (<i>struct libwebsocket *</i> <b>wsi</b>, | 
 | 150 | <i>enum pending_timeout</i> <b>reason</b>, | 
 | 151 | <i>int</i> <b>secs</b>) | 
 | 152 | <h3>Arguments</h3> | 
 | 153 | <dl> | 
 | 154 | <dt><b>wsi</b> | 
 | 155 | <dd>Websocket connection instance | 
 | 156 | <dt><b>reason</b> | 
 | 157 | <dd>timeout reason | 
 | 158 | <dt><b>secs</b> | 
 | 159 | <dd>how many seconds | 
 | 160 | </dl> | 
 | 161 | <h3>Description</h3> | 
 | 162 | <blockquote> | 
 | 163 | <p> | 
 | 164 | You will not need this unless you are doing something special | 
 | 165 | </blockquote> | 
 | 166 | <hr> | 
| Andy Green | a6cbece | 2011-01-27 20:06:03 +0000 | [diff] [blame] | 167 | <h2>libwebsocket_get_socket_fd - returns the socket file descriptor</h2> | 
 | 168 | <i>int</i> | 
 | 169 | <b>libwebsocket_get_socket_fd</b> | 
 | 170 | (<i>struct libwebsocket *</i> <b>wsi</b>) | 
 | 171 | <h3>Arguments</h3> | 
 | 172 | <dl> | 
 | 173 | <dt><b>wsi</b> | 
 | 174 | <dd>Websocket connection instance | 
 | 175 | </dl> | 
 | 176 | <h3>Description</h3> | 
 | 177 | <blockquote> | 
 | 178 | <p> | 
 | 179 | You will not need this unless you are doing something special | 
 | 180 | </blockquote> | 
 | 181 | <hr> | 
| Andy Green | 90c7cbc | 2011-01-27 06:26:52 +0000 | [diff] [blame] | 182 | <h2>libwebsocket_rx_flow_control - Enable and disable socket servicing for receieved packets.</h2> | 
 | 183 | <i>int</i> | 
 | 184 | <b>libwebsocket_rx_flow_control</b> | 
 | 185 | (<i>struct libwebsocket *</i> <b>wsi</b>, | 
 | 186 | <i>int</i> <b>enable</b>) | 
 | 187 | <h3>Arguments</h3> | 
 | 188 | <dl> | 
 | 189 | <dt><b>wsi</b> | 
 | 190 | <dd>Websocket connection instance to get callback for | 
 | 191 | <dt><b>enable</b> | 
 | 192 | <dd>0 = disable read servicing for this connection, 1 = enable | 
 | 193 | </dl> | 
 | 194 | <h3>Description</h3> | 
 | 195 | <blockquote> | 
 | 196 | <p> | 
 | 197 | If the output side of a server process becomes choked, this allows flow | 
 | 198 | control for the input side. | 
 | 199 | </blockquote> | 
 | 200 | <hr> | 
| Andy Green | 2ac5a6f | 2011-01-28 10:00:18 +0000 | [diff] [blame] | 201 | <h2>libwebsocket_canonical_hostname - returns this host's hostname</h2> | 
 | 202 | <i>const char *</i> | 
 | 203 | <b>libwebsocket_canonical_hostname</b> | 
| Peter Hinz | 56885f3 | 2011-03-02 22:03:47 +0000 | [diff] [blame] | 204 | (<i>struct libwebsocket_context *</i> <b>context</b>) | 
| Andy Green | 2ac5a6f | 2011-01-28 10:00:18 +0000 | [diff] [blame] | 205 | <h3>Arguments</h3> | 
 | 206 | <dl> | 
| Peter Hinz | 56885f3 | 2011-03-02 22:03:47 +0000 | [diff] [blame] | 207 | <dt><b>context</b> | 
| Andy Green | 2ac5a6f | 2011-01-28 10:00:18 +0000 | [diff] [blame] | 208 | <dd>Websocket context | 
 | 209 | </dl> | 
 | 210 | <h3>Description</h3> | 
 | 211 | <blockquote> | 
 | 212 | <p> | 
 | 213 | This is typically used by client code to fill in the host parameter | 
 | 214 | when making a client connection.  You can only call it after the context | 
 | 215 | has been created. | 
 | 216 | </blockquote> | 
 | 217 | <hr> | 
| Andy Green | 4739e5c | 2011-01-22 12:51:57 +0000 | [diff] [blame] | 218 | <h2>libwebsocket_create_context - Create the websocket handler</h2> | 
| Andy Green | e92cd17 | 2011-01-19 13:11:55 +0000 | [diff] [blame] | 219 | <i>struct libwebsocket_context *</i> | 
| Andy Green | 4739e5c | 2011-01-22 12:51:57 +0000 | [diff] [blame] | 220 | <b>libwebsocket_create_context</b> | 
| Andy Green | 62a1293 | 2010-11-03 11:19:23 +0000 | [diff] [blame] | 221 | (<i>int</i> <b>port</b>, | 
| Peter Hinz | 56885f3 | 2011-03-02 22:03:47 +0000 | [diff] [blame] | 222 | <i>const char *</i> <b>interf</b>, | 
| Andy Green | b45993c | 2010-12-18 15:13:50 +0000 | [diff] [blame] | 223 | <i>struct libwebsocket_protocols *</i> <b>protocols</b>, | 
| Andy Green | d6e0911 | 2011-03-05 16:12:15 +0000 | [diff] [blame] | 224 | <i>struct libwebsocket_extension *</i> <b>extensions</b>, | 
| Andy Green | 3faa9c7 | 2010-11-08 17:03:03 +0000 | [diff] [blame] | 225 | <i>const char *</i> <b>ssl_cert_filepath</b>, | 
 | 226 | <i>const char *</i> <b>ssl_private_key_filepath</b>, | 
 | 227 | <i>int</i> <b>gid</b>, | 
| Andy Green | 8014b29 | 2011-01-30 20:57:25 +0000 | [diff] [blame] | 228 | <i>int</i> <b>uid</b>, | 
 | 229 | <i>unsigned int</i> <b>options</b>) | 
| Andy Green | 62a1293 | 2010-11-03 11:19:23 +0000 | [diff] [blame] | 230 | <h3>Arguments</h3> | 
 | 231 | <dl> | 
 | 232 | <dt><b>port</b> | 
| Andy Green | 4739e5c | 2011-01-22 12:51:57 +0000 | [diff] [blame] | 233 | <dd>Port to listen on... you can use 0 to suppress listening on | 
 | 234 | any port, that's what you want if you are not running a | 
 | 235 | websocket server at all but just using it as a client | 
| Peter Hinz | 56885f3 | 2011-03-02 22:03:47 +0000 | [diff] [blame] | 236 | <dt><b>interf</b> | 
| Andy Green | 32375b7 | 2011-02-19 08:32:53 +0000 | [diff] [blame] | 237 | <dd>NULL to bind the listen socket to all interfaces, or the | 
 | 238 | interface name, eg, "eth2" | 
| Andy Green | 4f3943a | 2010-11-12 10:44:16 +0000 | [diff] [blame] | 239 | <dt><b>protocols</b> | 
 | 240 | <dd>Array of structures listing supported protocols and a protocol- | 
 | 241 | specific callback for each one.  The list is ended with an | 
 | 242 | entry that has a NULL callback pointer. | 
| Andy Green | b45993c | 2010-12-18 15:13:50 +0000 | [diff] [blame] | 243 | It's not const because we write the owning_server member | 
| Andy Green | c511482 | 2011-03-06 10:29:35 +0000 | [diff] [blame] | 244 | <dt><b>extensions</b> | 
 | 245 | <dd>NULL or array of libwebsocket_extension structs listing the | 
 | 246 | extensions this context supports | 
| Andy Green | 3faa9c7 | 2010-11-08 17:03:03 +0000 | [diff] [blame] | 247 | <dt><b>ssl_cert_filepath</b> | 
 | 248 | <dd>If libwebsockets was compiled to use ssl, and you want | 
 | 249 | to listen using SSL, set to the filepath to fetch the | 
 | 250 | server cert from, otherwise NULL for unencrypted | 
 | 251 | <dt><b>ssl_private_key_filepath</b> | 
 | 252 | <dd>filepath to private key if wanting SSL mode, | 
 | 253 | else ignored | 
 | 254 | <dt><b>gid</b> | 
 | 255 | <dd>group id to change to after setting listen socket, or -1. | 
 | 256 | <dt><b>uid</b> | 
 | 257 | <dd>user id to change to after setting listen socket, or -1. | 
| Andy Green | bfb051f | 2011-02-09 08:49:14 +0000 | [diff] [blame] | 258 | <dt><b>options</b> | 
 | 259 | <dd>0, or LWS_SERVER_OPTION_DEFEAT_CLIENT_MASK | 
| Andy Green | 62a1293 | 2010-11-03 11:19:23 +0000 | [diff] [blame] | 260 | </dl> | 
 | 261 | <h3>Description</h3> | 
 | 262 | <blockquote> | 
| Andy Green | 47943ae | 2010-11-12 11:15:49 +0000 | [diff] [blame] | 263 | This function creates the listening socket and takes care | 
| Andy Green | 62a1293 | 2010-11-03 11:19:23 +0000 | [diff] [blame] | 264 | of all initialization in one step. | 
 | 265 | <p> | 
| Andy Green | e92cd17 | 2011-01-19 13:11:55 +0000 | [diff] [blame] | 266 | After initialization, it returns a struct libwebsocket_context * that | 
 | 267 | represents this server.  After calling, user code needs to take care | 
 | 268 | of calling <b>libwebsocket_service</b> with the context pointer to get the | 
 | 269 | server's sockets serviced.  This can be done in the same process context | 
 | 270 | or a forked process, or another thread, | 
| Andy Green | 47943ae | 2010-11-12 11:15:49 +0000 | [diff] [blame] | 271 | <p> | 
 | 272 | The protocol callback functions are called for a handful of events | 
 | 273 | including http requests coming in, websocket connections becoming | 
| Andy Green | 62a1293 | 2010-11-03 11:19:23 +0000 | [diff] [blame] | 274 | established, and data arriving; it's also called periodically to allow | 
 | 275 | async transmission. | 
 | 276 | <p> | 
| Andy Green | 47943ae | 2010-11-12 11:15:49 +0000 | [diff] [blame] | 277 | HTTP requests are sent always to the FIRST protocol in <tt><b>protocol</b></tt>, since | 
 | 278 | at that time websocket protocol has not been negotiated.  Other | 
 | 279 | protocols after the first one never see any HTTP callack activity. | 
 | 280 | <p> | 
| Andy Green | 62a1293 | 2010-11-03 11:19:23 +0000 | [diff] [blame] | 281 | The server created is a simple http server by default; part of the | 
 | 282 | websocket standard is upgrading this http connection to a websocket one. | 
 | 283 | <p> | 
 | 284 | This allows the same server to provide files like scripts and favicon / | 
 | 285 | images or whatever over http and dynamic data over websockets all in | 
 | 286 | one place; they're all handled in the user callback. | 
 | 287 | </blockquote> | 
 | 288 | <hr> | 
| Andy Green | e92cd17 | 2011-01-19 13:11:55 +0000 | [diff] [blame] | 289 | <h2>libwebsockets_fork_service_loop - Optional helper function forks off a process for the websocket server loop. You don't have to use this but if not, you have to make sure you are calling libwebsocket_service periodically to service the websocket traffic</h2> | 
 | 290 | <i>int</i> | 
 | 291 | <b>libwebsockets_fork_service_loop</b> | 
| Peter Hinz | 56885f3 | 2011-03-02 22:03:47 +0000 | [diff] [blame] | 292 | (<i>struct libwebsocket_context *</i> <b>context</b>) | 
| Andy Green | e92cd17 | 2011-01-19 13:11:55 +0000 | [diff] [blame] | 293 | <h3>Arguments</h3> | 
 | 294 | <dl> | 
| Peter Hinz | 56885f3 | 2011-03-02 22:03:47 +0000 | [diff] [blame] | 295 | <dt><b>context</b> | 
| Andy Green | e92cd17 | 2011-01-19 13:11:55 +0000 | [diff] [blame] | 296 | <dd>server context returned by creation function | 
 | 297 | </dl> | 
 | 298 | <hr> | 
| Andy Green | b45993c | 2010-12-18 15:13:50 +0000 | [diff] [blame] | 299 | <h2>libwebsockets_get_protocol - Returns a protocol pointer from a websocket connection.</h2> | 
 | 300 | <i>const struct libwebsocket_protocols *</i> | 
 | 301 | <b>libwebsockets_get_protocol</b> | 
 | 302 | (<i>struct libwebsocket *</i> <b>wsi</b>) | 
 | 303 | <h3>Arguments</h3> | 
 | 304 | <dl> | 
 | 305 | <dt><b>wsi</b> | 
 | 306 | <dd>pointer to struct websocket you want to know the protocol of | 
 | 307 | </dl> | 
 | 308 | <h3>Description</h3> | 
 | 309 | <blockquote> | 
 | 310 | <p> | 
 | 311 | This is useful to get the protocol to broadcast back to from inside | 
 | 312 | the callback. | 
 | 313 | </blockquote> | 
 | 314 | <hr> | 
| Andy Green | e92cd17 | 2011-01-19 13:11:55 +0000 | [diff] [blame] | 315 | <h2>libwebsockets_broadcast - Sends a buffer to the callback for all active connections of the given protocol.</h2> | 
| Andy Green | b45993c | 2010-12-18 15:13:50 +0000 | [diff] [blame] | 316 | <i>int</i> | 
 | 317 | <b>libwebsockets_broadcast</b> | 
 | 318 | (<i>const struct libwebsocket_protocols *</i> <b>protocol</b>, | 
 | 319 | <i>unsigned char *</i> <b>buf</b>, | 
 | 320 | <i>size_t</i> <b>len</b>) | 
 | 321 | <h3>Arguments</h3> | 
 | 322 | <dl> | 
 | 323 | <dt><b>protocol</b> | 
 | 324 | <dd>pointer to the protocol you will broadcast to all members of | 
 | 325 | <dt><b>buf</b> | 
 | 326 | <dd>buffer containing the data to be broadcase.  NOTE: this has to be | 
 | 327 | allocated with LWS_SEND_BUFFER_PRE_PADDING valid bytes before | 
 | 328 | the pointer and LWS_SEND_BUFFER_POST_PADDING afterwards in the | 
 | 329 | case you are calling this function from callback context. | 
 | 330 | <dt><b>len</b> | 
 | 331 | <dd>length of payload data in buf, starting from buf. | 
 | 332 | </dl> | 
 | 333 | <h3>Description</h3> | 
 | 334 | <blockquote> | 
 | 335 | This function allows bulk sending of a packet to every connection using | 
 | 336 | the given protocol.  It does not send the data directly; instead it calls | 
 | 337 | the callback with a reason type of LWS_CALLBACK_BROADCAST.  If the callback | 
 | 338 | wants to actually send the data for that connection, the callback itself | 
 | 339 | should call <b>libwebsocket_write</b>. | 
 | 340 | <p> | 
 | 341 | <b>libwebsockets_broadcast</b> can be called from another fork context without | 
 | 342 | having to take any care about data visibility between the processes, it'll | 
 | 343 | "just work". | 
 | 344 | </blockquote> | 
 | 345 | <hr> | 
| Andy Green | 62a1293 | 2010-11-03 11:19:23 +0000 | [diff] [blame] | 346 | <h2>libwebsocket_write - Apply protocol then write data to client</h2> | 
 | 347 | <i>int</i> | 
 | 348 | <b>libwebsocket_write</b> | 
 | 349 | (<i>struct libwebsocket *</i> <b>wsi</b>, | 
 | 350 | <i>unsigned char *</i> <b>buf</b>, | 
 | 351 | <i>size_t</i> <b>len</b>, | 
 | 352 | <i>enum libwebsocket_write_protocol</i> <b>protocol</b>) | 
 | 353 | <h3>Arguments</h3> | 
 | 354 | <dl> | 
 | 355 | <dt><b>wsi</b> | 
 | 356 | <dd>Websocket instance (available from user callback) | 
 | 357 | <dt><b>buf</b> | 
 | 358 | <dd>The data to send.  For data being sent on a websocket | 
 | 359 | connection (ie, not default http), this buffer MUST have | 
 | 360 | LWS_SEND_BUFFER_PRE_PADDING bytes valid BEFORE the pointer | 
 | 361 | and an additional LWS_SEND_BUFFER_POST_PADDING bytes valid | 
 | 362 | in the buffer after (buf + len).  This is so the protocol | 
 | 363 | header and trailer data can be added in-situ. | 
 | 364 | <dt><b>len</b> | 
 | 365 | <dd>Count of the data bytes in the payload starting from buf | 
 | 366 | <dt><b>protocol</b> | 
 | 367 | <dd>Use LWS_WRITE_HTTP to reply to an http connection, and one | 
 | 368 | of LWS_WRITE_BINARY or LWS_WRITE_TEXT to send appropriate | 
 | 369 | data on a websockets connection.  Remember to allow the extra | 
 | 370 | bytes before and after buf if LWS_WRITE_BINARY or LWS_WRITE_TEXT | 
 | 371 | are used. | 
 | 372 | </dl> | 
 | 373 | <h3>Description</h3> | 
 | 374 | <blockquote> | 
 | 375 | This function provides the way to issue data back to the client | 
 | 376 | for both http and websocket protocols. | 
 | 377 | <p> | 
 | 378 | In the case of sending using websocket protocol, be sure to allocate | 
 | 379 | valid storage before and after buf as explained above.  This scheme | 
 | 380 | allows maximum efficiency of sending data and protocol in a single | 
 | 381 | packet while not burdening the user code with any protocol knowledge. | 
 | 382 | </blockquote> | 
 | 383 | <hr> | 
 | 384 | <h2>libwebsockets_serve_http_file - Send a file back to the client using http</h2> | 
 | 385 | <i>int</i> | 
 | 386 | <b>libwebsockets_serve_http_file</b> | 
 | 387 | (<i>struct libwebsocket *</i> <b>wsi</b>, | 
 | 388 | <i>const char *</i> <b>file</b>, | 
 | 389 | <i>const char *</i> <b>content_type</b>) | 
 | 390 | <h3>Arguments</h3> | 
 | 391 | <dl> | 
 | 392 | <dt><b>wsi</b> | 
 | 393 | <dd>Websocket instance (available from user callback) | 
 | 394 | <dt><b>file</b> | 
 | 395 | <dd>The file to issue over http | 
 | 396 | <dt><b>content_type</b> | 
 | 397 | <dd>The http content type, eg, text/html | 
 | 398 | </dl> | 
 | 399 | <h3>Description</h3> | 
 | 400 | <blockquote> | 
 | 401 | This function is intended to be called from the callback in response | 
 | 402 | to http requests from the client.  It allows the callback to issue | 
 | 403 | local files down the http link in a single step. | 
 | 404 | </blockquote> | 
 | 405 | <hr> | 
| Andy Green | 38e57bb | 2011-01-19 12:20:27 +0000 | [diff] [blame] | 406 | <h2>libwebsockets_remaining_packet_payload - Bytes to come before "overall" rx packet is complete</h2> | 
 | 407 | <i>size_t</i> | 
 | 408 | <b>libwebsockets_remaining_packet_payload</b> | 
 | 409 | (<i>struct libwebsocket *</i> <b>wsi</b>) | 
 | 410 | <h3>Arguments</h3> | 
 | 411 | <dl> | 
 | 412 | <dt><b>wsi</b> | 
 | 413 | <dd>Websocket instance (available from user callback) | 
 | 414 | </dl> | 
 | 415 | <h3>Description</h3> | 
 | 416 | <blockquote> | 
 | 417 | This function is intended to be called from the callback if the | 
 | 418 | user code is interested in "complete packets" from the client. | 
 | 419 | libwebsockets just passes through payload as it comes and issues a buffer | 
 | 420 | additionally when it hits a built-in limit.  The LWS_CALLBACK_RECEIVE | 
 | 421 | callback handler can use this API to find out if the buffer it has just | 
 | 422 | been given is the last piece of a "complete packet" from the client -- | 
 | 423 | when that is the case <b>libwebsockets_remaining_packet_payload</b> will return | 
 | 424 | 0. | 
 | 425 | <p> | 
 | 426 | Many protocols won't care becuse their packets are always small. | 
 | 427 | </blockquote> | 
 | 428 | <hr> | 
| Andy Green | 90c7cbc | 2011-01-27 06:26:52 +0000 | [diff] [blame] | 429 | <h2>libwebsocket_client_connect - Connect to another websocket server</h2> | 
 | 430 | <i>struct libwebsocket *</i> | 
 | 431 | <b>libwebsocket_client_connect</b> | 
| Peter Hinz | 56885f3 | 2011-03-02 22:03:47 +0000 | [diff] [blame] | 432 | (<i>struct libwebsocket_context *</i> <b>context</b>, | 
| Andy Green | 90c7cbc | 2011-01-27 06:26:52 +0000 | [diff] [blame] | 433 | <i>const char *</i> <b>address</b>, | 
 | 434 | <i>int</i> <b>port</b>, | 
 | 435 | <i>int</i> <b>ssl_connection</b>, | 
 | 436 | <i>const char *</i> <b>path</b>, | 
 | 437 | <i>const char *</i> <b>host</b>, | 
 | 438 | <i>const char *</i> <b>origin</b>, | 
| Andy Green | bfb051f | 2011-02-09 08:49:14 +0000 | [diff] [blame] | 439 | <i>const char *</i> <b>protocol</b>, | 
 | 440 | <i>int</i> <b>ietf_version_or_minus_one</b>) | 
| Andy Green | 90c7cbc | 2011-01-27 06:26:52 +0000 | [diff] [blame] | 441 | <h3>Arguments</h3> | 
 | 442 | <dl> | 
| Peter Hinz | 56885f3 | 2011-03-02 22:03:47 +0000 | [diff] [blame] | 443 | <dt><b>context</b> | 
| Andy Green | 90c7cbc | 2011-01-27 06:26:52 +0000 | [diff] [blame] | 444 | <dd>Websocket context | 
 | 445 | <dt><b>address</b> | 
 | 446 | <dd>Remote server address, eg, "myserver.com" | 
 | 447 | <dt><b>port</b> | 
 | 448 | <dd>Port to connect to on the remote server, eg, 80 | 
 | 449 | <dt><b>ssl_connection</b> | 
 | 450 | <dd>0 = ws://, 1 = wss:// encrypted, 2 = wss:// allow self | 
 | 451 | signed certs | 
 | 452 | <dt><b>path</b> | 
 | 453 | <dd>Websocket path on server | 
 | 454 | <dt><b>host</b> | 
 | 455 | <dd>Hostname on server | 
 | 456 | <dt><b>origin</b> | 
 | 457 | <dd>Socket origin name | 
 | 458 | <dt><b>protocol</b> | 
 | 459 | <dd>Comma-separated list of protocols being asked for from | 
 | 460 | the server, or just one.  The server will pick the one it | 
 | 461 | likes best. | 
| Andy Green | bfb051f | 2011-02-09 08:49:14 +0000 | [diff] [blame] | 462 | <dt><b>ietf_version_or_minus_one</b> | 
 | 463 | <dd>-1 to ask to connect using the default, latest | 
 | 464 | protocol supported, or the specific protocol ordinal | 
| Andy Green | 90c7cbc | 2011-01-27 06:26:52 +0000 | [diff] [blame] | 465 | </dl> | 
 | 466 | <h3>Description</h3> | 
 | 467 | <blockquote> | 
 | 468 | This function creates a connection to a remote server | 
 | 469 | </blockquote> | 
 | 470 | <hr> | 
| Andy Green | 8f037e4 | 2010-12-19 22:13:26 +0000 | [diff] [blame] | 471 | <h2>callback - User server actions</h2> | 
 | 472 | <i>int</i> | 
 | 473 | <b>callback</b> | 
| Darin Willits | c19456f | 2011-02-14 17:52:39 +0000 | [diff] [blame] | 474 | (<i>struct libwebsocket_context *</i> <b>context</b>, | 
| Andy Green | 62c54d2 | 2011-02-14 09:14:25 +0000 | [diff] [blame] | 475 | <i>struct libwebsocket *</i> <b>wsi</b>, | 
| Andy Green | 8f037e4 | 2010-12-19 22:13:26 +0000 | [diff] [blame] | 476 | <i>enum libwebsocket_callback_reasons</i> <b>reason</b>, | 
 | 477 | <i>void *</i> <b>user</b>, | 
 | 478 | <i>void *</i> <b>in</b>, | 
 | 479 | <i>size_t</i> <b>len</b>) | 
 | 480 | <h3>Arguments</h3> | 
 | 481 | <dl> | 
| Andy Green | 32375b7 | 2011-02-19 08:32:53 +0000 | [diff] [blame] | 482 | <dt><b>context</b> | 
 | 483 | <dd>Websockets context | 
| Andy Green | 8f037e4 | 2010-12-19 22:13:26 +0000 | [diff] [blame] | 484 | <dt><b>wsi</b> | 
 | 485 | <dd>Opaque websocket instance pointer | 
 | 486 | <dt><b>reason</b> | 
 | 487 | <dd>The reason for the call | 
 | 488 | <dt><b>user</b> | 
 | 489 | <dd>Pointer to per-session user data allocated by library | 
 | 490 | <dt><b>in</b> | 
 | 491 | <dd>Pointer used for some callback reasons | 
 | 492 | <dt><b>len</b> | 
 | 493 | <dd>Length set for some callback reasons | 
 | 494 | </dl> | 
 | 495 | <h3>Description</h3> | 
 | 496 | <blockquote> | 
 | 497 | This callback is the way the user controls what is served.  All the | 
 | 498 | protocol detail is hidden and handled by the library. | 
 | 499 | <p> | 
 | 500 | For each connection / session there is user data allocated that is | 
 | 501 | pointed to by "user".  You set the size of this user data area when | 
 | 502 | the library is initialized with libwebsocket_create_server. | 
 | 503 | <p> | 
 | 504 | You get an opportunity to initialize user data when called back with | 
 | 505 | LWS_CALLBACK_ESTABLISHED reason. | 
 | 506 | </blockquote> | 
 | 507 | <h3>LWS_CALLBACK_ESTABLISHED</h3> | 
 | 508 | <blockquote> | 
| Andy Green | 90c7cbc | 2011-01-27 06:26:52 +0000 | [diff] [blame] | 509 | after the server completes a handshake with | 
 | 510 | an incoming client | 
 | 511 | </blockquote> | 
 | 512 | <h3>LWS_CALLBACK_CLIENT_ESTABLISHED</h3> | 
 | 513 | <blockquote> | 
 | 514 | after your client connection completed | 
 | 515 | a handshake with the remote server | 
| Andy Green | 8f037e4 | 2010-12-19 22:13:26 +0000 | [diff] [blame] | 516 | </blockquote> | 
 | 517 | <h3>LWS_CALLBACK_CLOSED</h3> | 
 | 518 | <blockquote> | 
 | 519 | when the websocket session ends | 
 | 520 | </blockquote> | 
 | 521 | <h3>LWS_CALLBACK_BROADCAST</h3> | 
 | 522 | <blockquote> | 
 | 523 | signal to send to client (you would use | 
 | 524 | <b>libwebsocket_write</b> taking care about the | 
 | 525 | special buffer requirements | 
 | 526 | </blockquote> | 
 | 527 | <h3>LWS_CALLBACK_RECEIVE</h3> | 
 | 528 | <blockquote> | 
| Andy Green | 90c7cbc | 2011-01-27 06:26:52 +0000 | [diff] [blame] | 529 | data has appeared for this server endpoint from a | 
 | 530 | remote client, it can be found at *in and is | 
 | 531 | len bytes long | 
 | 532 | </blockquote> | 
| Andy Green | a6cbece | 2011-01-27 20:06:03 +0000 | [diff] [blame] | 533 | <h3>LWS_CALLBACK_CLIENT_RECEIVE_PONG</h3> | 
 | 534 | <blockquote> | 
 | 535 | if you elected to see PONG packets, | 
 | 536 | they appear with this callback reason.  PONG | 
 | 537 | packets only exist in 04+ protocol | 
 | 538 | </blockquote> | 
| Andy Green | 90c7cbc | 2011-01-27 06:26:52 +0000 | [diff] [blame] | 539 | <h3>LWS_CALLBACK_CLIENT_RECEIVE</h3> | 
 | 540 | <blockquote> | 
 | 541 | data has appeared from the server for the | 
 | 542 | client connection, it can be found at *in and | 
 | 543 | is len bytes long | 
| Andy Green | 8f037e4 | 2010-12-19 22:13:26 +0000 | [diff] [blame] | 544 | </blockquote> | 
 | 545 | <h3>LWS_CALLBACK_HTTP</h3> | 
 | 546 | <blockquote> | 
 | 547 | an http request has come from a client that is not | 
 | 548 | asking to upgrade the connection to a websocket | 
 | 549 | one.  This is a chance to serve http content, | 
 | 550 | for example, to send a script to the client | 
 | 551 | which will then open the websockets connection. | 
| Andy Green | 7619c47 | 2011-01-23 17:47:08 +0000 | [diff] [blame] | 552 | <tt><b>in</b></tt> points to the URI path requested and | 
| Andy Green | 8f037e4 | 2010-12-19 22:13:26 +0000 | [diff] [blame] | 553 | <b>libwebsockets_serve_http_file</b> makes it very | 
 | 554 | simple to send back a file to the client. | 
 | 555 | </blockquote> | 
| Andy Green | 90c7cbc | 2011-01-27 06:26:52 +0000 | [diff] [blame] | 556 | <h3>LWS_CALLBACK_CLIENT_WRITEABLE</h3> | 
 | 557 | <blockquote> | 
 | 558 | if you call | 
 | 559 | <b>libwebsocket_callback_on_writable</b> on a connection, you will | 
 | 560 | get this callback coming when the connection socket is able to | 
 | 561 | accept another write packet without blocking.  If it already | 
 | 562 | was able to take another packet without blocking, you'll get | 
 | 563 | this callback at the next call to the service loop function. | 
 | 564 | </blockquote> | 
| Andy Green | 0703409 | 2011-02-13 08:37:12 +0000 | [diff] [blame] | 565 | <h3>LWS_CALLBACK_FILTER_NETWORK_CONNECTION</h3> | 
 | 566 | <blockquote> | 
 | 567 | called when a client connects to | 
 | 568 | the server at network level; the connection is accepted but then | 
 | 569 | passed to this callback to decide whether to hang up immediately | 
 | 570 | or not, based on the client IP.  <tt><b>user</b></tt> contains the connection | 
 | 571 | socket's descriptor.  Return non-zero to terminate | 
 | 572 | the connection before sending or receiving anything. | 
 | 573 | Because this happens immediately after the network connection | 
 | 574 | from the client, there's no websocket protocol selected yet so | 
 | 575 | this callback is issued only to protocol 0. | 
 | 576 | </blockquote> | 
| Andy Green | c85619d | 2011-02-13 08:25:26 +0000 | [diff] [blame] | 577 | <h3>LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION</h3> | 
 | 578 | <blockquote> | 
 | 579 | called when the handshake has | 
 | 580 | been received and parsed from the client, but the response is | 
 | 581 | not sent yet.  Return non-zero to disallow the connection. | 
| Andy Green | 0703409 | 2011-02-13 08:37:12 +0000 | [diff] [blame] | 582 | <tt><b>user</b></tt> is a pointer to an array of struct lws_tokens, you can | 
 | 583 | use the header enums lws_token_indexes from libwebsockets.h | 
 | 584 | to check for and read the supported header presence and | 
 | 585 | content before deciding to allow the handshake to proceed or | 
 | 586 | to kill the connection. | 
| Andy Green | 0894bda | 2011-02-19 09:09:11 +0000 | [diff] [blame] | 587 | </blockquote> | 
 | 588 | <h3>LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS</h3> | 
 | 589 | <blockquote> | 
| Andy Green | 6901cb3 | 2011-02-21 08:06:47 +0000 | [diff] [blame] | 590 | if configured for | 
| Andy Green | 0894bda | 2011-02-19 09:09:11 +0000 | [diff] [blame] | 591 | including OpenSSL support, this callback allows your user code | 
 | 592 | to perform extra <b>SSL_CTX_load_verify_locations</b> or similar | 
 | 593 | calls to direct OpenSSL where to find certificates the client | 
 | 594 | can use to confirm the remote server identity.  <tt><b>user</b></tt> is the | 
 | 595 | OpenSSL SSL_CTX* | 
| Andy Green | 6901cb3 | 2011-02-21 08:06:47 +0000 | [diff] [blame] | 596 | </blockquote> | 
 | 597 | <h3>LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS</h3> | 
 | 598 | <blockquote> | 
 | 599 | if configured for | 
 | 600 | including OpenSSL support, this callback allows your user code | 
 | 601 | to load extra certifcates into the server which allow it to | 
 | 602 | verify the validity of certificates returned by clients.  <tt><b>user</b></tt> | 
 | 603 | is the server's OpenSSL SSL_CTX* | 
 | 604 | </blockquote> | 
 | 605 | <h3>LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION</h3> | 
 | 606 | <blockquote> | 
 | 607 | if the | 
 | 608 | libwebsockets context was created with the option | 
 | 609 | LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT, then this | 
 | 610 | callback is generated during OpenSSL verification of the cert | 
 | 611 | sent from the client.  It is sent to protocol[0] callback as | 
 | 612 | no protocol has been negotiated on the connection yet. | 
 | 613 | Notice that the libwebsockets context and wsi are both NULL | 
 | 614 | during this callback.  See | 
 | 615 | </blockquote> | 
 | 616 | <h3>http</h3> | 
 | 617 | <blockquote> | 
 | 618 | //www.openssl.org/docs/ssl/SSL_CTX_set_verify.html | 
 | 619 | to understand more detail about the OpenSSL callback that | 
 | 620 | generates this libwebsockets callback and the meanings of the | 
 | 621 | arguments passed.  In this callback, <tt><b>user</b></tt> is the x509_ctx, | 
 | 622 | <tt><b>in</b></tt> is the ssl pointer and <tt><b>len</b></tt> is preverify_ok | 
 | 623 | Notice that this callback maintains libwebsocket return | 
 | 624 | conventions, return 0 to mean the cert is OK or 1 to fail it. | 
 | 625 | This also means that if you don't handle this callback then | 
 | 626 | the default callback action of returning 0 allows the client | 
 | 627 | certificates. | 
| Andy Green | 385e7ad | 2011-03-01 21:06:02 +0000 | [diff] [blame] | 628 | </blockquote> | 
 | 629 | <h3>LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER</h3> | 
 | 630 | <blockquote> | 
 | 631 | this callback happens | 
 | 632 | when a client handshake is being compiled.  <tt><b>user</b></tt> is NULL, | 
 | 633 | <tt><b>in</b></tt> is a char **, it's pointing to a char * which holds the | 
 | 634 | next location in the header buffer where you can add | 
 | 635 | headers, and <tt><b>len</b></tt> is the remaining space in the header buffer, | 
 | 636 | which is typically some hundreds of bytes.  So, to add a canned | 
 | 637 | cookie, your handler code might look similar to: | 
 | 638 | <p> | 
 | 639 | char **p = (char **)in; | 
 | 640 | <p> | 
 | 641 | if (len < 100) | 
 | 642 | return 1; | 
 | 643 | <p> | 
 | 644 | *p += sprintf(*p, "Cookie: a=b\x0d\x0a"); | 
 | 645 | <p> | 
 | 646 | return 0; | 
 | 647 | <p> | 
 | 648 | Notice if you add anything, you just have to take care about | 
 | 649 | the CRLF on the line you added.  Obviously this callback is | 
 | 650 | optional, if you don't handle it everything is fine. | 
 | 651 | <p> | 
 | 652 | Notice the callback is coming to protocols[0] all the time, | 
 | 653 | because there is no specific protocol handshook yet. | 
| Andy Green | c511482 | 2011-03-06 10:29:35 +0000 | [diff] [blame] | 654 | </blockquote> | 
 | 655 | <h3>LWS_CALLBACK_CONFIRM_EXTENSION_OKAY</h3> | 
 | 656 | <blockquote> | 
 | 657 | When the server handshake code | 
 | 658 | sees that it does support a requested extension, before | 
 | 659 | accepting the extension by additing to the list sent back to | 
 | 660 | the client it gives this callback just to check that it's okay | 
 | 661 | to use that extension.  It calls back to the requested protocol | 
 | 662 | and with <tt><b>in</b></tt> being the extension name, <tt><b>len</b></tt> is 0 and <tt><b>user</b></tt> is | 
 | 663 | valid.  Note though at this time the ESTABLISHED callback hasn't | 
 | 664 | happened yet so if you initialize <tt><b>user</b></tt> content there, <tt><b>user</b></tt> | 
 | 665 | content during this callback might not be useful for anything. | 
 | 666 | Notice this callback comes to protocols[0]. | 
| Andy Green | c6517fa | 2011-03-06 13:15:29 +0000 | [diff] [blame] | 667 | </blockquote> | 
 | 668 | <h3>LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED</h3> | 
 | 669 | <blockquote> | 
 | 670 | When a client | 
 | 671 | connection is being prepared to start a handshake to a server, | 
 | 672 | each supported extension is checked with protocols[0] callback | 
 | 673 | with this reason, giving the user code a chance to suppress the | 
 | 674 | claim to support that extension by returning non-zero.  If | 
 | 675 | unhandled, by default 0 will be returned and the extension | 
 | 676 | support included in the header to the server.  Notice this | 
 | 677 | callback comes to protocols[0]. | 
| Andy Green | c85619d | 2011-02-13 08:25:26 +0000 | [diff] [blame] | 678 | <p> | 
 | 679 | The next four reasons are optional and only need taking care of if you | 
 | 680 | will be integrating libwebsockets sockets into an external polling | 
 | 681 | array. | 
 | 682 | </blockquote> | 
 | 683 | <h3>LWS_CALLBACK_ADD_POLL_FD</h3> | 
 | 684 | <blockquote> | 
 | 685 | libwebsocket deals with its <b>poll</b> loop | 
 | 686 | internally, but in the case you are integrating with another | 
 | 687 | server you will need to have libwebsocket sockets share a | 
 | 688 | polling array with the other server.  This and the other | 
 | 689 | POLL_FD related callbacks let you put your specialized | 
 | 690 | poll array interface code in the callback for protocol 0, the | 
 | 691 | first protocol you support, usually the HTTP protocol in the | 
 | 692 | serving case.  This callback happens when a socket needs to be | 
 | 693 | </blockquote> | 
 | 694 | <h3>added to the polling loop</h3> | 
 | 695 | <blockquote> | 
 | 696 | <tt><b>user</b></tt> contains the fd, and | 
 | 697 | <tt><b>len</b></tt> is the events bitmap (like, POLLIN).  If you are using the | 
 | 698 | internal polling loop (the "service" callback), you can just | 
 | 699 | ignore these callbacks. | 
 | 700 | </blockquote> | 
 | 701 | <h3>LWS_CALLBACK_DEL_POLL_FD</h3> | 
 | 702 | <blockquote> | 
 | 703 | This callback happens when a socket descriptor | 
 | 704 | needs to be removed from an external polling array.  <tt><b>user</b></tt> is | 
 | 705 | the socket desricptor.  If you are using the internal polling | 
 | 706 | loop, you can just ignore it. | 
 | 707 | </blockquote> | 
 | 708 | <h3>LWS_CALLBACK_SET_MODE_POLL_FD</h3> | 
 | 709 | <blockquote> | 
 | 710 | This callback happens when libwebsockets | 
 | 711 | wants to modify the events for the socket descriptor in <tt><b>user</b></tt>. | 
 | 712 | The handler should OR <tt><b>len</b></tt> on to the events member of the pollfd | 
 | 713 | struct for this socket descriptor.  If you are using the | 
 | 714 | internal polling loop, you can just ignore it. | 
 | 715 | </blockquote> | 
 | 716 | <h3>LWS_CALLBACK_CLEAR_MODE_POLL_FD</h3> | 
 | 717 | <blockquote> | 
 | 718 | This callback occurs when libwebsockets | 
 | 719 | wants to modify the events for the socket descriptor in <tt><b>user</b></tt>. | 
 | 720 | The handler should AND ~<tt><b>len</b></tt> on to the events member of the | 
 | 721 | pollfd struct for this socket descriptor.  If you are using the | 
 | 722 | internal polling loop, you can just ignore it. | 
 | 723 | </blockquote> | 
| Andy Green | 8f037e4 | 2010-12-19 22:13:26 +0000 | [diff] [blame] | 724 | <hr> | 
| Andy Green | 57b4e9a | 2011-03-06 13:14:46 +0000 | [diff] [blame] | 725 | <h2>extension_callback - Hooks to allow extensions to operate</h2> | 
 | 726 | <i>int</i> | 
 | 727 | <b>extension_callback</b> | 
 | 728 | (<i>struct libwebsocket_context *</i> <b>context</b>, | 
 | 729 | <i>struct libwebsocket *</i> <b>wsi</b>, | 
 | 730 | <i>enum libwebsocket_callback_reasons</i> <b>reason</b>, | 
 | 731 | <i>void *</i> <b>user</b>, | 
 | 732 | <i>void *</i> <b>in</b>, | 
 | 733 | <i>size_t</i> <b>len</b>) | 
 | 734 | <h3>Arguments</h3> | 
 | 735 | <dl> | 
 | 736 | <dt><b>context</b> | 
 | 737 | <dd>Websockets context | 
 | 738 | <dt><b>wsi</b> | 
 | 739 | <dd>Opaque websocket instance pointer | 
 | 740 | <dt><b>reason</b> | 
 | 741 | <dd>The reason for the call | 
 | 742 | <dt><b>user</b> | 
 | 743 | <dd>Pointer to per-session user data allocated by library | 
 | 744 | <dt><b>in</b> | 
 | 745 | <dd>Pointer used for some callback reasons | 
 | 746 | <dt><b>len</b> | 
 | 747 | <dd>Length set for some callback reasons | 
 | 748 | </dl> | 
 | 749 | <h3>Description</h3> | 
 | 750 | <blockquote> | 
 | 751 | Each extension that is active on a particular connection receives | 
 | 752 | callbacks during the connection lifetime to allow the extension to | 
 | 753 | operate on websocket data and manage itself. | 
 | 754 | <p> | 
 | 755 | Libwebsockets takes care of allocating and freeing "user" memory for | 
 | 756 | each active extension on each connection.  That is what is pointed to | 
 | 757 | by the <tt><b>user</b></tt> parameter. | 
 | 758 | </blockquote> | 
 | 759 | <h3>LWS_EXT_CALLBACK_CONSTRUCT</h3> | 
 | 760 | <blockquote> | 
 | 761 | called when the server has decided to | 
 | 762 | select this extension from the list provided by the client, | 
 | 763 | just before the server will send back the handshake accepting | 
 | 764 | the connection with this extension active.  This gives the | 
 | 765 | extension a chance to initialize its connection context found | 
 | 766 | in <tt><b>user</b></tt>. | 
 | 767 | </blockquote> | 
| Andy Green | 2366b1c | 2011-03-06 13:15:31 +0000 | [diff] [blame] | 768 | <h3>LWS_EXT_CALLBACK_CLIENT_CONSTRUCT</h3> | 
 | 769 | <blockquote> | 
 | 770 | same as LWS_EXT_CALLBACK_CONSTRUCT | 
 | 771 | but called when client is instantiating this extension.  Some | 
 | 772 | extensions will work the same on client and server side and then | 
 | 773 | you can just merge handlers for both CONSTRUCTS. | 
 | 774 | </blockquote> | 
| Andy Green | 57b4e9a | 2011-03-06 13:14:46 +0000 | [diff] [blame] | 775 | <h3>LWS_EXT_CALLBACK_DESTROY</h3> | 
 | 776 | <blockquote> | 
 | 777 | called when the connection the extension was | 
 | 778 | being used on is about to be closed and deallocated.  It's the | 
 | 779 | last chance for the extension to deallocate anything it has | 
 | 780 | allocated in the user data (pointed to by <tt><b>user</b></tt>) before the | 
| Andy Green | 2366b1c | 2011-03-06 13:15:31 +0000 | [diff] [blame] | 781 | user data is deleted.  This same callback is used whether you | 
 | 782 | are in client or server instantiation context. | 
| Andy Green | 57b4e9a | 2011-03-06 13:14:46 +0000 | [diff] [blame] | 783 | </blockquote> | 
 | 784 | <h3>LWS_EXT_CALLBACK_PACKET_RX_PREPARSE</h3> | 
 | 785 | <blockquote> | 
 | 786 | when this extension was active on | 
 | 787 | a connection, and a packet of data arrived at the connection, | 
 | 788 | it is passed to this callback to give the extension a chance to | 
 | 789 | change the data, eg, decompress it.  <tt><b>user</b></tt> is pointing to the | 
 | 790 | extension's private connection context data, <tt><b>in</b></tt> is pointing | 
 | 791 | to an lws_tokens struct, it consists of a char * pointer called | 
 | 792 | token, and an int called token_len.  At entry, these are | 
 | 793 | set to point to the received buffer and set to the content | 
 | 794 | length.  If the extension will grow the content, it should use | 
 | 795 | a new buffer allocated in its private user context data and | 
 | 796 | set the pointed-to lws_tokens members to point to its buffer. | 
 | 797 | </blockquote> | 
 | 798 | <h3>LWS_EXT_CALLBACK_PACKET_TX_PRESEND</h3> | 
 | 799 | <blockquote> | 
 | 800 | this works the same way as | 
 | 801 | LWS_EXT_CALLBACK_PACKET_RX_PREPARSE above, except it gives the | 
 | 802 | extension a chance to change websocket data just before it will | 
 | 803 | be sent out.  Using the same lws_token pointer scheme in <tt><b>in</b></tt>, | 
 | 804 | the extension can change the buffer and the length to be | 
 | 805 | transmitted how it likes.  Again if it wants to grow the | 
 | 806 | buffer safely, it should copy the data into its own buffer and | 
 | 807 | set the lws_tokens token pointer to it. | 
 | 808 | </blockquote> | 
 | 809 | <hr> | 
| Andy Green | 4f3943a | 2010-11-12 10:44:16 +0000 | [diff] [blame] | 810 | <h2>struct libwebsocket_protocols - List of protocols and handlers server supports.</h2> | 
 | 811 | <b>struct libwebsocket_protocols</b> {<br> | 
 | 812 |     <i>const char *</i> <b>name</b>;<br> | 
| Darin Willits | c19456f | 2011-02-14 17:52:39 +0000 | [diff] [blame] | 813 |     <i>int (*</i><b>callback</b>) <i>(struct libwebsocket_context * context,struct libwebsocket *wsi,enum libwebsocket_callback_reasons reason, void *user,void *in, size_t len)</i>;<br> | 
| Andy Green | 4f3943a | 2010-11-12 10:44:16 +0000 | [diff] [blame] | 814 |     <i>size_t</i> <b>per_session_data_size</b>;<br> | 
| Andy Green | b45993c | 2010-12-18 15:13:50 +0000 | [diff] [blame] | 815 |     <i>struct libwebsocket_context *</i> <b>owning_server</b>;<br> | 
 | 816 |     <i>int</i> <b>broadcast_socket_port</b>;<br> | 
 | 817 |     <i>int</i> <b>broadcast_socket_user_fd</b>;<br> | 
 | 818 |     <i>int</i> <b>protocol_index</b>;<br> | 
| Andy Green | 4f3943a | 2010-11-12 10:44:16 +0000 | [diff] [blame] | 819 | };<br> | 
 | 820 | <h3>Members</h3> | 
 | 821 | <dl> | 
 | 822 | <dt><b>name</b> | 
 | 823 | <dd>Protocol name that must match the one given in the client | 
 | 824 | Javascript new WebSocket(url, 'protocol') name | 
 | 825 | <dt><b>callback</b> | 
 | 826 | <dd>The service callback used for this protocol.  It allows the | 
 | 827 | service action for an entire protocol to be encapsulated in | 
 | 828 | the protocol-specific callback | 
 | 829 | <dt><b>per_session_data_size</b> | 
 | 830 | <dd>Each new connection using this protocol gets | 
 | 831 | this much memory allocated on connection establishment and | 
 | 832 | freed on connection takedown.  A pointer to this per-connection | 
 | 833 | allocation is passed into the callback in the 'user' parameter | 
| Andy Green | b45993c | 2010-12-18 15:13:50 +0000 | [diff] [blame] | 834 | <dt><b>owning_server</b> | 
 | 835 | <dd>the server init call fills in this opaque pointer when | 
 | 836 | registering this protocol with the server. | 
 | 837 | <dt><b>broadcast_socket_port</b> | 
 | 838 | <dd>the server init call fills this in with the | 
 | 839 | localhost port number used to forward broadcasts for this | 
 | 840 | protocol | 
 | 841 | <dt><b>broadcast_socket_user_fd</b> | 
 | 842 | <dd>the server init call fills this in ... the <b>main</b> | 
 | 843 | process context can write to this socket to perform broadcasts | 
 | 844 | (use the <b>libwebsockets_broadcast</b> api to do this instead, | 
 | 845 | it works from any process context) | 
 | 846 | <dt><b>protocol_index</b> | 
 | 847 | <dd>which protocol we are starting from zero | 
| Andy Green | 4f3943a | 2010-11-12 10:44:16 +0000 | [diff] [blame] | 848 | </dl> | 
 | 849 | <h3>Description</h3> | 
 | 850 | <blockquote> | 
 | 851 | This structure represents one protocol supported by the server.  An | 
 | 852 | array of these structures is passed to <b>libwebsocket_create_server</b> | 
 | 853 | allows as many protocols as you like to be handled by one server. | 
 | 854 | </blockquote> | 
 | 855 | <hr> | 
| Andy Green | d6e0911 | 2011-03-05 16:12:15 +0000 | [diff] [blame] | 856 | <h2>struct libwebsocket_extension - An extension we know how to cope with</h2> | 
 | 857 | <b>struct libwebsocket_extension</b> {<br> | 
 | 858 |     <i>const char *</i> <b>name</b>;<br> | 
| Andy Green | 98a717c | 2011-03-06 13:14:15 +0000 | [diff] [blame] | 859 |     <i>int (*</i><b>callback</b>) <i>(struct libwebsocket_context *context,struct libwebsocket *wsi,enum libwebsocket_extension_callback_reasons reason,void *user, void *in, size_t len)</i>;<br> | 
| Andy Green | d6e0911 | 2011-03-05 16:12:15 +0000 | [diff] [blame] | 860 |     <i>size_t</i> <b>per_session_data_size</b>;<br> | 
 | 861 | };<br> | 
 | 862 | <h3>Members</h3> | 
 | 863 | <dl> | 
 | 864 | <dt><b>name</b> | 
 | 865 | <dd>Formal extension name, eg, "deflate-stream" | 
 | 866 | <dt><b>callback</b> | 
 | 867 | <dd>Service callback | 
 | 868 | <dt><b>per_session_data_size</b> | 
 | 869 | <dd>Libwebsockets will auto-malloc this much | 
 | 870 | memory for the use of the extension, a pointer | 
 | 871 | to it comes in the <tt><b>user</b></tt> callback parameter | 
 | 872 | </dl> | 
 | 873 | <hr> |