introduce-k-switch-defeat-masking.patch
[platform/upstream/libwebsockets.git] / libwebsockets-api-doc.html
1 <h2>libwebsocket_context_destroy - Destroy the websocket context</h2>
2 <i>void</i>
3 <b>libwebsocket_context_destroy</b>
4 (<i>struct libwebsocket_context *</i> <b>this</b>)
5 <h3>Arguments</h3>
6 <dl>
7 <dt><b>this</b>
8 <dd>Websocket context
9 </dl>
10 <h3>Description</h3>
11 <blockquote>
12 This function closes any active connections and then frees the
13 context.  After calling this, any further use of the context is
14 undefined.
15 </blockquote>
16 <hr>
17 <h2>libwebsocket_service - Service any pending websocket activity</h2>
18 <i>int</i>
19 <b>libwebsocket_service</b>
20 (<i>struct libwebsocket_context *</i> <b>this</b>,
21 <i>int</i> <b>timeout_ms</b>)
22 <h3>Arguments</h3>
23 <dl>
24 <dt><b>this</b>
25 <dd>Websocket context
26 <dt><b>timeout_ms</b>
27 <dd>Timeout for poll; 0 means return immediately if nothing needed
28 service otherwise block and service immediately, returning
29 after the timeout if nothing needed service.
30 </dl>
31 <h3>Description</h3>
32 <blockquote>
33 This function deals with any pending websocket traffic, for three
34 kinds of event.  It handles these events on both server and client
35 types of connection the same.
36 <p>
37 1) Accept new connections to our context's server
38 <p>
39 2) Perform pending broadcast writes initiated from other forked
40 processes (effectively serializing asynchronous broadcasts)
41 <p>
42 3) Call the receive callback for incoming frame data received by
43 server or client connections.
44 <p>
45 You need to call this service function periodically to all the above
46 functions to happen; if your application is single-threaded you can
47 just call it in your main event loop.
48 <p>
49 Alternatively you can fork a new process that asynchronously handles
50 calling this service in a loop.  In that case you are happy if this
51 call blocks your thread until it needs to take care of something and
52 would call it with a large nonzero timeout.  Your loop then takes no
53 CPU while there is nothing happening.
54 <p>
55 If you are calling it in a single-threaded app, you don't want it to
56 wait around blocking other things in your loop from happening, so you
57 would call it with a timeout_ms of 0, so it returns immediately if
58 nothing is pending, or as soon as it services whatever was pending.
59 </blockquote>
60 <hr>
61 <h2>libwebsocket_callback_on_writable - Request a callback when this socket becomes able to be written to without blocking</h2>
62 <i>int</i>
63 <b>libwebsocket_callback_on_writable</b>
64 (<i>struct libwebsocket *</i> <b>wsi</b>)
65 <h3>Arguments</h3>
66 <dl>
67 <dt><b>wsi</b>
68 <dd>Websocket connection instance to get callback for
69 </dl>
70 <hr>
71 <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>
72 <i>int</i>
73 <b>libwebsocket_callback_on_writable_all_protocol</b>
74 (<i>const struct libwebsocket_protocols *</i> <b>protocol</b>)
75 <h3>Arguments</h3>
76 <dl>
77 <dt><b>protocol</b>
78 <dd>Protocol whose connections will get callbacks
79 </dl>
80 <hr>
81 <h2>libwebsocket_get_socket_fd - returns the socket file descriptor</h2>
82 <i>int</i>
83 <b>libwebsocket_get_socket_fd</b>
84 (<i>struct libwebsocket *</i> <b>wsi</b>)
85 <h3>Arguments</h3>
86 <dl>
87 <dt><b>wsi</b>
88 <dd>Websocket connection instance
89 </dl>
90 <h3>Description</h3>
91 <blockquote>
92 <p>
93 You will not need this unless you are doing something special
94 </blockquote>
95 <hr>
96 <h2>libwebsocket_rx_flow_control - Enable and disable socket servicing for receieved packets.</h2>
97 <i>int</i>
98 <b>libwebsocket_rx_flow_control</b>
99 (<i>struct libwebsocket *</i> <b>wsi</b>,
100 <i>int</i> <b>enable</b>)
101 <h3>Arguments</h3>
102 <dl>
103 <dt><b>wsi</b>
104 <dd>Websocket connection instance to get callback for
105 <dt><b>enable</b>
106 <dd>0 = disable read servicing for this connection, 1 = enable
107 </dl>
108 <h3>Description</h3>
109 <blockquote>
110 <p>
111 If the output side of a server process becomes choked, this allows flow
112 control for the input side.
113 </blockquote>
114 <hr>
115 <h2>libwebsocket_canonical_hostname - returns this host's hostname</h2>
116 <i>const char *</i>
117 <b>libwebsocket_canonical_hostname</b>
118 (<i>struct libwebsocket_context *</i> <b>this</b>)
119 <h3>Arguments</h3>
120 <dl>
121 <dt><b>this</b>
122 <dd>Websocket context
123 </dl>
124 <h3>Description</h3>
125 <blockquote>
126 <p>
127 This is typically used by client code to fill in the host parameter
128 when making a client connection.  You can only call it after the context
129 has been created.
130 </blockquote>
131 <hr>
132 <h2>libwebsocket_create_context - Create the websocket handler</h2>
133 <i>struct libwebsocket_context *</i>
134 <b>libwebsocket_create_context</b>
135 (<i>int</i> <b>port</b>,
136 <i>struct libwebsocket_protocols *</i> <b>protocols</b>,
137 <i>const char *</i> <b>ssl_cert_filepath</b>,
138 <i>const char *</i> <b>ssl_private_key_filepath</b>,
139 <i>int</i> <b>gid</b>,
140 <i>int</i> <b>uid</b>,
141 <i>unsigned int</i> <b>options</b>)
142 <h3>Arguments</h3>
143 <dl>
144 <dt><b>port</b>
145 <dd>Port to listen on... you can use 0 to suppress listening on
146 any port, that's what you want if you are not running a
147 websocket server at all but just using it as a client
148 <dt><b>protocols</b>
149 <dd>Array of structures listing supported protocols and a protocol-
150 specific callback for each one.  The list is ended with an
151 entry that has a NULL callback pointer.
152 It's not const because we write the owning_server member
153 <dt><b>ssl_cert_filepath</b>
154 <dd>If libwebsockets was compiled to use ssl, and you want
155 to listen using SSL, set to the filepath to fetch the
156 server cert from, otherwise NULL for unencrypted
157 <dt><b>ssl_private_key_filepath</b>
158 <dd>filepath to private key if wanting SSL mode,
159 else ignored
160 <dt><b>gid</b>
161 <dd>group id to change to after setting listen socket, or -1.
162 <dt><b>uid</b>
163 <dd>user id to change to after setting listen socket, or -1.
164 </dl>
165 <h3>Description</h3>
166 <blockquote>
167 This function creates the listening socket and takes care
168 of all initialization in one step.
169 <p>
170 After initialization, it returns a struct libwebsocket_context * that
171 represents this server.  After calling, user code needs to take care
172 of calling <b>libwebsocket_service</b> with the context pointer to get the
173 server's sockets serviced.  This can be done in the same process context
174 or a forked process, or another thread,
175 <p>
176 The protocol callback functions are called for a handful of events
177 including http requests coming in, websocket connections becoming
178 established, and data arriving; it's also called periodically to allow
179 async transmission.
180 <p>
181 HTTP requests are sent always to the FIRST protocol in <tt><b>protocol</b></tt>, since
182 at that time websocket protocol has not been negotiated.  Other
183 protocols after the first one never see any HTTP callack activity.
184 <p>
185 The server created is a simple http server by default; part of the
186 websocket standard is upgrading this http connection to a websocket one.
187 <p>
188 This allows the same server to provide files like scripts and favicon /
189 images or whatever over http and dynamic data over websockets all in
190 one place; they're all handled in the user callback.
191 </blockquote>
192 <hr>
193 <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>
194 <i>int</i>
195 <b>libwebsockets_fork_service_loop</b>
196 (<i>struct libwebsocket_context *</i> <b>this</b>)
197 <h3>Arguments</h3>
198 <dl>
199 <dt><b>this</b>
200 <dd>server context returned by creation function
201 </dl>
202 <hr>
203 <h2>libwebsockets_get_protocol - Returns a protocol pointer from a websocket connection.</h2>
204 <i>const struct libwebsocket_protocols *</i>
205 <b>libwebsockets_get_protocol</b>
206 (<i>struct libwebsocket *</i> <b>wsi</b>)
207 <h3>Arguments</h3>
208 <dl>
209 <dt><b>wsi</b>
210 <dd>pointer to struct websocket you want to know the protocol of
211 </dl>
212 <h3>Description</h3>
213 <blockquote>
214 <p>
215 This is useful to get the protocol to broadcast back to from inside
216 the callback.
217 </blockquote>
218 <hr>
219 <h2>libwebsockets_broadcast - Sends a buffer to the callback for all active connections of the given protocol.</h2>
220 <i>int</i>
221 <b>libwebsockets_broadcast</b>
222 (<i>const struct libwebsocket_protocols *</i> <b>protocol</b>,
223 <i>unsigned char *</i> <b>buf</b>,
224 <i>size_t</i> <b>len</b>)
225 <h3>Arguments</h3>
226 <dl>
227 <dt><b>protocol</b>
228 <dd>pointer to the protocol you will broadcast to all members of
229 <dt><b>buf</b>
230 <dd>buffer containing the data to be broadcase.  NOTE: this has to be
231 allocated with LWS_SEND_BUFFER_PRE_PADDING valid bytes before
232 the pointer and LWS_SEND_BUFFER_POST_PADDING afterwards in the
233 case you are calling this function from callback context.
234 <dt><b>len</b>
235 <dd>length of payload data in buf, starting from buf.
236 </dl>
237 <h3>Description</h3>
238 <blockquote>
239 This function allows bulk sending of a packet to every connection using
240 the given protocol.  It does not send the data directly; instead it calls
241 the callback with a reason type of LWS_CALLBACK_BROADCAST.  If the callback
242 wants to actually send the data for that connection, the callback itself
243 should call <b>libwebsocket_write</b>.
244 <p>
245 <b>libwebsockets_broadcast</b> can be called from another fork context without
246 having to take any care about data visibility between the processes, it'll
247 "just work".
248 </blockquote>
249 <hr>
250 <h2>libwebsocket_write - Apply protocol then write data to client</h2>
251 <i>int</i>
252 <b>libwebsocket_write</b>
253 (<i>struct libwebsocket *</i> <b>wsi</b>,
254 <i>unsigned char *</i> <b>buf</b>,
255 <i>size_t</i> <b>len</b>,
256 <i>enum libwebsocket_write_protocol</i> <b>protocol</b>)
257 <h3>Arguments</h3>
258 <dl>
259 <dt><b>wsi</b>
260 <dd>Websocket instance (available from user callback)
261 <dt><b>buf</b>
262 <dd>The data to send.  For data being sent on a websocket
263 connection (ie, not default http), this buffer MUST have
264 LWS_SEND_BUFFER_PRE_PADDING bytes valid BEFORE the pointer
265 and an additional LWS_SEND_BUFFER_POST_PADDING bytes valid
266 in the buffer after (buf + len).  This is so the protocol
267 header and trailer data can be added in-situ.
268 <dt><b>len</b>
269 <dd>Count of the data bytes in the payload starting from buf
270 <dt><b>protocol</b>
271 <dd>Use LWS_WRITE_HTTP to reply to an http connection, and one
272 of LWS_WRITE_BINARY or LWS_WRITE_TEXT to send appropriate
273 data on a websockets connection.  Remember to allow the extra
274 bytes before and after buf if LWS_WRITE_BINARY or LWS_WRITE_TEXT
275 are used.
276 </dl>
277 <h3>Description</h3>
278 <blockquote>
279 This function provides the way to issue data back to the client
280 for both http and websocket protocols.
281 <p>
282 In the case of sending using websocket protocol, be sure to allocate
283 valid storage before and after buf as explained above.  This scheme
284 allows maximum efficiency of sending data and protocol in a single
285 packet while not burdening the user code with any protocol knowledge.
286 </blockquote>
287 <hr>
288 <h2>libwebsockets_serve_http_file - Send a file back to the client using http</h2>
289 <i>int</i>
290 <b>libwebsockets_serve_http_file</b>
291 (<i>struct libwebsocket *</i> <b>wsi</b>,
292 <i>const char *</i> <b>file</b>,
293 <i>const char *</i> <b>content_type</b>)
294 <h3>Arguments</h3>
295 <dl>
296 <dt><b>wsi</b>
297 <dd>Websocket instance (available from user callback)
298 <dt><b>file</b>
299 <dd>The file to issue over http
300 <dt><b>content_type</b>
301 <dd>The http content type, eg, text/html
302 </dl>
303 <h3>Description</h3>
304 <blockquote>
305 This function is intended to be called from the callback in response
306 to http requests from the client.  It allows the callback to issue
307 local files down the http link in a single step.
308 </blockquote>
309 <hr>
310 <h2>libwebsockets_remaining_packet_payload - Bytes to come before "overall" rx packet is complete</h2>
311 <i>size_t</i>
312 <b>libwebsockets_remaining_packet_payload</b>
313 (<i>struct libwebsocket *</i> <b>wsi</b>)
314 <h3>Arguments</h3>
315 <dl>
316 <dt><b>wsi</b>
317 <dd>Websocket instance (available from user callback)
318 </dl>
319 <h3>Description</h3>
320 <blockquote>
321 This function is intended to be called from the callback if the
322 user code is interested in "complete packets" from the client.
323 libwebsockets just passes through payload as it comes and issues a buffer
324 additionally when it hits a built-in limit.  The LWS_CALLBACK_RECEIVE
325 callback handler can use this API to find out if the buffer it has just
326 been given is the last piece of a "complete packet" from the client --
327 when that is the case <b>libwebsockets_remaining_packet_payload</b> will return
328 0.
329 <p>
330 Many protocols won't care becuse their packets are always small.
331 </blockquote>
332 <hr>
333 <h2>libwebsocket_client_connect - Connect to another websocket server</h2>
334 <i>struct libwebsocket *</i>
335 <b>libwebsocket_client_connect</b>
336 (<i>struct libwebsocket_context *</i> <b>this</b>,
337 <i>const char *</i> <b>address</b>,
338 <i>int</i> <b>port</b>,
339 <i>int</i> <b>ssl_connection</b>,
340 <i>const char *</i> <b>path</b>,
341 <i>const char *</i> <b>host</b>,
342 <i>const char *</i> <b>origin</b>,
343 <i>const char *</i> <b>protocol</b>)
344 <h3>Arguments</h3>
345 <dl>
346 <dt><b>this</b>
347 <dd>Websocket context
348 <dt><b>address</b>
349 <dd>Remote server address, eg, "myserver.com"
350 <dt><b>port</b>
351 <dd>Port to connect to on the remote server, eg, 80
352 <dt><b>ssl_connection</b>
353 <dd>0 = ws://, 1 = wss:// encrypted, 2 = wss:// allow self
354 signed certs
355 <dt><b>path</b>
356 <dd>Websocket path on server
357 <dt><b>host</b>
358 <dd>Hostname on server
359 <dt><b>origin</b>
360 <dd>Socket origin name
361 <dt><b>protocol</b>
362 <dd>Comma-separated list of protocols being asked for from
363 the server, or just one.  The server will pick the one it
364 likes best.
365 </dl>
366 <h3>Description</h3>
367 <blockquote>
368 This function creates a connection to a remote server
369 </blockquote>
370 <hr>
371 <h2>callback - User server actions</h2>
372 <i>int</i>
373 <b>callback</b>
374 (<i>struct libwebsocket *</i> <b>wsi</b>,
375 <i>enum libwebsocket_callback_reasons</i> <b>reason</b>,
376 <i>void *</i> <b>user</b>,
377 <i>void *</i> <b>in</b>,
378 <i>size_t</i> <b>len</b>)
379 <h3>Arguments</h3>
380 <dl>
381 <dt><b>wsi</b>
382 <dd>Opaque websocket instance pointer
383 <dt><b>reason</b>
384 <dd>The reason for the call
385 <dt><b>user</b>
386 <dd>Pointer to per-session user data allocated by library
387 <dt><b>in</b>
388 <dd>Pointer used for some callback reasons
389 <dt><b>len</b>
390 <dd>Length set for some callback reasons
391 </dl>
392 <h3>Description</h3>
393 <blockquote>
394 This callback is the way the user controls what is served.  All the
395 protocol detail is hidden and handled by the library.
396 <p>
397 For each connection / session there is user data allocated that is
398 pointed to by "user".  You set the size of this user data area when
399 the library is initialized with libwebsocket_create_server.
400 <p>
401 You get an opportunity to initialize user data when called back with
402 LWS_CALLBACK_ESTABLISHED reason.
403 </blockquote>
404 <h3>LWS_CALLBACK_ESTABLISHED</h3>
405 <blockquote>
406 after the server completes a handshake with
407 an incoming client
408 </blockquote>
409 <h3>LWS_CALLBACK_CLIENT_ESTABLISHED</h3>
410 <blockquote>
411 after your client connection completed
412 a handshake with the remote server
413 </blockquote>
414 <h3>LWS_CALLBACK_CLOSED</h3>
415 <blockquote>
416 when the websocket session ends
417 </blockquote>
418 <h3>LWS_CALLBACK_BROADCAST</h3>
419 <blockquote>
420 signal to send to client (you would use
421 <b>libwebsocket_write</b> taking care about the
422 special buffer requirements
423 </blockquote>
424 <h3>LWS_CALLBACK_RECEIVE</h3>
425 <blockquote>
426 data has appeared for this server endpoint from a
427 remote client, it can be found at *in and is
428 len bytes long
429 </blockquote>
430 <h3>LWS_CALLBACK_CLIENT_RECEIVE_PONG</h3>
431 <blockquote>
432 if you elected to see PONG packets,
433 they appear with this callback reason.  PONG
434 packets only exist in 04+ protocol
435 </blockquote>
436 <h3>LWS_CALLBACK_CLIENT_RECEIVE</h3>
437 <blockquote>
438 data has appeared from the server for the
439 client connection, it can be found at *in and
440 is len bytes long
441 </blockquote>
442 <h3>LWS_CALLBACK_HTTP</h3>
443 <blockquote>
444 an http request has come from a client that is not
445 asking to upgrade the connection to a websocket
446 one.  This is a chance to serve http content,
447 for example, to send a script to the client
448 which will then open the websockets connection.
449 <tt><b>in</b></tt> points to the URI path requested and
450 <b>libwebsockets_serve_http_file</b> makes it very
451 simple to send back a file to the client.
452 </blockquote>
453 <h3>LWS_CALLBACK_CLIENT_WRITEABLE</h3>
454 <blockquote>
455 if you call
456 <b>libwebsocket_callback_on_writable</b> on a connection, you will
457 get this callback coming when the connection socket is able to
458 accept another write packet without blocking.  If it already
459 was able to take another packet without blocking, you'll get
460 this callback at the next call to the service loop function.
461 </blockquote>
462 <hr>
463 <h2>struct libwebsocket_protocols - List of protocols and handlers server supports.</h2>
464 <b>struct libwebsocket_protocols</b> {<br>
465 &nbsp; &nbsp; <i>const char *</i> <b>name</b>;<br>
466 &nbsp; &nbsp; <i>int (*</i><b>callback</b>) <i>(struct libwebsocket *wsi,enum libwebsocket_callback_reasons reason, void *user,void *in, size_t len)</i>;<br>
467 &nbsp; &nbsp; <i>size_t</i> <b>per_session_data_size</b>;<br>
468 &nbsp; &nbsp; <i>struct libwebsocket_context *</i> <b>owning_server</b>;<br>
469 &nbsp; &nbsp; <i>int</i> <b>broadcast_socket_port</b>;<br>
470 &nbsp; &nbsp; <i>int</i> <b>broadcast_socket_user_fd</b>;<br>
471 &nbsp; &nbsp; <i>int</i> <b>protocol_index</b>;<br>
472 };<br>
473 <h3>Members</h3>
474 <dl>
475 <dt><b>name</b>
476 <dd>Protocol name that must match the one given in the client
477 Javascript new WebSocket(url, 'protocol') name
478 <dt><b>callback</b>
479 <dd>The service callback used for this protocol.  It allows the
480 service action for an entire protocol to be encapsulated in
481 the protocol-specific callback
482 <dt><b>per_session_data_size</b>
483 <dd>Each new connection using this protocol gets
484 this much memory allocated on connection establishment and
485 freed on connection takedown.  A pointer to this per-connection
486 allocation is passed into the callback in the 'user' parameter
487 <dt><b>owning_server</b>
488 <dd>the server init call fills in this opaque pointer when
489 registering this protocol with the server.
490 <dt><b>broadcast_socket_port</b>
491 <dd>the server init call fills this in with the
492 localhost port number used to forward broadcasts for this
493 protocol
494 <dt><b>broadcast_socket_user_fd</b>
495 <dd>the server init call fills this in ... the <b>main</b>
496 process context can write to this socket to perform broadcasts
497 (use the <b>libwebsockets_broadcast</b> api to do this instead,
498 it works from any process context)
499 <dt><b>protocol_index</b>
500 <dd>which protocol we are starting from zero
501 </dl>
502 <h3>Description</h3>
503 <blockquote>
504 This structure represents one protocol supported by the server.  An
505 array of these structures is passed to <b>libwebsocket_create_server</b>
506 allows as many protocols as you like to be handled by one server.
507 </blockquote>
508 <hr>