blob: e240eed6fcdd39b54b7b18084875e72e800f7444 [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 Greene92cd172011-01-19 13:11:55 +0000429<h2>libwebsockets_broadcast - Sends a buffer to the callback for all active connections of the given protocol.</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>
455<b>libwebsockets_broadcast</b> can be called from another fork context without
456having to take any care about data visibility between the processes, it'll
457"just work".
458</blockquote>
459<hr>
Andy Greenacbaee62013-01-18 22:00:22 +0800460<h2>lws_confirm_legit_wsi - </h2>
461<i>int</i>
462<b>lws_confirm_legit_wsi</b>
463(<i>struct libwebsocket *</i> <b>wsi</b>)
464<h3>Arguments</h3>
465<dl>
466<dt><b>wsi</b>
467<dd>struct libwebsocket to assess
468</dl>
469<h3>Description</h3>
470<blockquote>
471Performs consistecy checks on what the wsi claims and what the
472polling arrays hold. This'll catch a closed wsi still in use.
473Don't try to use on the listen (nonconnection) wsi as it will
474fail it. Otherwise 0 return == wsi seems consistent.
475</blockquote>
476<hr>
Andy Green43db0452013-01-10 19:50:35 +0800477<h2>lws_set_log_level - Set the logging bitfield</h2>
478<i>void</i>
479<b>lws_set_log_level</b>
Andy Greende8f27a2013-01-12 09:17:42 +0800480(<i>int</i> <b>level</b>,
Andy Green058ba812013-01-19 11:32:18 +0800481<i>void (*</i><b>log_emit_function</b>) <i>(int level, const char *line)</i>)
Andy Green43db0452013-01-10 19:50:35 +0800482<h3>Arguments</h3>
483<dl>
484<dt><b>level</b>
485<dd>OR together the LLL_ debug contexts you want output from
Andy Greende8f27a2013-01-12 09:17:42 +0800486<dt><b>log_emit_function</b>
487<dd>NULL to leave it as it is, or a user-supplied
488function to perform log string emission instead of
489the default stderr one.
Andy Green43db0452013-01-10 19:50:35 +0800490</dl>
491<h3>Description</h3>
492<blockquote>
Andy Greende8f27a2013-01-12 09:17:42 +0800493log level defaults to "err" and "warn" contexts enabled only and
494emission on stderr.
Andy Green43db0452013-01-10 19:50:35 +0800495</blockquote>
496<hr>
Andy Greend88146d2013-01-22 12:40:35 +0800497<h2>libwebsocket_write - Apply protocol then write data to client</h2>
498<i>int</i>
499<b>libwebsocket_write</b>
500(<i>struct libwebsocket *</i> <b>wsi</b>,
501<i>unsigned char *</i> <b>buf</b>,
502<i>size_t</i> <b>len</b>,
503<i>enum libwebsocket_write_protocol</i> <b>protocol</b>)
504<h3>Arguments</h3>
505<dl>
506<dt><b>wsi</b>
507<dd>Websocket instance (available from user callback)
508<dt><b>buf</b>
509<dd>The data to send. For data being sent on a websocket
510connection (ie, not default http), this buffer MUST have
511LWS_SEND_BUFFER_PRE_PADDING bytes valid BEFORE the pointer
512and an additional LWS_SEND_BUFFER_POST_PADDING bytes valid
513in the buffer after (buf + len). This is so the protocol
514header and trailer data can be added in-situ.
515<dt><b>len</b>
516<dd>Count of the data bytes in the payload starting from buf
517<dt><b>protocol</b>
518<dd>Use LWS_WRITE_HTTP to reply to an http connection, and one
519of LWS_WRITE_BINARY or LWS_WRITE_TEXT to send appropriate
520data on a websockets connection. Remember to allow the extra
521bytes before and after buf if LWS_WRITE_BINARY or LWS_WRITE_TEXT
522are used.
523</dl>
524<h3>Description</h3>
525<blockquote>
526This function provides the way to issue data back to the client
527for both http and websocket protocols.
528<p>
529In the case of sending using websocket protocol, be sure to allocate
530valid storage before and after buf as explained above. This scheme
531allows maximum efficiency of sending data and protocol in a single
532packet while not burdening the user code with any protocol knowledge.
533</blockquote>
534<hr>
535<h2>libwebsockets_serve_http_file - Send a file back to the client using http</h2>
536<i>int</i>
537<b>libwebsockets_serve_http_file</b>
538(<i>struct libwebsocket_context *</i> <b>context</b>,
539<i>struct libwebsocket *</i> <b>wsi</b>,
540<i>const char *</i> <b>file</b>,
541<i>const char *</i> <b>content_type</b>)
542<h3>Arguments</h3>
543<dl>
544<dt><b>context</b>
545<dd>libwebsockets context
546<dt><b>wsi</b>
547<dd>Websocket instance (available from user callback)
548<dt><b>file</b>
549<dd>The file to issue over http
550<dt><b>content_type</b>
551<dd>The http content type, eg, text/html
552</dl>
553<h3>Description</h3>
554<blockquote>
555This function is intended to be called from the callback in response
556to http requests from the client. It allows the callback to issue
557local files down the http link in a single step.
558</blockquote>
559<hr>
Andy Green2fd3f2f2013-01-18 09:49:20 +0800560<h2>lws_frame_is_binary - </h2>
561<i>int</i>
562<b>lws_frame_is_binary</b>
563(<i>struct libwebsocket *</i> <b>wsi</b>)
564<h3>Arguments</h3>
565<dl>
566<dt><b>wsi</b>
567<dd>the connection we are inquiring about
568</dl>
569<h3>Description</h3>
570<blockquote>
571This is intended to be called from the LWS_CALLBACK_RECEIVE callback if
572it's interested to see if the frame it's dealing with was sent in binary
573mode.
574</blockquote>
575<hr>
Andy Green38e57bb2011-01-19 12:20:27 +0000576<h2>libwebsockets_remaining_packet_payload - Bytes to come before "overall" rx packet is complete</h2>
577<i>size_t</i>
578<b>libwebsockets_remaining_packet_payload</b>
579(<i>struct libwebsocket *</i> <b>wsi</b>)
580<h3>Arguments</h3>
581<dl>
582<dt><b>wsi</b>
583<dd>Websocket instance (available from user callback)
584</dl>
585<h3>Description</h3>
586<blockquote>
587This function is intended to be called from the callback if the
588user code is interested in "complete packets" from the client.
589libwebsockets just passes through payload as it comes and issues a buffer
590additionally when it hits a built-in limit. The LWS_CALLBACK_RECEIVE
591callback handler can use this API to find out if the buffer it has just
592been given is the last piece of a "complete packet" from the client --
593when that is the case <b>libwebsockets_remaining_packet_payload</b> will return
5940.
595<p>
596Many protocols won't care becuse their packets are always small.
597</blockquote>
598<hr>
Andy Green8f037e42010-12-19 22:13:26 +0000599<h2>callback - User server actions</h2>
Andy Green07b56e62011-10-03 19:30:22 +0800600<i>LWS_EXTERN int</i>
Andy Green8f037e42010-12-19 22:13:26 +0000601<b>callback</b>
Darin Willitsc19456f2011-02-14 17:52:39 +0000602(<i>struct libwebsocket_context *</i> <b>context</b>,
Andy Green62c54d22011-02-14 09:14:25 +0000603<i>struct libwebsocket *</i> <b>wsi</b>,
Andy Green8f037e42010-12-19 22:13:26 +0000604<i>enum libwebsocket_callback_reasons</i> <b>reason</b>,
605<i>void *</i> <b>user</b>,
606<i>void *</i> <b>in</b>,
607<i>size_t</i> <b>len</b>)
608<h3>Arguments</h3>
609<dl>
Andy Green32375b72011-02-19 08:32:53 +0000610<dt><b>context</b>
611<dd>Websockets context
Andy Green8f037e42010-12-19 22:13:26 +0000612<dt><b>wsi</b>
613<dd>Opaque websocket instance pointer
614<dt><b>reason</b>
615<dd>The reason for the call
616<dt><b>user</b>
617<dd>Pointer to per-session user data allocated by library
618<dt><b>in</b>
619<dd>Pointer used for some callback reasons
620<dt><b>len</b>
621<dd>Length set for some callback reasons
622</dl>
623<h3>Description</h3>
624<blockquote>
625This callback is the way the user controls what is served. All the
626protocol detail is hidden and handled by the library.
627<p>
628For each connection / session there is user data allocated that is
629pointed to by "user". You set the size of this user data area when
630the library is initialized with libwebsocket_create_server.
631<p>
632You get an opportunity to initialize user data when called back with
633LWS_CALLBACK_ESTABLISHED reason.
634</blockquote>
635<h3>LWS_CALLBACK_ESTABLISHED</h3>
636<blockquote>
Andy Green90c7cbc2011-01-27 06:26:52 +0000637after the server completes a handshake with
638an incoming client
639</blockquote>
David Brooks2c60d952012-04-20 12:19:01 +0800640<h3>LWS_CALLBACK_CLIENT_CONNECTION_ERROR</h3>
641<blockquote>
642the request client connection has
643been unable to complete a handshake with the remote server
644</blockquote>
Andy Green90c7cbc2011-01-27 06:26:52 +0000645<h3>LWS_CALLBACK_CLIENT_ESTABLISHED</h3>
646<blockquote>
647after your client connection completed
648a handshake with the remote server
Andy Green8f037e42010-12-19 22:13:26 +0000649</blockquote>
650<h3>LWS_CALLBACK_CLOSED</h3>
651<blockquote>
652when the websocket session ends
653</blockquote>
654<h3>LWS_CALLBACK_BROADCAST</h3>
655<blockquote>
656signal to send to client (you would use
657<b>libwebsocket_write</b> taking care about the
658special buffer requirements
659</blockquote>
660<h3>LWS_CALLBACK_RECEIVE</h3>
661<blockquote>
Andy Green90c7cbc2011-01-27 06:26:52 +0000662data has appeared for this server endpoint from a
663remote client, it can be found at *in and is
664len bytes long
665</blockquote>
Andy Greena6cbece2011-01-27 20:06:03 +0000666<h3>LWS_CALLBACK_CLIENT_RECEIVE_PONG</h3>
667<blockquote>
668if you elected to see PONG packets,
669they appear with this callback reason. PONG
670packets only exist in 04+ protocol
671</blockquote>
Andy Green90c7cbc2011-01-27 06:26:52 +0000672<h3>LWS_CALLBACK_CLIENT_RECEIVE</h3>
673<blockquote>
674data has appeared from the server for the
675client connection, it can be found at *in and
676is len bytes long
Andy Green8f037e42010-12-19 22:13:26 +0000677</blockquote>
678<h3>LWS_CALLBACK_HTTP</h3>
679<blockquote>
680an http request has come from a client that is not
681asking to upgrade the connection to a websocket
682one. This is a chance to serve http content,
683for example, to send a script to the client
684which will then open the websockets connection.
Andy Green7619c472011-01-23 17:47:08 +0000685<tt><b>in</b></tt> points to the URI path requested and
Andy Green8f037e42010-12-19 22:13:26 +0000686<b>libwebsockets_serve_http_file</b> makes it very
687simple to send back a file to the client.
Andy Green24b588b2013-01-13 09:53:18 +0800688Normally after sending the file you are done
689with the http connection, since the rest of the
690activity will come by websockets from the script
691that was delivered by http, so you will want to
692return 1; to close and free up the connection.
693That's important because it uses a slot in the
694total number of client connections allowed set
695by MAX_CLIENTS.
Andy Green8f037e42010-12-19 22:13:26 +0000696</blockquote>
Andy Greend280b6e2013-01-15 13:40:23 +0800697<h3>LWS_CALLBACK_HTTP_FILE_COMPLETION</h3>
698<blockquote>
699a file requested to be send down
700http link has completed.
701</blockquote>
Andy Greene9739ed2011-03-07 21:40:59 +0000702<h3>LWS_CALLBACK_SERVER_WRITEABLE</h3>
Andy Green90c7cbc2011-01-27 06:26:52 +0000703<blockquote>
Andy Greene9739ed2011-03-07 21:40:59 +0000704If you call
Andy Green90c7cbc2011-01-27 06:26:52 +0000705<b>libwebsocket_callback_on_writable</b> on a connection, you will
Andy Greene9739ed2011-03-07 21:40:59 +0000706get one of these callbacks coming when the connection socket
707is able to accept another write packet without blocking.
708If it already was able to take another packet without blocking,
709you'll get this callback at the next call to the service loop
710function. Notice that CLIENTs get LWS_CALLBACK_CLIENT_WRITEABLE
711and servers get LWS_CALLBACK_SERVER_WRITEABLE.
Andy Green90c7cbc2011-01-27 06:26:52 +0000712</blockquote>
Andy Green07034092011-02-13 08:37:12 +0000713<h3>LWS_CALLBACK_FILTER_NETWORK_CONNECTION</h3>
714<blockquote>
715called when a client connects to
716the server at network level; the connection is accepted but then
717passed to this callback to decide whether to hang up immediately
718or not, based on the client IP. <tt><b>user</b></tt> contains the connection
719socket's descriptor. Return non-zero to terminate
720the connection before sending or receiving anything.
721Because this happens immediately after the network connection
722from the client, there's no websocket protocol selected yet so
723this callback is issued only to protocol 0.
724</blockquote>
Andy Greenc85619d2011-02-13 08:25:26 +0000725<h3>LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION</h3>
726<blockquote>
727called when the handshake has
728been received and parsed from the client, but the response is
729not sent yet. Return non-zero to disallow the connection.
Andy Green07034092011-02-13 08:37:12 +0000730<tt><b>user</b></tt> is a pointer to an array of struct lws_tokens, you can
731use the header enums lws_token_indexes from libwebsockets.h
732to check for and read the supported header presence and
733content before deciding to allow the handshake to proceed or
734to kill the connection.
Andy Green0894bda2011-02-19 09:09:11 +0000735</blockquote>
736<h3>LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS</h3>
737<blockquote>
Andy Green6901cb32011-02-21 08:06:47 +0000738if configured for
Andy Green0894bda2011-02-19 09:09:11 +0000739including OpenSSL support, this callback allows your user code
740to perform extra <b>SSL_CTX_load_verify_locations</b> or similar
741calls to direct OpenSSL where to find certificates the client
742can use to confirm the remote server identity. <tt><b>user</b></tt> is the
743OpenSSL SSL_CTX*
Andy Green6901cb32011-02-21 08:06:47 +0000744</blockquote>
745<h3>LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS</h3>
746<blockquote>
747if configured for
748including OpenSSL support, this callback allows your user code
749to load extra certifcates into the server which allow it to
750verify the validity of certificates returned by clients. <tt><b>user</b></tt>
751is the server's OpenSSL SSL_CTX*
752</blockquote>
753<h3>LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION</h3>
754<blockquote>
755if the
756libwebsockets context was created with the option
757LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT, then this
758callback is generated during OpenSSL verification of the cert
759sent from the client. It is sent to protocol[0] callback as
760no protocol has been negotiated on the connection yet.
761Notice that the libwebsockets context and wsi are both NULL
762during this callback. See
763</blockquote>
764<h3>http</h3>
765<blockquote>
766//www.openssl.org/docs/ssl/SSL_CTX_set_verify.html
767to understand more detail about the OpenSSL callback that
768generates this libwebsockets callback and the meanings of the
769arguments passed. In this callback, <tt><b>user</b></tt> is the x509_ctx,
770<tt><b>in</b></tt> is the ssl pointer and <tt><b>len</b></tt> is preverify_ok
771Notice that this callback maintains libwebsocket return
772conventions, return 0 to mean the cert is OK or 1 to fail it.
773This also means that if you don't handle this callback then
774the default callback action of returning 0 allows the client
775certificates.
Andy Green385e7ad2011-03-01 21:06:02 +0000776</blockquote>
777<h3>LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER</h3>
778<blockquote>
779this callback happens
780when a client handshake is being compiled. <tt><b>user</b></tt> is NULL,
781<tt><b>in</b></tt> is a char **, it's pointing to a char * which holds the
782next location in the header buffer where you can add
783headers, and <tt><b>len</b></tt> is the remaining space in the header buffer,
784which is typically some hundreds of bytes. So, to add a canned
785cookie, your handler code might look similar to:
786<p>
787char **p = (char **)in;
788<p>
789if (len &lt; 100)
790return 1;
791<p>
792*p += sprintf(*p, "Cookie: a=b\x0d\x0a");
793<p>
794return 0;
795<p>
796Notice if you add anything, you just have to take care about
797the CRLF on the line you added. Obviously this callback is
798optional, if you don't handle it everything is fine.
799<p>
800Notice the callback is coming to protocols[0] all the time,
801because there is no specific protocol handshook yet.
Andy Greenc5114822011-03-06 10:29:35 +0000802</blockquote>
803<h3>LWS_CALLBACK_CONFIRM_EXTENSION_OKAY</h3>
804<blockquote>
805When the server handshake code
806sees that it does support a requested extension, before
807accepting the extension by additing to the list sent back to
808the client it gives this callback just to check that it's okay
809to use that extension. It calls back to the requested protocol
810and with <tt><b>in</b></tt> being the extension name, <tt><b>len</b></tt> is 0 and <tt><b>user</b></tt> is
811valid. Note though at this time the ESTABLISHED callback hasn't
812happened yet so if you initialize <tt><b>user</b></tt> content there, <tt><b>user</b></tt>
813content during this callback might not be useful for anything.
814Notice this callback comes to protocols[0].
Andy Greenc6517fa2011-03-06 13:15:29 +0000815</blockquote>
816<h3>LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED</h3>
817<blockquote>
818When a client
819connection is being prepared to start a handshake to a server,
820each supported extension is checked with protocols[0] callback
821with this reason, giving the user code a chance to suppress the
822claim to support that extension by returning non-zero. If
823unhandled, by default 0 will be returned and the extension
824support included in the header to the server. Notice this
825callback comes to protocols[0].
Andy Greenc85619d2011-02-13 08:25:26 +0000826<p>
827The next four reasons are optional and only need taking care of if you
828will be integrating libwebsockets sockets into an external polling
829array.
830</blockquote>
831<h3>LWS_CALLBACK_ADD_POLL_FD</h3>
832<blockquote>
833libwebsocket deals with its <b>poll</b> loop
834internally, but in the case you are integrating with another
835server you will need to have libwebsocket sockets share a
836polling array with the other server. This and the other
837POLL_FD related callbacks let you put your specialized
838poll array interface code in the callback for protocol 0, the
839first protocol you support, usually the HTTP protocol in the
840serving case. This callback happens when a socket needs to be
841</blockquote>
842<h3>added to the polling loop</h3>
843<blockquote>
844<tt><b>user</b></tt> contains the fd, and
845<tt><b>len</b></tt> is the events bitmap (like, POLLIN). If you are using the
846internal polling loop (the "service" callback), you can just
847ignore these callbacks.
848</blockquote>
849<h3>LWS_CALLBACK_DEL_POLL_FD</h3>
850<blockquote>
851This callback happens when a socket descriptor
852needs to be removed from an external polling array. <tt><b>user</b></tt> is
853the socket desricptor. If you are using the internal polling
854loop, you can just ignore it.
855</blockquote>
856<h3>LWS_CALLBACK_SET_MODE_POLL_FD</h3>
857<blockquote>
858This callback happens when libwebsockets
859wants to modify the events for the socket descriptor in <tt><b>user</b></tt>.
860The handler should OR <tt><b>len</b></tt> on to the events member of the pollfd
861struct for this socket descriptor. If you are using the
862internal polling loop, you can just ignore it.
863</blockquote>
864<h3>LWS_CALLBACK_CLEAR_MODE_POLL_FD</h3>
865<blockquote>
866This callback occurs when libwebsockets
867wants to modify the events for the socket descriptor in <tt><b>user</b></tt>.
868The handler should AND ~<tt><b>len</b></tt> on to the events member of the
869pollfd struct for this socket descriptor. If you are using the
870internal polling loop, you can just ignore it.
871</blockquote>
Andy Green8f037e42010-12-19 22:13:26 +0000872<hr>
Andy Green57b4e9a2011-03-06 13:14:46 +0000873<h2>extension_callback - Hooks to allow extensions to operate</h2>
Andy Green07b56e62011-10-03 19:30:22 +0800874<i>LWS_EXTERN int</i>
Andy Green57b4e9a2011-03-06 13:14:46 +0000875<b>extension_callback</b>
876(<i>struct libwebsocket_context *</i> <b>context</b>,
Andy Green46c2ea02011-03-22 09:04:01 +0000877<i>struct libwebsocket_extension *</i> <b>ext</b>,
Andy Green57b4e9a2011-03-06 13:14:46 +0000878<i>struct libwebsocket *</i> <b>wsi</b>,
David Brooks2c60d952012-04-20 12:19:01 +0800879<i>enum libwebsocket_extension_callback_reasons</i> <b>reason</b>,
Andy Green57b4e9a2011-03-06 13:14:46 +0000880<i>void *</i> <b>user</b>,
881<i>void *</i> <b>in</b>,
882<i>size_t</i> <b>len</b>)
883<h3>Arguments</h3>
884<dl>
885<dt><b>context</b>
886<dd>Websockets context
Andy Green46c2ea02011-03-22 09:04:01 +0000887<dt><b>ext</b>
888<dd>This extension
Andy Green57b4e9a2011-03-06 13:14:46 +0000889<dt><b>wsi</b>
890<dd>Opaque websocket instance pointer
891<dt><b>reason</b>
892<dd>The reason for the call
893<dt><b>user</b>
894<dd>Pointer to per-session user data allocated by library
895<dt><b>in</b>
896<dd>Pointer used for some callback reasons
897<dt><b>len</b>
898<dd>Length set for some callback reasons
899</dl>
900<h3>Description</h3>
901<blockquote>
902Each extension that is active on a particular connection receives
903callbacks during the connection lifetime to allow the extension to
904operate on websocket data and manage itself.
905<p>
906Libwebsockets takes care of allocating and freeing "user" memory for
907each active extension on each connection. That is what is pointed to
908by the <tt><b>user</b></tt> parameter.
909</blockquote>
910<h3>LWS_EXT_CALLBACK_CONSTRUCT</h3>
911<blockquote>
912called when the server has decided to
913select this extension from the list provided by the client,
914just before the server will send back the handshake accepting
915the connection with this extension active. This gives the
916extension a chance to initialize its connection context found
917in <tt><b>user</b></tt>.
918</blockquote>
Andy Green2366b1c2011-03-06 13:15:31 +0000919<h3>LWS_EXT_CALLBACK_CLIENT_CONSTRUCT</h3>
920<blockquote>
921same as LWS_EXT_CALLBACK_CONSTRUCT
922but called when client is instantiating this extension. Some
923extensions will work the same on client and server side and then
924you can just merge handlers for both CONSTRUCTS.
925</blockquote>
Andy Green57b4e9a2011-03-06 13:14:46 +0000926<h3>LWS_EXT_CALLBACK_DESTROY</h3>
927<blockquote>
928called when the connection the extension was
929being used on is about to be closed and deallocated. It's the
930last chance for the extension to deallocate anything it has
931allocated in the user data (pointed to by <tt><b>user</b></tt>) before the
Andy Green2366b1c2011-03-06 13:15:31 +0000932user data is deleted. This same callback is used whether you
933are in client or server instantiation context.
Andy Green57b4e9a2011-03-06 13:14:46 +0000934</blockquote>
935<h3>LWS_EXT_CALLBACK_PACKET_RX_PREPARSE</h3>
936<blockquote>
937when this extension was active on
938a connection, and a packet of data arrived at the connection,
939it is passed to this callback to give the extension a chance to
940change the data, eg, decompress it. <tt><b>user</b></tt> is pointing to the
941extension's private connection context data, <tt><b>in</b></tt> is pointing
942to an lws_tokens struct, it consists of a char * pointer called
943token, and an int called token_len. At entry, these are
944set to point to the received buffer and set to the content
945length. If the extension will grow the content, it should use
946a new buffer allocated in its private user context data and
947set the pointed-to lws_tokens members to point to its buffer.
948</blockquote>
949<h3>LWS_EXT_CALLBACK_PACKET_TX_PRESEND</h3>
950<blockquote>
951this works the same way as
952LWS_EXT_CALLBACK_PACKET_RX_PREPARSE above, except it gives the
953extension a chance to change websocket data just before it will
954be sent out. Using the same lws_token pointer scheme in <tt><b>in</b></tt>,
955the extension can change the buffer and the length to be
956transmitted how it likes. Again if it wants to grow the
957buffer safely, it should copy the data into its own buffer and
958set the lws_tokens token pointer to it.
959</blockquote>
960<hr>
Andy Green4f3943a2010-11-12 10:44:16 +0000961<h2>struct libwebsocket_protocols - List of protocols and handlers server supports.</h2>
962<b>struct libwebsocket_protocols</b> {<br>
963&nbsp; &nbsp; <i>const char *</i> <b>name</b>;<br>
David Brooks2c60d952012-04-20 12:19:01 +0800964&nbsp; &nbsp; <i>callback_function *</i> <b>callback</b>;<br>
Andy Green4f3943a2010-11-12 10:44:16 +0000965&nbsp; &nbsp; <i>size_t</i> <b>per_session_data_size</b>;<br>
Andy Greenb45993c2010-12-18 15:13:50 +0000966&nbsp; &nbsp; <i>struct libwebsocket_context *</i> <b>owning_server</b>;<br>
967&nbsp; &nbsp; <i>int</i> <b>broadcast_socket_port</b>;<br>
968&nbsp; &nbsp; <i>int</i> <b>broadcast_socket_user_fd</b>;<br>
969&nbsp; &nbsp; <i>int</i> <b>protocol_index</b>;<br>
Andy Green4f3943a2010-11-12 10:44:16 +0000970};<br>
971<h3>Members</h3>
972<dl>
973<dt><b>name</b>
974<dd>Protocol name that must match the one given in the client
975Javascript new WebSocket(url, 'protocol') name
976<dt><b>callback</b>
977<dd>The service callback used for this protocol. It allows the
978service action for an entire protocol to be encapsulated in
979the protocol-specific callback
980<dt><b>per_session_data_size</b>
981<dd>Each new connection using this protocol gets
982this much memory allocated on connection establishment and
983freed on connection takedown. A pointer to this per-connection
984allocation is passed into the callback in the 'user' parameter
Andy Greenb45993c2010-12-18 15:13:50 +0000985<dt><b>owning_server</b>
986<dd>the server init call fills in this opaque pointer when
987registering this protocol with the server.
988<dt><b>broadcast_socket_port</b>
989<dd>the server init call fills this in with the
990localhost port number used to forward broadcasts for this
991protocol
992<dt><b>broadcast_socket_user_fd</b>
993<dd>the server init call fills this in ... the <b>main</b>
994process context can write to this socket to perform broadcasts
995(use the <b>libwebsockets_broadcast</b> api to do this instead,
996it works from any process context)
997<dt><b>protocol_index</b>
998<dd>which protocol we are starting from zero
Andy Green4f3943a2010-11-12 10:44:16 +0000999</dl>
1000<h3>Description</h3>
1001<blockquote>
1002This structure represents one protocol supported by the server. An
1003array of these structures is passed to <b>libwebsocket_create_server</b>
1004allows as many protocols as you like to be handled by one server.
1005</blockquote>
1006<hr>
Andy Greend6e09112011-03-05 16:12:15 +00001007<h2>struct libwebsocket_extension - An extension we know how to cope with</h2>
1008<b>struct libwebsocket_extension</b> {<br>
1009&nbsp; &nbsp; <i>const char *</i> <b>name</b>;<br>
David Brooks2c60d952012-04-20 12:19:01 +08001010&nbsp; &nbsp; <i>extension_callback_function *</i> <b>callback</b>;<br>
Andy Greend6e09112011-03-05 16:12:15 +00001011&nbsp; &nbsp; <i>size_t</i> <b>per_session_data_size</b>;<br>
Andy Greenaa6fc442012-04-12 13:26:49 +08001012&nbsp; &nbsp; <i>void *</i> <b>per_context_private_data</b>;<br>
Andy Greend6e09112011-03-05 16:12:15 +00001013};<br>
1014<h3>Members</h3>
1015<dl>
1016<dt><b>name</b>
1017<dd>Formal extension name, eg, "deflate-stream"
1018<dt><b>callback</b>
1019<dd>Service callback
1020<dt><b>per_session_data_size</b>
1021<dd>Libwebsockets will auto-malloc this much
1022memory for the use of the extension, a pointer
1023to it comes in the <tt><b>user</b></tt> callback parameter
Andy Greenaa6fc442012-04-12 13:26:49 +08001024<dt><b>per_context_private_data</b>
1025<dd>Optional storage for this externsion that
1026is per-context, so it can track stuff across
1027all sessions, etc, if it wants
Andy Greend6e09112011-03-05 16:12:15 +00001028</dl>
1029<hr>