blob: 156afe79edb2b6d9c577b0990d3151628ff2fb40 [file] [log] [blame]
Andy Greend88146d2013-01-22 12:40:35 +08001<h2>libwebsocket_client_connect - Connect to another websocket server</h2>
2<i>struct libwebsocket *</i>
3<b>libwebsocket_client_connect</b>
4(<i>struct libwebsocket_context *</i> <b>context</b>,
5<i>const char *</i> <b>address</b>,
6<i>int</i> <b>port</b>,
7<i>int</i> <b>ssl_connection</b>,
8<i>const char *</i> <b>path</b>,
9<i>const char *</i> <b>host</b>,
10<i>const char *</i> <b>origin</b>,
11<i>const char *</i> <b>protocol</b>,
12<i>int</i> <b>ietf_version_or_minus_one</b>)
13<h3>Arguments</h3>
14<dl>
15<dt><b>context</b>
16<dd>Websocket context
17<dt><b>address</b>
18<dd>Remote server address, eg, "myserver.com"
19<dt><b>port</b>
20<dd>Port to connect to on the remote server, eg, 80
21<dt><b>ssl_connection</b>
22<dd>0 = ws://, 1 = wss:// encrypted, 2 = wss:// allow self
23signed certs
24<dt><b>path</b>
25<dd>Websocket path on server
26<dt><b>host</b>
27<dd>Hostname on server
28<dt><b>origin</b>
29<dd>Socket origin name
30<dt><b>protocol</b>
31<dd>Comma-separated list of protocols being asked for from
32the server, or just one. The server will pick the one it
33likes best.
34<dt><b>ietf_version_or_minus_one</b>
35<dd>-1 to ask to connect using the default, latest
36protocol supported, or the specific protocol ordinal
37</dl>
38<h3>Description</h3>
39<blockquote>
40This function creates a connection to a remote server
41</blockquote>
42<hr>
43<h2>libwebsocket_client_connect_extended - Connect to another websocket server</h2>
44<i>struct libwebsocket *</i>
45<b>libwebsocket_client_connect_extended</b>
46(<i>struct libwebsocket_context *</i> <b>context</b>,
47<i>const char *</i> <b>address</b>,
48<i>int</i> <b>port</b>,
49<i>int</i> <b>ssl_connection</b>,
50<i>const char *</i> <b>path</b>,
51<i>const char *</i> <b>host</b>,
52<i>const char *</i> <b>origin</b>,
53<i>const char *</i> <b>protocol</b>,
54<i>int</i> <b>ietf_version_or_minus_one</b>,
55<i>void *</i> <b>userdata</b>)
56<h3>Arguments</h3>
57<dl>
58<dt><b>context</b>
59<dd>Websocket context
60<dt><b>address</b>
61<dd>Remote server address, eg, "myserver.com"
62<dt><b>port</b>
63<dd>Port to connect to on the remote server, eg, 80
64<dt><b>ssl_connection</b>
65<dd>0 = ws://, 1 = wss:// encrypted, 2 = wss:// allow self
66signed certs
67<dt><b>path</b>
68<dd>Websocket path on server
69<dt><b>host</b>
70<dd>Hostname on server
71<dt><b>origin</b>
72<dd>Socket origin name
73<dt><b>protocol</b>
74<dd>Comma-separated list of protocols being asked for from
75the server, or just one. The server will pick the one it
76likes best.
77<dt><b>ietf_version_or_minus_one</b>
78<dd>-1 to ask to connect using the default, latest
79protocol supported, or the specific protocol ordinal
80<dt><b>userdata</b>
81<dd>Pre-allocated user data
82</dl>
83<h3>Description</h3>
84<blockquote>
85This function creates a connection to a remote server
86</blockquote>
87<hr>
Andy Greenf7ee5492011-02-13 09:04:21 +000088<h2>libwebsockets_hangup_on_client - Server calls to terminate client connection</h2>
89<i>void</i>
90<b>libwebsockets_hangup_on_client</b>
Peter Hinz56885f32011-03-02 22:03:47 +000091(<i>struct libwebsocket_context *</i> <b>context</b>,
Andy Greenf7ee5492011-02-13 09:04:21 +000092<i>int</i> <b>fd</b>)
93<h3>Arguments</h3>
94<dl>
Peter Hinz56885f32011-03-02 22:03:47 +000095<dt><b>context</b>
Andy Greenf7ee5492011-02-13 09:04:21 +000096<dd>libwebsockets context
97<dt><b>fd</b>
98<dd>Connection socket descriptor
99</dl>
100<hr>
Andy Green07034092011-02-13 08:37:12 +0000101<h2>libwebsockets_get_peer_addresses - Get client address information</h2>
102<i>void</i>
103<b>libwebsockets_get_peer_addresses</b>
104(<i>int</i> <b>fd</b>,
105<i>char *</i> <b>name</b>,
106<i>int</i> <b>name_len</b>,
107<i>char *</i> <b>rip</b>,
108<i>int</i> <b>rip_len</b>)
109<h3>Arguments</h3>
110<dl>
111<dt><b>fd</b>
112<dd>Connection socket descriptor
113<dt><b>name</b>
114<dd>Buffer to take client address name
115<dt><b>name_len</b>
116<dd>Length of client address name buffer
117<dt><b>rip</b>
118<dd>Buffer to take client address IP qotted quad
119<dt><b>rip_len</b>
120<dd>Length of client address IP buffer
121</dl>
122<h3>Description</h3>
123<blockquote>
124This function fills in <tt><b>name</b></tt> and <tt><b>rip</b></tt> with the name and IP of
125the client connected with socket descriptor <tt><b>fd</b></tt>. Names may be
126truncated if there is not enough room. If either cannot be
127determined, they will be returned as valid zero-length strings.
128</blockquote>
129<hr>
Andy Green9f990342011-02-12 11:57:45 +0000130<h2>libwebsocket_service_fd - Service polled socket with something waiting</h2>
131<i>int</i>
132<b>libwebsocket_service_fd</b>
Peter Hinz56885f32011-03-02 22:03:47 +0000133(<i>struct libwebsocket_context *</i> <b>context</b>,
Andy Green9f990342011-02-12 11:57:45 +0000134<i>struct pollfd *</i> <b>pollfd</b>)
135<h3>Arguments</h3>
136<dl>
Peter Hinz56885f32011-03-02 22:03:47 +0000137<dt><b>context</b>
Andy Green9f990342011-02-12 11:57:45 +0000138<dd>Websocket context
139<dt><b>pollfd</b>
140<dd>The pollfd entry describing the socket fd and which events
141happened.
142</dl>
143<h3>Description</h3>
144<blockquote>
Andy Green75006172013-01-22 12:32:11 +0800145This function takes a pollfd that has POLLIN or POLLOUT activity and
146services it according to the state of the associated struct libwebsocket.
147<p>
148The one call deals with all "service" that might happen on a socket
149including listen accepts, http files as well as websocket protocol.
Andy Green9f990342011-02-12 11:57:45 +0000150</blockquote>
151<hr>
Andy Green6964bb52011-01-23 16:50:33 +0000152<h2>libwebsocket_context_destroy - Destroy the websocket context</h2>
153<i>void</i>
154<b>libwebsocket_context_destroy</b>
Peter Hinz56885f32011-03-02 22:03:47 +0000155(<i>struct libwebsocket_context *</i> <b>context</b>)
Andy Green6964bb52011-01-23 16:50:33 +0000156<h3>Arguments</h3>
157<dl>
Peter Hinz56885f32011-03-02 22:03:47 +0000158<dt><b>context</b>
Andy Green6964bb52011-01-23 16:50:33 +0000159<dd>Websocket context
160</dl>
161<h3>Description</h3>
162<blockquote>
163This function closes any active connections and then frees the
164context. After calling this, any further use of the context is
165undefined.
166</blockquote>
167<hr>
Andy Greend88146d2013-01-22 12:40:35 +0800168<h2>libwebsocket_context_user - get the user data associated with the whole context</h2>
169<i>LWS_EXTERN void *</i>
170<b>libwebsocket_context_user</b>
171(<i>struct libwebsocket_context *</i> <b>context</b>)
172<h3>Arguments</h3>
173<dl>
174<dt><b>context</b>
175<dd>Websocket context
176</dl>
177<h3>Description</h3>
178<blockquote>
179This returns the optional user allocation that can be attached to
180the context the sockets live in at context_create time. It's a way
181to let all sockets serviced in the same context share data without
182using globals statics in the user code.
183</blockquote>
184<hr>
Andy Green6964bb52011-01-23 16:50:33 +0000185<h2>libwebsocket_service - Service any pending websocket activity</h2>
186<i>int</i>
187<b>libwebsocket_service</b>
Peter Hinz56885f32011-03-02 22:03:47 +0000188(<i>struct libwebsocket_context *</i> <b>context</b>,
Andy Green6964bb52011-01-23 16:50:33 +0000189<i>int</i> <b>timeout_ms</b>)
190<h3>Arguments</h3>
191<dl>
Peter Hinz56885f32011-03-02 22:03:47 +0000192<dt><b>context</b>
Andy Green6964bb52011-01-23 16:50:33 +0000193<dd>Websocket context
194<dt><b>timeout_ms</b>
195<dd>Timeout for poll; 0 means return immediately if nothing needed
196service otherwise block and service immediately, returning
197after the timeout if nothing needed service.
198</dl>
199<h3>Description</h3>
200<blockquote>
201This function deals with any pending websocket traffic, for three
202kinds of event. It handles these events on both server and client
203types of connection the same.
204<p>
2051) Accept new connections to our context's server
206<p>
2072) Perform pending broadcast writes initiated from other forked
208processes (effectively serializing asynchronous broadcasts)
209<p>
2103) Call the receive callback for incoming frame data received by
211server or client connections.
212<p>
213You need to call this service function periodically to all the above
214functions to happen; if your application is single-threaded you can
215just call it in your main event loop.
216<p>
217Alternatively you can fork a new process that asynchronously handles
218calling this service in a loop. In that case you are happy if this
219call blocks your thread until it needs to take care of something and
220would call it with a large nonzero timeout. Your loop then takes no
221CPU while there is nothing happening.
222<p>
223If you are calling it in a single-threaded app, you don't want it to
224wait around blocking other things in your loop from happening, so you
225would call it with a timeout_ms of 0, so it returns immediately if
226nothing is pending, or as soon as it services whatever was pending.
227</blockquote>
228<hr>
Andy Green32375b72011-02-19 08:32:53 +0000229<h2>libwebsocket_callback_on_writable - Request a callback when this socket becomes able to be written to without blocking</h2>
Andy Green90c7cbc2011-01-27 06:26:52 +0000230<i>int</i>
231<b>libwebsocket_callback_on_writable</b>
Peter Hinz56885f32011-03-02 22:03:47 +0000232(<i>struct libwebsocket_context *</i> <b>context</b>,
Andy Green62c54d22011-02-14 09:14:25 +0000233<i>struct libwebsocket *</i> <b>wsi</b>)
Andy Green90c7cbc2011-01-27 06:26:52 +0000234<h3>Arguments</h3>
235<dl>
Peter Hinz56885f32011-03-02 22:03:47 +0000236<dt><b>context</b>
Andy Green32375b72011-02-19 08:32:53 +0000237<dd>libwebsockets context
Andy Green90c7cbc2011-01-27 06:26:52 +0000238<dt><b>wsi</b>
239<dd>Websocket connection instance to get callback for
240</dl>
241<hr>
242<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>
243<i>int</i>
244<b>libwebsocket_callback_on_writable_all_protocol</b>
245(<i>const struct libwebsocket_protocols *</i> <b>protocol</b>)
246<h3>Arguments</h3>
247<dl>
248<dt><b>protocol</b>
249<dd>Protocol whose connections will get callbacks
250</dl>
251<hr>
Andy Greenbe93fef2011-02-14 20:25:43 +0000252<h2>libwebsocket_set_timeout - marks the wsi as subject to a timeout</h2>
253<i>void</i>
254<b>libwebsocket_set_timeout</b>
255(<i>struct libwebsocket *</i> <b>wsi</b>,
256<i>enum pending_timeout</i> <b>reason</b>,
257<i>int</i> <b>secs</b>)
258<h3>Arguments</h3>
259<dl>
260<dt><b>wsi</b>
261<dd>Websocket connection instance
262<dt><b>reason</b>
263<dd>timeout reason
264<dt><b>secs</b>
265<dd>how many seconds
266</dl>
267<h3>Description</h3>
268<blockquote>
269<p>
270You will not need this unless you are doing something special
271</blockquote>
272<hr>
Andy Greena6cbece2011-01-27 20:06:03 +0000273<h2>libwebsocket_get_socket_fd - returns the socket file descriptor</h2>
274<i>int</i>
275<b>libwebsocket_get_socket_fd</b>
276(<i>struct libwebsocket *</i> <b>wsi</b>)
277<h3>Arguments</h3>
278<dl>
279<dt><b>wsi</b>
280<dd>Websocket connection instance
281</dl>
282<h3>Description</h3>
283<blockquote>
284<p>
285You will not need this unless you are doing something special
286</blockquote>
287<hr>
Andy Green90c7cbc2011-01-27 06:26:52 +0000288<h2>libwebsocket_rx_flow_control - Enable and disable socket servicing for receieved packets.</h2>
289<i>int</i>
290<b>libwebsocket_rx_flow_control</b>
291(<i>struct libwebsocket *</i> <b>wsi</b>,
292<i>int</i> <b>enable</b>)
293<h3>Arguments</h3>
294<dl>
295<dt><b>wsi</b>
296<dd>Websocket connection instance to get callback for
297<dt><b>enable</b>
298<dd>0 = disable read servicing for this connection, 1 = enable
299</dl>
300<h3>Description</h3>
301<blockquote>
302<p>
303If the output side of a server process becomes choked, this allows flow
304control for the input side.
305</blockquote>
306<hr>
Andy Green2ac5a6f2011-01-28 10:00:18 +0000307<h2>libwebsocket_canonical_hostname - returns this host's hostname</h2>
308<i>const char *</i>
309<b>libwebsocket_canonical_hostname</b>
Peter Hinz56885f32011-03-02 22:03:47 +0000310(<i>struct libwebsocket_context *</i> <b>context</b>)
Andy Green2ac5a6f2011-01-28 10:00:18 +0000311<h3>Arguments</h3>
312<dl>
Peter Hinz56885f32011-03-02 22:03:47 +0000313<dt><b>context</b>
Andy Green2ac5a6f2011-01-28 10:00:18 +0000314<dd>Websocket context
315</dl>
316<h3>Description</h3>
317<blockquote>
318<p>
319This is typically used by client code to fill in the host parameter
320when making a client connection. You can only call it after the context
321has been created.
322</blockquote>
323<hr>
Andy Green4739e5c2011-01-22 12:51:57 +0000324<h2>libwebsocket_create_context - Create the websocket handler</h2>
Andy Greene92cd172011-01-19 13:11:55 +0000325<i>struct libwebsocket_context *</i>
Andy Green4739e5c2011-01-22 12:51:57 +0000326<b>libwebsocket_create_context</b>
Andy Green62a12932010-11-03 11:19:23 +0000327(<i>int</i> <b>port</b>,
Peter Hinz56885f32011-03-02 22:03:47 +0000328<i>const char *</i> <b>interf</b>,
Andy Greenb45993c2010-12-18 15:13:50 +0000329<i>struct libwebsocket_protocols *</i> <b>protocols</b>,
Andy Greend6e09112011-03-05 16:12:15 +0000330<i>struct libwebsocket_extension *</i> <b>extensions</b>,
Andy Green3faa9c72010-11-08 17:03:03 +0000331<i>const char *</i> <b>ssl_cert_filepath</b>,
332<i>const char *</i> <b>ssl_private_key_filepath</b>,
David Galeano2f82be82013-01-09 16:25:54 +0800333<i>const char *</i> <b>ssl_ca_filepath</b>,
Andy Green3faa9c72010-11-08 17:03:03 +0000334<i>int</i> <b>gid</b>,
Andy Green8014b292011-01-30 20:57:25 +0000335<i>int</i> <b>uid</b>,
Alon Levy0291eb32012-10-19 11:21:56 +0200336<i>unsigned int</i> <b>options</b>,
337<i>void *</i> <b>user</b>)
Andy Green62a12932010-11-03 11:19:23 +0000338<h3>Arguments</h3>
339<dl>
340<dt><b>port</b>
Andy Green4739e5c2011-01-22 12:51:57 +0000341<dd>Port to listen on... you can use 0 to suppress listening on
342any port, that's what you want if you are not running a
343websocket server at all but just using it as a client
Peter Hinz56885f32011-03-02 22:03:47 +0000344<dt><b>interf</b>
Andy Green32375b72011-02-19 08:32:53 +0000345<dd>NULL to bind the listen socket to all interfaces, or the
346interface name, eg, "eth2"
Andy Green4f3943a2010-11-12 10:44:16 +0000347<dt><b>protocols</b>
348<dd>Array of structures listing supported protocols and a protocol-
349specific callback for each one. The list is ended with an
350entry that has a NULL callback pointer.
Andy Greenb45993c2010-12-18 15:13:50 +0000351It's not const because we write the owning_server member
Andy Greenc5114822011-03-06 10:29:35 +0000352<dt><b>extensions</b>
353<dd>NULL or array of libwebsocket_extension structs listing the
Andy Green3182ece2013-01-20 17:08:31 +0800354extensions this context supports. If you configured with
355--without-extensions, you should give NULL here.
Andy Green3faa9c72010-11-08 17:03:03 +0000356<dt><b>ssl_cert_filepath</b>
357<dd>If libwebsockets was compiled to use ssl, and you want
358to listen using SSL, set to the filepath to fetch the
359server cert from, otherwise NULL for unencrypted
360<dt><b>ssl_private_key_filepath</b>
361<dd>filepath to private key if wanting SSL mode,
362else ignored
David Galeano2f82be82013-01-09 16:25:54 +0800363<dt><b>ssl_ca_filepath</b>
Andy Green988bd982013-01-10 12:26:13 +0800364<dd>CA certificate filepath or NULL
Andy Green3faa9c72010-11-08 17:03:03 +0000365<dt><b>gid</b>
366<dd>group id to change to after setting listen socket, or -1.
367<dt><b>uid</b>
368<dd>user id to change to after setting listen socket, or -1.
Andy Greenbfb051f2011-02-09 08:49:14 +0000369<dt><b>options</b>
370<dd>0, or LWS_SERVER_OPTION_DEFEAT_CLIENT_MASK
Andy Green788c4a82012-10-22 12:29:57 +0100371<dt><b>user</b>
372<dd>optional user pointer that can be recovered via the context
373pointer using libwebsocket_context_user
Andy Green62a12932010-11-03 11:19:23 +0000374</dl>
375<h3>Description</h3>
376<blockquote>
Andy Green47943ae2010-11-12 11:15:49 +0000377This function creates the listening socket and takes care
Andy Green62a12932010-11-03 11:19:23 +0000378of all initialization in one step.
379<p>
Andy Greene92cd172011-01-19 13:11:55 +0000380After initialization, it returns a struct libwebsocket_context * that
381represents this server. After calling, user code needs to take care
382of calling <b>libwebsocket_service</b> with the context pointer to get the
383server's sockets serviced. This can be done in the same process context
384or a forked process, or another thread,
Andy Green47943ae2010-11-12 11:15:49 +0000385<p>
386The protocol callback functions are called for a handful of events
387including http requests coming in, websocket connections becoming
Andy Green62a12932010-11-03 11:19:23 +0000388established, and data arriving; it's also called periodically to allow
389async transmission.
390<p>
Andy Green47943ae2010-11-12 11:15:49 +0000391HTTP requests are sent always to the FIRST protocol in <tt><b>protocol</b></tt>, since
392at that time websocket protocol has not been negotiated. Other
393protocols after the first one never see any HTTP callack activity.
394<p>
Andy Green62a12932010-11-03 11:19:23 +0000395The server created is a simple http server by default; part of the
396websocket standard is upgrading this http connection to a websocket one.
397<p>
398This allows the same server to provide files like scripts and favicon /
399images or whatever over http and dynamic data over websockets all in
400one place; they're all handled in the user callback.
401</blockquote>
402<hr>
Andy Greene92cd172011-01-19 13:11:55 +0000403<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>
404<i>int</i>
405<b>libwebsockets_fork_service_loop</b>
Peter Hinz56885f32011-03-02 22:03:47 +0000406(<i>struct libwebsocket_context *</i> <b>context</b>)
Andy Greene92cd172011-01-19 13:11:55 +0000407<h3>Arguments</h3>
408<dl>
Peter Hinz56885f32011-03-02 22:03:47 +0000409<dt><b>context</b>
Andy Greene92cd172011-01-19 13:11:55 +0000410<dd>server context returned by creation function
411</dl>
412<hr>
Andy Greenb45993c2010-12-18 15:13:50 +0000413<h2>libwebsockets_get_protocol - Returns a protocol pointer from a websocket connection.</h2>
414<i>const struct libwebsocket_protocols *</i>
415<b>libwebsockets_get_protocol</b>
416(<i>struct libwebsocket *</i> <b>wsi</b>)
417<h3>Arguments</h3>
418<dl>
419<dt><b>wsi</b>
420<dd>pointer to struct websocket you want to know the protocol of
421</dl>
422<h3>Description</h3>
423<blockquote>
424<p>
425This is useful to get the protocol to broadcast back to from inside
426the callback.
427</blockquote>
428<hr>
Andy Green52f28ce2013-01-25 17:34:15 +0800429<h2>libwebsockets_broadcast - Sends a buffer to tx callback for all connections of given protocol from single thread</h2>
Andy Greenb45993c2010-12-18 15:13:50 +0000430<i>int</i>
431<b>libwebsockets_broadcast</b>
432(<i>const struct libwebsocket_protocols *</i> <b>protocol</b>,
433<i>unsigned char *</i> <b>buf</b>,
434<i>size_t</i> <b>len</b>)
435<h3>Arguments</h3>
436<dl>
437<dt><b>protocol</b>
438<dd>pointer to the protocol you will broadcast to all members of
439<dt><b>buf</b>
440<dd>buffer containing the data to be broadcase. NOTE: this has to be
441allocated with LWS_SEND_BUFFER_PRE_PADDING valid bytes before
442the pointer and LWS_SEND_BUFFER_POST_PADDING afterwards in the
443case you are calling this function from callback context.
444<dt><b>len</b>
445<dd>length of payload data in buf, starting from buf.
446</dl>
447<h3>Description</h3>
448<blockquote>
449This function allows bulk sending of a packet to every connection using
450the given protocol. It does not send the data directly; instead it calls
451the callback with a reason type of LWS_CALLBACK_BROADCAST. If the callback
452wants to actually send the data for that connection, the callback itself
453should call <b>libwebsocket_write</b>.
454<p>
Andy Green52f28ce2013-01-25 17:34:15 +0800455This version only works from the same thread / process context as the service
456loop. Use libwesockets_broadcast_foreign(...) to do the same job from a different
457thread in a safe way.
458</blockquote>
459<hr>
460<h2>libwebsockets_broadcast_foreign - Sends a buffer to the callback for all active connections of the given protocol.</h2>
461<i>int</i>
462<b>libwebsockets_broadcast_foreign</b>
463(<i>struct libwebsocket_protocols *</i> <b>protocol</b>,
464<i>unsigned char *</i> <b>buf</b>,
465<i>size_t</i> <b>len</b>)
466<h3>Arguments</h3>
467<dl>
468<dt><b>protocol</b>
469<dd>pointer to the protocol you will broadcast to all members of
470<dt><b>buf</b>
471<dd>buffer containing the data to be broadcase. NOTE: this has to be
472allocated with LWS_SEND_BUFFER_PRE_PADDING valid bytes before
473the pointer and LWS_SEND_BUFFER_POST_PADDING afterwards in the
474case you are calling this function from callback context.
475<dt><b>len</b>
476<dd>length of payload data in buf, starting from buf.
477</dl>
478<h3>Description</h3>
479<blockquote>
480This function allows bulk sending of a packet to every connection using
481the given protocol. It does not send the data directly; instead it calls
482the callback with a reason type of LWS_CALLBACK_BROADCAST. If the callback
483wants to actually send the data for that connection, the callback itself
484should call <b>libwebsocket_write</b>.
485<p>
486This ...<b>_foreign</b> version is designed to be randomly called from other thread or
487process contexts than the main libwebsocket service one. A private socket is used
488to serialize accesses here with the main service loop.
Andy Greenb45993c2010-12-18 15:13:50 +0000489</blockquote>
490<hr>
Andy Greenacbaee62013-01-18 22:00:22 +0800491<h2>lws_confirm_legit_wsi - </h2>
492<i>int</i>
493<b>lws_confirm_legit_wsi</b>
494(<i>struct libwebsocket *</i> <b>wsi</b>)
495<h3>Arguments</h3>
496<dl>
497<dt><b>wsi</b>
498<dd>struct libwebsocket to assess
499</dl>
500<h3>Description</h3>
501<blockquote>
502Performs consistecy checks on what the wsi claims and what the
503polling arrays hold. This'll catch a closed wsi still in use.
504Don't try to use on the listen (nonconnection) wsi as it will
505fail it. Otherwise 0 return == wsi seems consistent.
506</blockquote>
507<hr>
Andy Green43db0452013-01-10 19:50:35 +0800508<h2>lws_set_log_level - Set the logging bitfield</h2>
509<i>void</i>
510<b>lws_set_log_level</b>
Andy Greende8f27a2013-01-12 09:17:42 +0800511(<i>int</i> <b>level</b>,
Andy Green058ba812013-01-19 11:32:18 +0800512<i>void (*</i><b>log_emit_function</b>) <i>(int level, const char *line)</i>)
Andy Green43db0452013-01-10 19:50:35 +0800513<h3>Arguments</h3>
514<dl>
515<dt><b>level</b>
516<dd>OR together the LLL_ debug contexts you want output from
Andy Greende8f27a2013-01-12 09:17:42 +0800517<dt><b>log_emit_function</b>
518<dd>NULL to leave it as it is, or a user-supplied
519function to perform log string emission instead of
520the default stderr one.
Andy Green43db0452013-01-10 19:50:35 +0800521</dl>
522<h3>Description</h3>
523<blockquote>
Andy Greende8f27a2013-01-12 09:17:42 +0800524log level defaults to "err" and "warn" contexts enabled only and
525emission on stderr.
Andy Green43db0452013-01-10 19:50:35 +0800526</blockquote>
527<hr>
Andy Greend88146d2013-01-22 12:40:35 +0800528<h2>libwebsocket_write - Apply protocol then write data to client</h2>
529<i>int</i>
530<b>libwebsocket_write</b>
531(<i>struct libwebsocket *</i> <b>wsi</b>,
532<i>unsigned char *</i> <b>buf</b>,
533<i>size_t</i> <b>len</b>,
534<i>enum libwebsocket_write_protocol</i> <b>protocol</b>)
535<h3>Arguments</h3>
536<dl>
537<dt><b>wsi</b>
538<dd>Websocket instance (available from user callback)
539<dt><b>buf</b>
540<dd>The data to send. For data being sent on a websocket
541connection (ie, not default http), this buffer MUST have
542LWS_SEND_BUFFER_PRE_PADDING bytes valid BEFORE the pointer
543and an additional LWS_SEND_BUFFER_POST_PADDING bytes valid
544in the buffer after (buf + len). This is so the protocol
545header and trailer data can be added in-situ.
546<dt><b>len</b>
547<dd>Count of the data bytes in the payload starting from buf
548<dt><b>protocol</b>
549<dd>Use LWS_WRITE_HTTP to reply to an http connection, and one
550of LWS_WRITE_BINARY or LWS_WRITE_TEXT to send appropriate
551data on a websockets connection. Remember to allow the extra
552bytes before and after buf if LWS_WRITE_BINARY or LWS_WRITE_TEXT
553are used.
554</dl>
555<h3>Description</h3>
556<blockquote>
557This function provides the way to issue data back to the client
558for both http and websocket protocols.
559<p>
560In the case of sending using websocket protocol, be sure to allocate
561valid storage before and after buf as explained above. This scheme
562allows maximum efficiency of sending data and protocol in a single
563packet while not burdening the user code with any protocol knowledge.
564</blockquote>
565<hr>
566<h2>libwebsockets_serve_http_file - Send a file back to the client using http</h2>
567<i>int</i>
568<b>libwebsockets_serve_http_file</b>
569(<i>struct libwebsocket_context *</i> <b>context</b>,
570<i>struct libwebsocket *</i> <b>wsi</b>,
571<i>const char *</i> <b>file</b>,
572<i>const char *</i> <b>content_type</b>)
573<h3>Arguments</h3>
574<dl>
575<dt><b>context</b>
576<dd>libwebsockets context
577<dt><b>wsi</b>
578<dd>Websocket instance (available from user callback)
579<dt><b>file</b>
580<dd>The file to issue over http
581<dt><b>content_type</b>
582<dd>The http content type, eg, text/html
583</dl>
584<h3>Description</h3>
585<blockquote>
586This function is intended to be called from the callback in response
587to http requests from the client. It allows the callback to issue
588local files down the http link in a single step.
589</blockquote>
590<hr>
Andy Green2fd3f2f2013-01-18 09:49:20 +0800591<h2>lws_frame_is_binary - </h2>
592<i>int</i>
593<b>lws_frame_is_binary</b>
594(<i>struct libwebsocket *</i> <b>wsi</b>)
595<h3>Arguments</h3>
596<dl>
597<dt><b>wsi</b>
598<dd>the connection we are inquiring about
599</dl>
600<h3>Description</h3>
601<blockquote>
602This is intended to be called from the LWS_CALLBACK_RECEIVE callback if
603it's interested to see if the frame it's dealing with was sent in binary
604mode.
605</blockquote>
606<hr>
Andy Green38e57bb2011-01-19 12:20:27 +0000607<h2>libwebsockets_remaining_packet_payload - Bytes to come before "overall" rx packet is complete</h2>
608<i>size_t</i>
609<b>libwebsockets_remaining_packet_payload</b>
610(<i>struct libwebsocket *</i> <b>wsi</b>)
611<h3>Arguments</h3>
612<dl>
613<dt><b>wsi</b>
614<dd>Websocket instance (available from user callback)
615</dl>
616<h3>Description</h3>
617<blockquote>
618This function is intended to be called from the callback if the
619user code is interested in "complete packets" from the client.
620libwebsockets just passes through payload as it comes and issues a buffer
621additionally when it hits a built-in limit. The LWS_CALLBACK_RECEIVE
622callback handler can use this API to find out if the buffer it has just
623been given is the last piece of a "complete packet" from the client --
624when that is the case <b>libwebsockets_remaining_packet_payload</b> will return
6250.
626<p>
627Many protocols won't care becuse their packets are always small.
628</blockquote>
629<hr>
Andy Green8f037e42010-12-19 22:13:26 +0000630<h2>callback - User server actions</h2>
Andy Green07b56e62011-10-03 19:30:22 +0800631<i>LWS_EXTERN int</i>
Andy Green8f037e42010-12-19 22:13:26 +0000632<b>callback</b>
Darin Willitsc19456f2011-02-14 17:52:39 +0000633(<i>struct libwebsocket_context *</i> <b>context</b>,
Andy Green62c54d22011-02-14 09:14:25 +0000634<i>struct libwebsocket *</i> <b>wsi</b>,
Andy Green8f037e42010-12-19 22:13:26 +0000635<i>enum libwebsocket_callback_reasons</i> <b>reason</b>,
636<i>void *</i> <b>user</b>,
637<i>void *</i> <b>in</b>,
638<i>size_t</i> <b>len</b>)
639<h3>Arguments</h3>
640<dl>
Andy Green32375b72011-02-19 08:32:53 +0000641<dt><b>context</b>
642<dd>Websockets context
Andy Green8f037e42010-12-19 22:13:26 +0000643<dt><b>wsi</b>
644<dd>Opaque websocket instance pointer
645<dt><b>reason</b>
646<dd>The reason for the call
647<dt><b>user</b>
648<dd>Pointer to per-session user data allocated by library
649<dt><b>in</b>
650<dd>Pointer used for some callback reasons
651<dt><b>len</b>
652<dd>Length set for some callback reasons
653</dl>
654<h3>Description</h3>
655<blockquote>
656This callback is the way the user controls what is served. All the
657protocol detail is hidden and handled by the library.
658<p>
659For each connection / session there is user data allocated that is
660pointed to by "user". You set the size of this user data area when
661the library is initialized with libwebsocket_create_server.
662<p>
663You get an opportunity to initialize user data when called back with
664LWS_CALLBACK_ESTABLISHED reason.
665</blockquote>
666<h3>LWS_CALLBACK_ESTABLISHED</h3>
667<blockquote>
Andy Green90c7cbc2011-01-27 06:26:52 +0000668after the server completes a handshake with
669an incoming client
670</blockquote>
David Brooks2c60d952012-04-20 12:19:01 +0800671<h3>LWS_CALLBACK_CLIENT_CONNECTION_ERROR</h3>
672<blockquote>
673the request client connection has
674been unable to complete a handshake with the remote server
675</blockquote>
Andy Green90c7cbc2011-01-27 06:26:52 +0000676<h3>LWS_CALLBACK_CLIENT_ESTABLISHED</h3>
677<blockquote>
678after your client connection completed
679a handshake with the remote server
Andy Green8f037e42010-12-19 22:13:26 +0000680</blockquote>
681<h3>LWS_CALLBACK_CLOSED</h3>
682<blockquote>
683when the websocket session ends
684</blockquote>
685<h3>LWS_CALLBACK_BROADCAST</h3>
686<blockquote>
687signal to send to client (you would use
688<b>libwebsocket_write</b> taking care about the
689special buffer requirements
690</blockquote>
691<h3>LWS_CALLBACK_RECEIVE</h3>
692<blockquote>
Andy Green90c7cbc2011-01-27 06:26:52 +0000693data has appeared for this server endpoint from a
694remote client, it can be found at *in and is
695len bytes long
696</blockquote>
Andy Greena6cbece2011-01-27 20:06:03 +0000697<h3>LWS_CALLBACK_CLIENT_RECEIVE_PONG</h3>
698<blockquote>
699if you elected to see PONG packets,
700they appear with this callback reason. PONG
701packets only exist in 04+ protocol
702</blockquote>
Andy Green90c7cbc2011-01-27 06:26:52 +0000703<h3>LWS_CALLBACK_CLIENT_RECEIVE</h3>
704<blockquote>
705data has appeared from the server for the
706client connection, it can be found at *in and
707is len bytes long
Andy Green8f037e42010-12-19 22:13:26 +0000708</blockquote>
709<h3>LWS_CALLBACK_HTTP</h3>
710<blockquote>
711an http request has come from a client that is not
712asking to upgrade the connection to a websocket
713one. This is a chance to serve http content,
714for example, to send a script to the client
715which will then open the websockets connection.
Andy Green7619c472011-01-23 17:47:08 +0000716<tt><b>in</b></tt> points to the URI path requested and
Andy Green8f037e42010-12-19 22:13:26 +0000717<b>libwebsockets_serve_http_file</b> makes it very
718simple to send back a file to the client.
Andy Green24b588b2013-01-13 09:53:18 +0800719Normally after sending the file you are done
720with the http connection, since the rest of the
721activity will come by websockets from the script
722that was delivered by http, so you will want to
723return 1; to close and free up the connection.
724That's important because it uses a slot in the
725total number of client connections allowed set
726by MAX_CLIENTS.
Andy Green8f037e42010-12-19 22:13:26 +0000727</blockquote>
Andy Greend280b6e2013-01-15 13:40:23 +0800728<h3>LWS_CALLBACK_HTTP_FILE_COMPLETION</h3>
729<blockquote>
730a file requested to be send down
731http link has completed.
732</blockquote>
Andy Greene9739ed2011-03-07 21:40:59 +0000733<h3>LWS_CALLBACK_SERVER_WRITEABLE</h3>
Andy Green90c7cbc2011-01-27 06:26:52 +0000734<blockquote>
Andy Greene9739ed2011-03-07 21:40:59 +0000735If you call
Andy Green90c7cbc2011-01-27 06:26:52 +0000736<b>libwebsocket_callback_on_writable</b> on a connection, you will
Andy Greene9739ed2011-03-07 21:40:59 +0000737get one of these callbacks coming when the connection socket
738is able to accept another write packet without blocking.
739If it already was able to take another packet without blocking,
740you'll get this callback at the next call to the service loop
741function. Notice that CLIENTs get LWS_CALLBACK_CLIENT_WRITEABLE
742and servers get LWS_CALLBACK_SERVER_WRITEABLE.
Andy Green90c7cbc2011-01-27 06:26:52 +0000743</blockquote>
Andy Green07034092011-02-13 08:37:12 +0000744<h3>LWS_CALLBACK_FILTER_NETWORK_CONNECTION</h3>
745<blockquote>
746called when a client connects to
747the server at network level; the connection is accepted but then
748passed to this callback to decide whether to hang up immediately
749or not, based on the client IP. <tt><b>user</b></tt> contains the connection
750socket's descriptor. Return non-zero to terminate
751the connection before sending or receiving anything.
752Because this happens immediately after the network connection
753from the client, there's no websocket protocol selected yet so
754this callback is issued only to protocol 0.
755</blockquote>
Andy Greenc85619d2011-02-13 08:25:26 +0000756<h3>LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION</h3>
757<blockquote>
758called when the handshake has
759been received and parsed from the client, but the response is
760not sent yet. Return non-zero to disallow the connection.
Andy Green07034092011-02-13 08:37:12 +0000761<tt><b>user</b></tt> is a pointer to an array of struct lws_tokens, you can
762use the header enums lws_token_indexes from libwebsockets.h
763to check for and read the supported header presence and
764content before deciding to allow the handshake to proceed or
765to kill the connection.
Andy Green0894bda2011-02-19 09:09:11 +0000766</blockquote>
767<h3>LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS</h3>
768<blockquote>
Andy Green6901cb32011-02-21 08:06:47 +0000769if configured for
Andy Green0894bda2011-02-19 09:09:11 +0000770including OpenSSL support, this callback allows your user code
771to perform extra <b>SSL_CTX_load_verify_locations</b> or similar
772calls to direct OpenSSL where to find certificates the client
773can use to confirm the remote server identity. <tt><b>user</b></tt> is the
774OpenSSL SSL_CTX*
Andy Green6901cb32011-02-21 08:06:47 +0000775</blockquote>
776<h3>LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS</h3>
777<blockquote>
778if configured for
779including OpenSSL support, this callback allows your user code
780to load extra certifcates into the server which allow it to
781verify the validity of certificates returned by clients. <tt><b>user</b></tt>
782is the server's OpenSSL SSL_CTX*
783</blockquote>
784<h3>LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION</h3>
785<blockquote>
786if the
787libwebsockets context was created with the option
788LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT, then this
789callback is generated during OpenSSL verification of the cert
790sent from the client. It is sent to protocol[0] callback as
791no protocol has been negotiated on the connection yet.
792Notice that the libwebsockets context and wsi are both NULL
793during this callback. See
794</blockquote>
795<h3>http</h3>
796<blockquote>
797//www.openssl.org/docs/ssl/SSL_CTX_set_verify.html
798to understand more detail about the OpenSSL callback that
799generates this libwebsockets callback and the meanings of the
800arguments passed. In this callback, <tt><b>user</b></tt> is the x509_ctx,
801<tt><b>in</b></tt> is the ssl pointer and <tt><b>len</b></tt> is preverify_ok
802Notice that this callback maintains libwebsocket return
803conventions, return 0 to mean the cert is OK or 1 to fail it.
804This also means that if you don't handle this callback then
805the default callback action of returning 0 allows the client
806certificates.
Andy Green385e7ad2011-03-01 21:06:02 +0000807</blockquote>
808<h3>LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER</h3>
809<blockquote>
810this callback happens
811when a client handshake is being compiled. <tt><b>user</b></tt> is NULL,
812<tt><b>in</b></tt> is a char **, it's pointing to a char * which holds the
813next location in the header buffer where you can add
814headers, and <tt><b>len</b></tt> is the remaining space in the header buffer,
815which is typically some hundreds of bytes. So, to add a canned
816cookie, your handler code might look similar to:
817<p>
818char **p = (char **)in;
819<p>
820if (len &lt; 100)
821return 1;
822<p>
823*p += sprintf(*p, "Cookie: a=b\x0d\x0a");
824<p>
825return 0;
826<p>
827Notice if you add anything, you just have to take care about
828the CRLF on the line you added. Obviously this callback is
829optional, if you don't handle it everything is fine.
830<p>
831Notice the callback is coming to protocols[0] all the time,
832because there is no specific protocol handshook yet.
Andy Greenc5114822011-03-06 10:29:35 +0000833</blockquote>
834<h3>LWS_CALLBACK_CONFIRM_EXTENSION_OKAY</h3>
835<blockquote>
836When the server handshake code
837sees that it does support a requested extension, before
838accepting the extension by additing to the list sent back to
839the client it gives this callback just to check that it's okay
840to use that extension. It calls back to the requested protocol
841and with <tt><b>in</b></tt> being the extension name, <tt><b>len</b></tt> is 0 and <tt><b>user</b></tt> is
842valid. Note though at this time the ESTABLISHED callback hasn't
843happened yet so if you initialize <tt><b>user</b></tt> content there, <tt><b>user</b></tt>
844content during this callback might not be useful for anything.
845Notice this callback comes to protocols[0].
Andy Greenc6517fa2011-03-06 13:15:29 +0000846</blockquote>
847<h3>LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED</h3>
848<blockquote>
849When a client
850connection is being prepared to start a handshake to a server,
851each supported extension is checked with protocols[0] callback
852with this reason, giving the user code a chance to suppress the
853claim to support that extension by returning non-zero. If
854unhandled, by default 0 will be returned and the extension
855support included in the header to the server. Notice this
856callback comes to protocols[0].
Andy Greenc85619d2011-02-13 08:25:26 +0000857<p>
858The next four reasons are optional and only need taking care of if you
859will be integrating libwebsockets sockets into an external polling
860array.
861</blockquote>
862<h3>LWS_CALLBACK_ADD_POLL_FD</h3>
863<blockquote>
864libwebsocket deals with its <b>poll</b> loop
865internally, but in the case you are integrating with another
866server you will need to have libwebsocket sockets share a
867polling array with the other server. This and the other
868POLL_FD related callbacks let you put your specialized
869poll array interface code in the callback for protocol 0, the
870first protocol you support, usually the HTTP protocol in the
871serving case. This callback happens when a socket needs to be
872</blockquote>
873<h3>added to the polling loop</h3>
874<blockquote>
875<tt><b>user</b></tt> contains the fd, and
876<tt><b>len</b></tt> is the events bitmap (like, POLLIN). If you are using the
877internal polling loop (the "service" callback), you can just
878ignore these callbacks.
879</blockquote>
880<h3>LWS_CALLBACK_DEL_POLL_FD</h3>
881<blockquote>
882This callback happens when a socket descriptor
883needs to be removed from an external polling array. <tt><b>user</b></tt> is
884the socket desricptor. If you are using the internal polling
885loop, you can just ignore it.
886</blockquote>
887<h3>LWS_CALLBACK_SET_MODE_POLL_FD</h3>
888<blockquote>
889This callback happens when libwebsockets
890wants to modify the events for the socket descriptor in <tt><b>user</b></tt>.
891The handler should OR <tt><b>len</b></tt> on to the events member of the pollfd
892struct for this socket descriptor. If you are using the
893internal polling loop, you can just ignore it.
894</blockquote>
895<h3>LWS_CALLBACK_CLEAR_MODE_POLL_FD</h3>
896<blockquote>
897This callback occurs when libwebsockets
898wants to modify the events for the socket descriptor in <tt><b>user</b></tt>.
899The handler should AND ~<tt><b>len</b></tt> on to the events member of the
900pollfd struct for this socket descriptor. If you are using the
901internal polling loop, you can just ignore it.
902</blockquote>
Andy Green8f037e42010-12-19 22:13:26 +0000903<hr>
Andy Green57b4e9a2011-03-06 13:14:46 +0000904<h2>extension_callback - Hooks to allow extensions to operate</h2>
Andy Green07b56e62011-10-03 19:30:22 +0800905<i>LWS_EXTERN int</i>
Andy Green57b4e9a2011-03-06 13:14:46 +0000906<b>extension_callback</b>
907(<i>struct libwebsocket_context *</i> <b>context</b>,
Andy Green46c2ea02011-03-22 09:04:01 +0000908<i>struct libwebsocket_extension *</i> <b>ext</b>,
Andy Green57b4e9a2011-03-06 13:14:46 +0000909<i>struct libwebsocket *</i> <b>wsi</b>,
David Brooks2c60d952012-04-20 12:19:01 +0800910<i>enum libwebsocket_extension_callback_reasons</i> <b>reason</b>,
Andy Green57b4e9a2011-03-06 13:14:46 +0000911<i>void *</i> <b>user</b>,
912<i>void *</i> <b>in</b>,
913<i>size_t</i> <b>len</b>)
914<h3>Arguments</h3>
915<dl>
916<dt><b>context</b>
917<dd>Websockets context
Andy Green46c2ea02011-03-22 09:04:01 +0000918<dt><b>ext</b>
919<dd>This extension
Andy Green57b4e9a2011-03-06 13:14:46 +0000920<dt><b>wsi</b>
921<dd>Opaque websocket instance pointer
922<dt><b>reason</b>
923<dd>The reason for the call
924<dt><b>user</b>
925<dd>Pointer to per-session user data allocated by library
926<dt><b>in</b>
927<dd>Pointer used for some callback reasons
928<dt><b>len</b>
929<dd>Length set for some callback reasons
930</dl>
931<h3>Description</h3>
932<blockquote>
933Each extension that is active on a particular connection receives
934callbacks during the connection lifetime to allow the extension to
935operate on websocket data and manage itself.
936<p>
937Libwebsockets takes care of allocating and freeing "user" memory for
938each active extension on each connection. That is what is pointed to
939by the <tt><b>user</b></tt> parameter.
940</blockquote>
941<h3>LWS_EXT_CALLBACK_CONSTRUCT</h3>
942<blockquote>
943called when the server has decided to
944select this extension from the list provided by the client,
945just before the server will send back the handshake accepting
946the connection with this extension active. This gives the
947extension a chance to initialize its connection context found
948in <tt><b>user</b></tt>.
949</blockquote>
Andy Green2366b1c2011-03-06 13:15:31 +0000950<h3>LWS_EXT_CALLBACK_CLIENT_CONSTRUCT</h3>
951<blockquote>
952same as LWS_EXT_CALLBACK_CONSTRUCT
953but called when client is instantiating this extension. Some
954extensions will work the same on client and server side and then
955you can just merge handlers for both CONSTRUCTS.
956</blockquote>
Andy Green57b4e9a2011-03-06 13:14:46 +0000957<h3>LWS_EXT_CALLBACK_DESTROY</h3>
958<blockquote>
959called when the connection the extension was
960being used on is about to be closed and deallocated. It's the
961last chance for the extension to deallocate anything it has
962allocated in the user data (pointed to by <tt><b>user</b></tt>) before the
Andy Green2366b1c2011-03-06 13:15:31 +0000963user data is deleted. This same callback is used whether you
964are in client or server instantiation context.
Andy Green57b4e9a2011-03-06 13:14:46 +0000965</blockquote>
966<h3>LWS_EXT_CALLBACK_PACKET_RX_PREPARSE</h3>
967<blockquote>
968when this extension was active on
969a connection, and a packet of data arrived at the connection,
970it is passed to this callback to give the extension a chance to
971change the data, eg, decompress it. <tt><b>user</b></tt> is pointing to the
972extension's private connection context data, <tt><b>in</b></tt> is pointing
973to an lws_tokens struct, it consists of a char * pointer called
974token, and an int called token_len. At entry, these are
975set to point to the received buffer and set to the content
976length. If the extension will grow the content, it should use
977a new buffer allocated in its private user context data and
978set the pointed-to lws_tokens members to point to its buffer.
979</blockquote>
980<h3>LWS_EXT_CALLBACK_PACKET_TX_PRESEND</h3>
981<blockquote>
982this works the same way as
983LWS_EXT_CALLBACK_PACKET_RX_PREPARSE above, except it gives the
984extension a chance to change websocket data just before it will
985be sent out. Using the same lws_token pointer scheme in <tt><b>in</b></tt>,
986the extension can change the buffer and the length to be
987transmitted how it likes. Again if it wants to grow the
988buffer safely, it should copy the data into its own buffer and
989set the lws_tokens token pointer to it.
990</blockquote>
991<hr>
Andy Green4f3943a2010-11-12 10:44:16 +0000992<h2>struct libwebsocket_protocols - List of protocols and handlers server supports.</h2>
993<b>struct libwebsocket_protocols</b> {<br>
994&nbsp; &nbsp; <i>const char *</i> <b>name</b>;<br>
David Brooks2c60d952012-04-20 12:19:01 +0800995&nbsp; &nbsp; <i>callback_function *</i> <b>callback</b>;<br>
Andy Green4f3943a2010-11-12 10:44:16 +0000996&nbsp; &nbsp; <i>size_t</i> <b>per_session_data_size</b>;<br>
Andy Greenb45993c2010-12-18 15:13:50 +0000997&nbsp; &nbsp; <i>struct libwebsocket_context *</i> <b>owning_server</b>;<br>
998&nbsp; &nbsp; <i>int</i> <b>broadcast_socket_port</b>;<br>
999&nbsp; &nbsp; <i>int</i> <b>broadcast_socket_user_fd</b>;<br>
1000&nbsp; &nbsp; <i>int</i> <b>protocol_index</b>;<br>
Andy Green4f3943a2010-11-12 10:44:16 +00001001};<br>
1002<h3>Members</h3>
1003<dl>
1004<dt><b>name</b>
1005<dd>Protocol name that must match the one given in the client
1006Javascript new WebSocket(url, 'protocol') name
1007<dt><b>callback</b>
1008<dd>The service callback used for this protocol. It allows the
1009service action for an entire protocol to be encapsulated in
1010the protocol-specific callback
1011<dt><b>per_session_data_size</b>
1012<dd>Each new connection using this protocol gets
1013this much memory allocated on connection establishment and
1014freed on connection takedown. A pointer to this per-connection
1015allocation is passed into the callback in the 'user' parameter
Andy Greenb45993c2010-12-18 15:13:50 +00001016<dt><b>owning_server</b>
1017<dd>the server init call fills in this opaque pointer when
1018registering this protocol with the server.
1019<dt><b>broadcast_socket_port</b>
1020<dd>the server init call fills this in with the
1021localhost port number used to forward broadcasts for this
1022protocol
1023<dt><b>broadcast_socket_user_fd</b>
1024<dd>the server init call fills this in ... the <b>main</b>
1025process context can write to this socket to perform broadcasts
1026(use the <b>libwebsockets_broadcast</b> api to do this instead,
1027it works from any process context)
1028<dt><b>protocol_index</b>
1029<dd>which protocol we are starting from zero
Andy Green4f3943a2010-11-12 10:44:16 +00001030</dl>
1031<h3>Description</h3>
1032<blockquote>
1033This structure represents one protocol supported by the server. An
1034array of these structures is passed to <b>libwebsocket_create_server</b>
1035allows as many protocols as you like to be handled by one server.
1036</blockquote>
1037<hr>
Andy Greend6e09112011-03-05 16:12:15 +00001038<h2>struct libwebsocket_extension - An extension we know how to cope with</h2>
1039<b>struct libwebsocket_extension</b> {<br>
1040&nbsp; &nbsp; <i>const char *</i> <b>name</b>;<br>
David Brooks2c60d952012-04-20 12:19:01 +08001041&nbsp; &nbsp; <i>extension_callback_function *</i> <b>callback</b>;<br>
Andy Greend6e09112011-03-05 16:12:15 +00001042&nbsp; &nbsp; <i>size_t</i> <b>per_session_data_size</b>;<br>
Andy Greenaa6fc442012-04-12 13:26:49 +08001043&nbsp; &nbsp; <i>void *</i> <b>per_context_private_data</b>;<br>
Andy Greend6e09112011-03-05 16:12:15 +00001044};<br>
1045<h3>Members</h3>
1046<dl>
1047<dt><b>name</b>
1048<dd>Formal extension name, eg, "deflate-stream"
1049<dt><b>callback</b>
1050<dd>Service callback
1051<dt><b>per_session_data_size</b>
1052<dd>Libwebsockets will auto-malloc this much
1053memory for the use of the extension, a pointer
1054to it comes in the <tt><b>user</b></tt> callback parameter
Andy Greenaa6fc442012-04-12 13:26:49 +08001055<dt><b>per_context_private_data</b>
1056<dd>Optional storage for this externsion that
1057is per-context, so it can track stuff across
1058all sessions, etc, if it wants
Andy Greend6e09112011-03-05 16:12:15 +00001059</dl>
1060<hr>