blob: 7c8e1c1834bbfbb96795205c8d08d8649d490980 [file] [log] [blame]
Andy Green2577c832013-03-11 20:37:03 +08001<h2>lws_frame_is_binary - </h2>
2<i>int</i>
3<b>lws_frame_is_binary</b>
4(<i>struct libwebsocket *</i> <b>wsi</b>)
Andy Greend88146d2013-01-22 12:40:35 +08005<h3>Arguments</h3>
6<dl>
Andy Green2577c832013-03-11 20:37:03 +08007<dt><b>wsi</b>
8<dd>the connection we are inquiring about
Andy Greend88146d2013-01-22 12:40:35 +08009</dl>
10<h3>Description</h3>
11<blockquote>
Andy Green2577c832013-03-11 20:37:03 +080012This is intended to be called from the LWS_CALLBACK_RECEIVE callback if
13it's interested to see if the frame it's dealing with was sent in binary
14mode.
Andy Greend88146d2013-01-22 12:40:35 +080015</blockquote>
16<hr>
Andy Green2577c832013-03-11 20:37:03 +080017<h2>libwebsockets_remaining_packet_payload - Bytes to come before "overall" rx packet is complete</h2>
18<i>size_t</i>
19<b>libwebsockets_remaining_packet_payload</b>
20(<i>struct libwebsocket *</i> <b>wsi</b>)
Andy Greend88146d2013-01-22 12:40:35 +080021<h3>Arguments</h3>
22<dl>
Andy Green2577c832013-03-11 20:37:03 +080023<dt><b>wsi</b>
24<dd>Websocket instance (available from user callback)
Andy Greend88146d2013-01-22 12:40:35 +080025</dl>
26<h3>Description</h3>
27<blockquote>
Andy Green2577c832013-03-11 20:37:03 +080028This function is intended to be called from the callback if the
29user code is interested in "complete packets" from the client.
30libwebsockets just passes through payload as it comes and issues a buffer
31additionally when it hits a built-in limit. The LWS_CALLBACK_RECEIVE
32callback handler can use this API to find out if the buffer it has just
33been given is the last piece of a "complete packet" from the client --
34when that is the case <b>libwebsockets_remaining_packet_payload</b> will return
350.
36<p>
37Many protocols won't care becuse their packets are always small.
Andy Greend88146d2013-01-22 12:40:35 +080038</blockquote>
39<hr>
Andy Green7b405452013-02-01 10:50:15 +080040<h2>lws_get_library_version - </h2>
41<i>const char *</i>
42<b>lws_get_library_version</b>
43(<i></i> <b>void</b>)
44<h3>Arguments</h3>
45<dl>
46<dt><b>void</b>
47<dd>no arguments
48</dl>
49<h3>Description</h3>
50<blockquote>
51<p>
52returns a const char * to a string like "1.1 178d78c"
53representing the library version followed by the git head hash it
54was built from
55</blockquote>
56<hr>
Andy Green07034092011-02-13 08:37:12 +000057<h2>libwebsockets_get_peer_addresses - Get client address information</h2>
58<i>void</i>
59<b>libwebsockets_get_peer_addresses</b>
Andy Greenaaf0b9f2013-01-30 08:12:20 +080060(<i>struct libwebsocket_context *</i> <b>context</b>,
61<i>struct libwebsocket *</i> <b>wsi</b>,
62<i>int</i> <b>fd</b>,
Andy Green07034092011-02-13 08:37:12 +000063<i>char *</i> <b>name</b>,
64<i>int</i> <b>name_len</b>,
65<i>char *</i> <b>rip</b>,
66<i>int</i> <b>rip_len</b>)
67<h3>Arguments</h3>
68<dl>
Andy Greenaaf0b9f2013-01-30 08:12:20 +080069<dt><b>context</b>
70<dd>Libwebsockets context
71<dt><b>wsi</b>
72<dd>Local struct libwebsocket associated with
Andy Green07034092011-02-13 08:37:12 +000073<dt><b>fd</b>
74<dd>Connection socket descriptor
75<dt><b>name</b>
76<dd>Buffer to take client address name
77<dt><b>name_len</b>
78<dd>Length of client address name buffer
79<dt><b>rip</b>
80<dd>Buffer to take client address IP qotted quad
81<dt><b>rip_len</b>
82<dd>Length of client address IP buffer
83</dl>
84<h3>Description</h3>
85<blockquote>
86This function fills in <tt><b>name</b></tt> and <tt><b>rip</b></tt> with the name and IP of
87the client connected with socket descriptor <tt><b>fd</b></tt>. Names may be
88truncated if there is not enough room. If either cannot be
89determined, they will be returned as valid zero-length strings.
90</blockquote>
91<hr>
Andy Green9f990342011-02-12 11:57:45 +000092<h2>libwebsocket_service_fd - Service polled socket with something waiting</h2>
93<i>int</i>
94<b>libwebsocket_service_fd</b>
Peter Hinz56885f32011-03-02 22:03:47 +000095(<i>struct libwebsocket_context *</i> <b>context</b>,
Andy Green9f990342011-02-12 11:57:45 +000096<i>struct pollfd *</i> <b>pollfd</b>)
97<h3>Arguments</h3>
98<dl>
Peter Hinz56885f32011-03-02 22:03:47 +000099<dt><b>context</b>
Andy Green9f990342011-02-12 11:57:45 +0000100<dd>Websocket context
101<dt><b>pollfd</b>
102<dd>The pollfd entry describing the socket fd and which events
103happened.
104</dl>
105<h3>Description</h3>
106<blockquote>
Andy Green75006172013-01-22 12:32:11 +0800107This function takes a pollfd that has POLLIN or POLLOUT activity and
Andy Greenb5b23192013-02-11 17:13:32 +0800108services it according to the state of the associated
109struct libwebsocket.
Andy Green75006172013-01-22 12:32:11 +0800110<p>
111The one call deals with all "service" that might happen on a socket
112including listen accepts, http files as well as websocket protocol.
Andy Green2577c832013-03-11 20:37:03 +0800113<p>
114If a pollfd says it has something, you can just pass it to
115<b>libwebsocket_serice_fd</b> whether it is a socket handled by lws or not.
116If it sees it is a lws socket, the traffic will be handled and
117pollfd-&gt;revents will be zeroed now.
118<p>
119If the socket is foreign to lws, it leaves revents alone. So you can
120see if you should service yourself by checking the pollfd revents
121after letting lws try to service it.
Andy Green9f990342011-02-12 11:57:45 +0000122</blockquote>
123<hr>
Andy Green6964bb52011-01-23 16:50:33 +0000124<h2>libwebsocket_context_destroy - Destroy the websocket context</h2>
125<i>void</i>
126<b>libwebsocket_context_destroy</b>
Peter Hinz56885f32011-03-02 22:03:47 +0000127(<i>struct libwebsocket_context *</i> <b>context</b>)
Andy Green6964bb52011-01-23 16:50:33 +0000128<h3>Arguments</h3>
129<dl>
Peter Hinz56885f32011-03-02 22:03:47 +0000130<dt><b>context</b>
Andy Green6964bb52011-01-23 16:50:33 +0000131<dd>Websocket context
132</dl>
133<h3>Description</h3>
134<blockquote>
135This function closes any active connections and then frees the
136context. After calling this, any further use of the context is
137undefined.
138</blockquote>
139<hr>
Andy Greenb5b23192013-02-11 17:13:32 +0800140<h2>libwebsocket_context_user - get the user data associated with the context</h2>
Andy Greend88146d2013-01-22 12:40:35 +0800141<i>LWS_EXTERN void *</i>
142<b>libwebsocket_context_user</b>
143(<i>struct libwebsocket_context *</i> <b>context</b>)
144<h3>Arguments</h3>
145<dl>
146<dt><b>context</b>
147<dd>Websocket context
148</dl>
149<h3>Description</h3>
150<blockquote>
151This returns the optional user allocation that can be attached to
152the context the sockets live in at context_create time. It's a way
153to let all sockets serviced in the same context share data without
154using globals statics in the user code.
155</blockquote>
156<hr>
Andy Green6964bb52011-01-23 16:50:33 +0000157<h2>libwebsocket_service - Service any pending websocket activity</h2>
158<i>int</i>
159<b>libwebsocket_service</b>
Peter Hinz56885f32011-03-02 22:03:47 +0000160(<i>struct libwebsocket_context *</i> <b>context</b>,
Andy Green6964bb52011-01-23 16:50:33 +0000161<i>int</i> <b>timeout_ms</b>)
162<h3>Arguments</h3>
163<dl>
Peter Hinz56885f32011-03-02 22:03:47 +0000164<dt><b>context</b>
Andy Green6964bb52011-01-23 16:50:33 +0000165<dd>Websocket context
166<dt><b>timeout_ms</b>
167<dd>Timeout for poll; 0 means return immediately if nothing needed
168service otherwise block and service immediately, returning
169after the timeout if nothing needed service.
170</dl>
171<h3>Description</h3>
172<blockquote>
173This function deals with any pending websocket traffic, for three
174kinds of event. It handles these events on both server and client
175types of connection the same.
176<p>
1771) Accept new connections to our context's server
178<p>
Andy Green6f520a52013-01-29 17:57:39 +08001792) Call the receive callback for incoming frame data received by
Andy Green6964bb52011-01-23 16:50:33 +0000180server or client connections.
181<p>
182You need to call this service function periodically to all the above
183functions to happen; if your application is single-threaded you can
184just call it in your main event loop.
185<p>
186Alternatively you can fork a new process that asynchronously handles
187calling this service in a loop. In that case you are happy if this
188call blocks your thread until it needs to take care of something and
189would call it with a large nonzero timeout. Your loop then takes no
190CPU while there is nothing happening.
191<p>
192If you are calling it in a single-threaded app, you don't want it to
193wait around blocking other things in your loop from happening, so you
194would call it with a timeout_ms of 0, so it returns immediately if
195nothing is pending, or as soon as it services whatever was pending.
196</blockquote>
197<hr>
Andy Green32375b72011-02-19 08:32:53 +0000198<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 +0000199<i>int</i>
200<b>libwebsocket_callback_on_writable</b>
Peter Hinz56885f32011-03-02 22:03:47 +0000201(<i>struct libwebsocket_context *</i> <b>context</b>,
Andy Green62c54d22011-02-14 09:14:25 +0000202<i>struct libwebsocket *</i> <b>wsi</b>)
Andy Green90c7cbc2011-01-27 06:26:52 +0000203<h3>Arguments</h3>
204<dl>
Peter Hinz56885f32011-03-02 22:03:47 +0000205<dt><b>context</b>
Andy Green32375b72011-02-19 08:32:53 +0000206<dd>libwebsockets context
Andy Green90c7cbc2011-01-27 06:26:52 +0000207<dt><b>wsi</b>
208<dd>Websocket connection instance to get callback for
209</dl>
210<hr>
211<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>
212<i>int</i>
213<b>libwebsocket_callback_on_writable_all_protocol</b>
214(<i>const struct libwebsocket_protocols *</i> <b>protocol</b>)
215<h3>Arguments</h3>
216<dl>
217<dt><b>protocol</b>
218<dd>Protocol whose connections will get callbacks
219</dl>
220<hr>
Andy Greenbe93fef2011-02-14 20:25:43 +0000221<h2>libwebsocket_set_timeout - marks the wsi as subject to a timeout</h2>
222<i>void</i>
223<b>libwebsocket_set_timeout</b>
224(<i>struct libwebsocket *</i> <b>wsi</b>,
225<i>enum pending_timeout</i> <b>reason</b>,
226<i>int</i> <b>secs</b>)
227<h3>Arguments</h3>
228<dl>
229<dt><b>wsi</b>
230<dd>Websocket connection instance
231<dt><b>reason</b>
232<dd>timeout reason
233<dt><b>secs</b>
234<dd>how many seconds
235</dl>
236<h3>Description</h3>
237<blockquote>
238<p>
239You will not need this unless you are doing something special
240</blockquote>
241<hr>
Andy Greena6cbece2011-01-27 20:06:03 +0000242<h2>libwebsocket_get_socket_fd - returns the socket file descriptor</h2>
243<i>int</i>
244<b>libwebsocket_get_socket_fd</b>
245(<i>struct libwebsocket *</i> <b>wsi</b>)
246<h3>Arguments</h3>
247<dl>
248<dt><b>wsi</b>
249<dd>Websocket connection instance
250</dl>
251<h3>Description</h3>
252<blockquote>
253<p>
254You will not need this unless you are doing something special
255</blockquote>
256<hr>
Andy Green90c7cbc2011-01-27 06:26:52 +0000257<h2>libwebsocket_rx_flow_control - Enable and disable socket servicing for receieved packets.</h2>
258<i>int</i>
259<b>libwebsocket_rx_flow_control</b>
260(<i>struct libwebsocket *</i> <b>wsi</b>,
261<i>int</i> <b>enable</b>)
262<h3>Arguments</h3>
263<dl>
264<dt><b>wsi</b>
265<dd>Websocket connection instance to get callback for
266<dt><b>enable</b>
267<dd>0 = disable read servicing for this connection, 1 = enable
268</dl>
269<h3>Description</h3>
270<blockquote>
271<p>
272If the output side of a server process becomes choked, this allows flow
273control for the input side.
274</blockquote>
275<hr>
Andy Green2ac5a6f2011-01-28 10:00:18 +0000276<h2>libwebsocket_canonical_hostname - returns this host's hostname</h2>
277<i>const char *</i>
278<b>libwebsocket_canonical_hostname</b>
Peter Hinz56885f32011-03-02 22:03:47 +0000279(<i>struct libwebsocket_context *</i> <b>context</b>)
Andy Green2ac5a6f2011-01-28 10:00:18 +0000280<h3>Arguments</h3>
281<dl>
Peter Hinz56885f32011-03-02 22:03:47 +0000282<dt><b>context</b>
Andy Green2ac5a6f2011-01-28 10:00:18 +0000283<dd>Websocket context
284</dl>
285<h3>Description</h3>
286<blockquote>
287<p>
288This is typically used by client code to fill in the host parameter
289when making a client connection. You can only call it after the context
290has been created.
291</blockquote>
292<hr>
Andy Green4739e5c2011-01-22 12:51:57 +0000293<h2>libwebsocket_create_context - Create the websocket handler</h2>
Andy Greene92cd172011-01-19 13:11:55 +0000294<i>struct libwebsocket_context *</i>
Andy Green4739e5c2011-01-22 12:51:57 +0000295<b>libwebsocket_create_context</b>
Andy Green1b265272013-02-09 14:01:09 +0800296(<i>struct lws_context_creation_info *</i> <b>info</b>)
Andy Green62a12932010-11-03 11:19:23 +0000297<h3>Arguments</h3>
298<dl>
Andy Green1b265272013-02-09 14:01:09 +0800299<dt><b>info</b>
300<dd>pointer to struct with parameters
Andy Green62a12932010-11-03 11:19:23 +0000301</dl>
302<h3>Description</h3>
303<blockquote>
Andy Green1b265272013-02-09 14:01:09 +0800304This function creates the listening socket (if serving) and takes care
Andy Green62a12932010-11-03 11:19:23 +0000305of all initialization in one step.
306<p>
Andy Greene92cd172011-01-19 13:11:55 +0000307After initialization, it returns a struct libwebsocket_context * that
308represents this server. After calling, user code needs to take care
309of calling <b>libwebsocket_service</b> with the context pointer to get the
310server's sockets serviced. This can be done in the same process context
311or a forked process, or another thread,
Andy Green47943ae2010-11-12 11:15:49 +0000312<p>
313The protocol callback functions are called for a handful of events
314including http requests coming in, websocket connections becoming
Andy Green62a12932010-11-03 11:19:23 +0000315established, and data arriving; it's also called periodically to allow
316async transmission.
317<p>
Andy Green47943ae2010-11-12 11:15:49 +0000318HTTP requests are sent always to the FIRST protocol in <tt><b>protocol</b></tt>, since
319at that time websocket protocol has not been negotiated. Other
320protocols after the first one never see any HTTP callack activity.
321<p>
Andy Green62a12932010-11-03 11:19:23 +0000322The server created is a simple http server by default; part of the
323websocket standard is upgrading this http connection to a websocket one.
324<p>
325This allows the same server to provide files like scripts and favicon /
326images or whatever over http and dynamic data over websockets all in
327one place; they're all handled in the user callback.
328</blockquote>
329<hr>
Andy Greenb45993c2010-12-18 15:13:50 +0000330<h2>libwebsockets_get_protocol - Returns a protocol pointer from a websocket connection.</h2>
331<i>const struct libwebsocket_protocols *</i>
332<b>libwebsockets_get_protocol</b>
333(<i>struct libwebsocket *</i> <b>wsi</b>)
334<h3>Arguments</h3>
335<dl>
336<dt><b>wsi</b>
337<dd>pointer to struct websocket you want to know the protocol of
338</dl>
339<h3>Description</h3>
340<blockquote>
341<p>
Andy Green6f520a52013-01-29 17:57:39 +0800342Some apis can act on all live connections of a given protocol,
343this is how you can get a pointer to the active protocol if needed.
Andy Greenacbaee62013-01-18 22:00:22 +0800344</blockquote>
345<hr>
Andy Green43db0452013-01-10 19:50:35 +0800346<h2>lws_set_log_level - Set the logging bitfield</h2>
347<i>void</i>
348<b>lws_set_log_level</b>
Andy Greende8f27a2013-01-12 09:17:42 +0800349(<i>int</i> <b>level</b>,
Andy Greenb5b23192013-02-11 17:13:32 +0800350<i>void (*</i><b>log_emit_function</b>) <i>(int level, const char *line)</i>)
Andy Green43db0452013-01-10 19:50:35 +0800351<h3>Arguments</h3>
352<dl>
353<dt><b>level</b>
354<dd>OR together the LLL_ debug contexts you want output from
Andy Greende8f27a2013-01-12 09:17:42 +0800355<dt><b>log_emit_function</b>
356<dd>NULL to leave it as it is, or a user-supplied
357function to perform log string emission instead of
358the default stderr one.
Andy Green43db0452013-01-10 19:50:35 +0800359</dl>
360<h3>Description</h3>
361<blockquote>
Andy Greenc6511a02013-02-19 10:01:48 +0800362log level defaults to "err", "warn" and "notice" contexts enabled and
Andy Greende8f27a2013-01-12 09:17:42 +0800363emission on stderr.
Andy Green43db0452013-01-10 19:50:35 +0800364</blockquote>
365<hr>
Andy Greend88146d2013-01-22 12:40:35 +0800366<h2>libwebsocket_write - Apply protocol then write data to client</h2>
367<i>int</i>
368<b>libwebsocket_write</b>
369(<i>struct libwebsocket *</i> <b>wsi</b>,
370<i>unsigned char *</i> <b>buf</b>,
371<i>size_t</i> <b>len</b>,
372<i>enum libwebsocket_write_protocol</i> <b>protocol</b>)
373<h3>Arguments</h3>
374<dl>
375<dt><b>wsi</b>
376<dd>Websocket instance (available from user callback)
377<dt><b>buf</b>
378<dd>The data to send. For data being sent on a websocket
379connection (ie, not default http), this buffer MUST have
380LWS_SEND_BUFFER_PRE_PADDING bytes valid BEFORE the pointer
381and an additional LWS_SEND_BUFFER_POST_PADDING bytes valid
382in the buffer after (buf + len). This is so the protocol
383header and trailer data can be added in-situ.
384<dt><b>len</b>
385<dd>Count of the data bytes in the payload starting from buf
386<dt><b>protocol</b>
387<dd>Use LWS_WRITE_HTTP to reply to an http connection, and one
388of LWS_WRITE_BINARY or LWS_WRITE_TEXT to send appropriate
389data on a websockets connection. Remember to allow the extra
390bytes before and after buf if LWS_WRITE_BINARY or LWS_WRITE_TEXT
391are used.
392</dl>
393<h3>Description</h3>
394<blockquote>
395This function provides the way to issue data back to the client
396for both http and websocket protocols.
397<p>
398In the case of sending using websocket protocol, be sure to allocate
399valid storage before and after buf as explained above. This scheme
400allows maximum efficiency of sending data and protocol in a single
401packet while not burdening the user code with any protocol knowledge.
Andy Greenfc7c5e42013-02-23 10:50:10 +0800402<p>
403Return may be -1 for a fatal error needing connection close, or a
404positive number reflecting the amount of bytes actually sent. This
405can be less than the requested number of bytes due to OS memory
406pressure at any given time.
Andy Greend88146d2013-01-22 12:40:35 +0800407</blockquote>
408<hr>
409<h2>libwebsockets_serve_http_file - Send a file back to the client using http</h2>
410<i>int</i>
411<b>libwebsockets_serve_http_file</b>
412(<i>struct libwebsocket_context *</i> <b>context</b>,
413<i>struct libwebsocket *</i> <b>wsi</b>,
414<i>const char *</i> <b>file</b>,
415<i>const char *</i> <b>content_type</b>)
416<h3>Arguments</h3>
417<dl>
418<dt><b>context</b>
419<dd>libwebsockets context
420<dt><b>wsi</b>
421<dd>Websocket instance (available from user callback)
422<dt><b>file</b>
423<dd>The file to issue over http
424<dt><b>content_type</b>
425<dd>The http content type, eg, text/html
426</dl>
427<h3>Description</h3>
428<blockquote>
429This function is intended to be called from the callback in response
430to http requests from the client. It allows the callback to issue
431local files down the http link in a single step.
Andy Greenb8b247d2013-01-22 07:20:08 +0800432<p>
433Returning &lt;0 indicates error and the wsi should be closed. Returning
434&gt;0 indicates the file was completely sent and the wsi should be closed.
435==0 indicates the file transfer is started and needs more service later,
436the wsi should be left alone.
Andy Greend88146d2013-01-22 12:40:35 +0800437</blockquote>
438<hr>
Andy Green2577c832013-03-11 20:37:03 +0800439<h2>libwebsocket_client_connect - Connect to another websocket server</h2>
440<i>struct libwebsocket *</i>
441<b>libwebsocket_client_connect</b>
442(<i>struct libwebsocket_context *</i> <b>context</b>,
443<i>const char *</i> <b>address</b>,
444<i>int</i> <b>port</b>,
445<i>int</i> <b>ssl_connection</b>,
446<i>const char *</i> <b>path</b>,
447<i>const char *</i> <b>host</b>,
448<i>const char *</i> <b>origin</b>,
449<i>const char *</i> <b>protocol</b>,
450<i>int</i> <b>ietf_version_or_minus_one</b>)
Andy Green2fd3f2f2013-01-18 09:49:20 +0800451<h3>Arguments</h3>
452<dl>
Andy Green2577c832013-03-11 20:37:03 +0800453<dt><b>context</b>
454<dd>Websocket context
455<dt><b>address</b>
456<dd>Remote server address, eg, "myserver.com"
457<dt><b>port</b>
458<dd>Port to connect to on the remote server, eg, 80
459<dt><b>ssl_connection</b>
460<dd>0 = ws://, 1 = wss:// encrypted, 2 = wss:// allow self
461signed certs
462<dt><b>path</b>
463<dd>Websocket path on server
464<dt><b>host</b>
465<dd>Hostname on server
466<dt><b>origin</b>
467<dd>Socket origin name
468<dt><b>protocol</b>
469<dd>Comma-separated list of protocols being asked for from
470the server, or just one. The server will pick the one it
471likes best.
472<dt><b>ietf_version_or_minus_one</b>
473<dd>-1 to ask to connect using the default, latest
474protocol supported, or the specific protocol ordinal
Andy Green2fd3f2f2013-01-18 09:49:20 +0800475</dl>
476<h3>Description</h3>
477<blockquote>
Andy Green2577c832013-03-11 20:37:03 +0800478This function creates a connection to a remote server
Andy Green2fd3f2f2013-01-18 09:49:20 +0800479</blockquote>
480<hr>
Andy Green2577c832013-03-11 20:37:03 +0800481<h2>libwebsocket_client_connect_extended - Connect to another websocket server</h2>
482<i>struct libwebsocket *</i>
483<b>libwebsocket_client_connect_extended</b>
484(<i>struct libwebsocket_context *</i> <b>context</b>,
485<i>const char *</i> <b>address</b>,
486<i>int</i> <b>port</b>,
487<i>int</i> <b>ssl_connection</b>,
488<i>const char *</i> <b>path</b>,
489<i>const char *</i> <b>host</b>,
490<i>const char *</i> <b>origin</b>,
491<i>const char *</i> <b>protocol</b>,
492<i>int</i> <b>ietf_version_or_minus_one</b>,
493<i>void *</i> <b>userdata</b>)
Andy Green38e57bb2011-01-19 12:20:27 +0000494<h3>Arguments</h3>
495<dl>
Andy Green2577c832013-03-11 20:37:03 +0800496<dt><b>context</b>
497<dd>Websocket context
498<dt><b>address</b>
499<dd>Remote server address, eg, "myserver.com"
500<dt><b>port</b>
501<dd>Port to connect to on the remote server, eg, 80
502<dt><b>ssl_connection</b>
503<dd>0 = ws://, 1 = wss:// encrypted, 2 = wss:// allow self
504signed certs
505<dt><b>path</b>
506<dd>Websocket path on server
507<dt><b>host</b>
508<dd>Hostname on server
509<dt><b>origin</b>
510<dd>Socket origin name
511<dt><b>protocol</b>
512<dd>Comma-separated list of protocols being asked for from
513the server, or just one. The server will pick the one it
514likes best.
515<dt><b>ietf_version_or_minus_one</b>
516<dd>-1 to ask to connect using the default, latest
517protocol supported, or the specific protocol ordinal
518<dt><b>userdata</b>
519<dd>Pre-allocated user data
Andy Green38e57bb2011-01-19 12:20:27 +0000520</dl>
521<h3>Description</h3>
522<blockquote>
Andy Green2577c832013-03-11 20:37:03 +0800523This function creates a connection to a remote server
Andy Green38e57bb2011-01-19 12:20:27 +0000524</blockquote>
525<hr>
Andy Green8f037e42010-12-19 22:13:26 +0000526<h2>callback - User server actions</h2>
Andy Green07b56e62011-10-03 19:30:22 +0800527<i>LWS_EXTERN int</i>
Andy Green8f037e42010-12-19 22:13:26 +0000528<b>callback</b>
Darin Willitsc19456f2011-02-14 17:52:39 +0000529(<i>struct libwebsocket_context *</i> <b>context</b>,
Andy Green62c54d22011-02-14 09:14:25 +0000530<i>struct libwebsocket *</i> <b>wsi</b>,
Andy Green8f037e42010-12-19 22:13:26 +0000531<i>enum libwebsocket_callback_reasons</i> <b>reason</b>,
532<i>void *</i> <b>user</b>,
533<i>void *</i> <b>in</b>,
534<i>size_t</i> <b>len</b>)
535<h3>Arguments</h3>
536<dl>
Andy Green32375b72011-02-19 08:32:53 +0000537<dt><b>context</b>
538<dd>Websockets context
Andy Green8f037e42010-12-19 22:13:26 +0000539<dt><b>wsi</b>
540<dd>Opaque websocket instance pointer
541<dt><b>reason</b>
542<dd>The reason for the call
543<dt><b>user</b>
544<dd>Pointer to per-session user data allocated by library
545<dt><b>in</b>
546<dd>Pointer used for some callback reasons
547<dt><b>len</b>
548<dd>Length set for some callback reasons
549</dl>
550<h3>Description</h3>
551<blockquote>
552This callback is the way the user controls what is served. All the
553protocol detail is hidden and handled by the library.
554<p>
555For each connection / session there is user data allocated that is
556pointed to by "user". You set the size of this user data area when
557the library is initialized with libwebsocket_create_server.
558<p>
559You get an opportunity to initialize user data when called back with
560LWS_CALLBACK_ESTABLISHED reason.
561</blockquote>
562<h3>LWS_CALLBACK_ESTABLISHED</h3>
563<blockquote>
Andy Green90c7cbc2011-01-27 06:26:52 +0000564after the server completes a handshake with
565an incoming client
566</blockquote>
David Brooks2c60d952012-04-20 12:19:01 +0800567<h3>LWS_CALLBACK_CLIENT_CONNECTION_ERROR</h3>
568<blockquote>
569the request client connection has
570been unable to complete a handshake with the remote server
571</blockquote>
Andy Green2b57a342013-02-06 15:15:25 +0900572<h3>LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH</h3>
573<blockquote>
574this is the last chance for the
575client user code to examine the http headers
576and decide to reject the connection. If the
577content in the headers is interesting to the
578client (url, etc) it needs to copy it out at
579this point since it will be destroyed before
580the CLIENT_ESTABLISHED call
581</blockquote>
Andy Green90c7cbc2011-01-27 06:26:52 +0000582<h3>LWS_CALLBACK_CLIENT_ESTABLISHED</h3>
583<blockquote>
584after your client connection completed
585a handshake with the remote server
Andy Green8f037e42010-12-19 22:13:26 +0000586</blockquote>
587<h3>LWS_CALLBACK_CLOSED</h3>
588<blockquote>
589when the websocket session ends
590</blockquote>
Andy Green8f037e42010-12-19 22:13:26 +0000591<h3>LWS_CALLBACK_RECEIVE</h3>
592<blockquote>
Andy Green90c7cbc2011-01-27 06:26:52 +0000593data has appeared for this server endpoint from a
594remote client, it can be found at *in and is
595len bytes long
596</blockquote>
Andy Greena6cbece2011-01-27 20:06:03 +0000597<h3>LWS_CALLBACK_CLIENT_RECEIVE_PONG</h3>
598<blockquote>
599if you elected to see PONG packets,
600they appear with this callback reason. PONG
601packets only exist in 04+ protocol
602</blockquote>
Andy Green90c7cbc2011-01-27 06:26:52 +0000603<h3>LWS_CALLBACK_CLIENT_RECEIVE</h3>
604<blockquote>
605data has appeared from the server for the
606client connection, it can be found at *in and
607is len bytes long
Andy Green8f037e42010-12-19 22:13:26 +0000608</blockquote>
609<h3>LWS_CALLBACK_HTTP</h3>
610<blockquote>
611an http request has come from a client that is not
612asking to upgrade the connection to a websocket
613one. This is a chance to serve http content,
614for example, to send a script to the client
615which will then open the websockets connection.
Andy Green7619c472011-01-23 17:47:08 +0000616<tt><b>in</b></tt> points to the URI path requested and
Andy Green8f037e42010-12-19 22:13:26 +0000617<b>libwebsockets_serve_http_file</b> makes it very
618simple to send back a file to the client.
Andy Green24b588b2013-01-13 09:53:18 +0800619Normally after sending the file you are done
620with the http connection, since the rest of the
621activity will come by websockets from the script
622that was delivered by http, so you will want to
623return 1; to close and free up the connection.
624That's important because it uses a slot in the
625total number of client connections allowed set
626by MAX_CLIENTS.
Andy Green8f037e42010-12-19 22:13:26 +0000627</blockquote>
Andy Greene803c822013-02-14 23:18:10 +0800628<h3>LWS_CALLBACK_HTTP_WRITEABLE</h3>
629<blockquote>
630you can write more down the http protocol
631link now.
632</blockquote>
Andy Greend280b6e2013-01-15 13:40:23 +0800633<h3>LWS_CALLBACK_HTTP_FILE_COMPLETION</h3>
634<blockquote>
635a file requested to be send down
636http link has completed.
637</blockquote>
Andy Greene9739ed2011-03-07 21:40:59 +0000638<h3>LWS_CALLBACK_SERVER_WRITEABLE</h3>
Andy Green90c7cbc2011-01-27 06:26:52 +0000639<blockquote>
Andy Greene9739ed2011-03-07 21:40:59 +0000640If you call
Andy Green90c7cbc2011-01-27 06:26:52 +0000641<b>libwebsocket_callback_on_writable</b> on a connection, you will
Andy Greene9739ed2011-03-07 21:40:59 +0000642get one of these callbacks coming when the connection socket
643is able to accept another write packet without blocking.
644If it already was able to take another packet without blocking,
645you'll get this callback at the next call to the service loop
646function. Notice that CLIENTs get LWS_CALLBACK_CLIENT_WRITEABLE
647and servers get LWS_CALLBACK_SERVER_WRITEABLE.
Andy Green90c7cbc2011-01-27 06:26:52 +0000648</blockquote>
Andy Green07034092011-02-13 08:37:12 +0000649<h3>LWS_CALLBACK_FILTER_NETWORK_CONNECTION</h3>
650<blockquote>
651called when a client connects to
652the server at network level; the connection is accepted but then
653passed to this callback to decide whether to hang up immediately
Andy Green2672fb22013-02-22 09:54:35 +0800654or not, based on the client IP. <tt><b>in</b></tt> contains the connection
Andy Green07034092011-02-13 08:37:12 +0000655socket's descriptor. Return non-zero to terminate
656the connection before sending or receiving anything.
657Because this happens immediately after the network connection
658from the client, there's no websocket protocol selected yet so
659this callback is issued only to protocol 0.
660</blockquote>
Andy Greenc85619d2011-02-13 08:25:26 +0000661<h3>LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION</h3>
662<blockquote>
663called when the handshake has
664been received and parsed from the client, but the response is
665not sent yet. Return non-zero to disallow the connection.
Andy Green07034092011-02-13 08:37:12 +0000666<tt><b>user</b></tt> is a pointer to an array of struct lws_tokens, you can
667use the header enums lws_token_indexes from libwebsockets.h
668to check for and read the supported header presence and
669content before deciding to allow the handshake to proceed or
670to kill the connection.
Andy Green0894bda2011-02-19 09:09:11 +0000671</blockquote>
672<h3>LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS</h3>
673<blockquote>
Andy Green6901cb32011-02-21 08:06:47 +0000674if configured for
Andy Green0894bda2011-02-19 09:09:11 +0000675including OpenSSL support, this callback allows your user code
676to perform extra <b>SSL_CTX_load_verify_locations</b> or similar
677calls to direct OpenSSL where to find certificates the client
678can use to confirm the remote server identity. <tt><b>user</b></tt> is the
679OpenSSL SSL_CTX*
Andy Green6901cb32011-02-21 08:06:47 +0000680</blockquote>
681<h3>LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS</h3>
682<blockquote>
683if configured for
684including OpenSSL support, this callback allows your user code
685to load extra certifcates into the server which allow it to
686verify the validity of certificates returned by clients. <tt><b>user</b></tt>
687is the server's OpenSSL SSL_CTX*
688</blockquote>
689<h3>LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION</h3>
690<blockquote>
691if the
692libwebsockets context was created with the option
693LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT, then this
694callback is generated during OpenSSL verification of the cert
695sent from the client. It is sent to protocol[0] callback as
696no protocol has been negotiated on the connection yet.
697Notice that the libwebsockets context and wsi are both NULL
698during this callback. See
699</blockquote>
700<h3>http</h3>
701<blockquote>
702//www.openssl.org/docs/ssl/SSL_CTX_set_verify.html
703to understand more detail about the OpenSSL callback that
704generates this libwebsockets callback and the meanings of the
705arguments passed. In this callback, <tt><b>user</b></tt> is the x509_ctx,
706<tt><b>in</b></tt> is the ssl pointer and <tt><b>len</b></tt> is preverify_ok
707Notice that this callback maintains libwebsocket return
708conventions, return 0 to mean the cert is OK or 1 to fail it.
709This also means that if you don't handle this callback then
710the default callback action of returning 0 allows the client
711certificates.
Andy Green385e7ad2011-03-01 21:06:02 +0000712</blockquote>
713<h3>LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER</h3>
714<blockquote>
715this callback happens
716when a client handshake is being compiled. <tt><b>user</b></tt> is NULL,
717<tt><b>in</b></tt> is a char **, it's pointing to a char * which holds the
718next location in the header buffer where you can add
719headers, and <tt><b>len</b></tt> is the remaining space in the header buffer,
720which is typically some hundreds of bytes. So, to add a canned
721cookie, your handler code might look similar to:
722<p>
723char **p = (char **)in;
724<p>
725if (len &lt; 100)
726return 1;
727<p>
728*p += sprintf(*p, "Cookie: a=b\x0d\x0a");
729<p>
730return 0;
731<p>
732Notice if you add anything, you just have to take care about
733the CRLF on the line you added. Obviously this callback is
734optional, if you don't handle it everything is fine.
735<p>
736Notice the callback is coming to protocols[0] all the time,
737because there is no specific protocol handshook yet.
Andy Greenc5114822011-03-06 10:29:35 +0000738</blockquote>
739<h3>LWS_CALLBACK_CONFIRM_EXTENSION_OKAY</h3>
740<blockquote>
741When the server handshake code
742sees that it does support a requested extension, before
743accepting the extension by additing to the list sent back to
744the client it gives this callback just to check that it's okay
745to use that extension. It calls back to the requested protocol
746and with <tt><b>in</b></tt> being the extension name, <tt><b>len</b></tt> is 0 and <tt><b>user</b></tt> is
747valid. Note though at this time the ESTABLISHED callback hasn't
748happened yet so if you initialize <tt><b>user</b></tt> content there, <tt><b>user</b></tt>
749content during this callback might not be useful for anything.
750Notice this callback comes to protocols[0].
Andy Greenc6517fa2011-03-06 13:15:29 +0000751</blockquote>
752<h3>LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED</h3>
753<blockquote>
754When a client
755connection is being prepared to start a handshake to a server,
756each supported extension is checked with protocols[0] callback
757with this reason, giving the user code a chance to suppress the
758claim to support that extension by returning non-zero. If
759unhandled, by default 0 will be returned and the extension
760support included in the header to the server. Notice this
761callback comes to protocols[0].
Andy Greena7109e62013-02-11 12:05:54 +0800762</blockquote>
763<h3>LWS_CALLBACK_PROTOCOL_INIT</h3>
764<blockquote>
765One-time call per protocol so it can
766do initial setup / allocations etc
767</blockquote>
768<h3>LWS_CALLBACK_PROTOCOL_DESTROY</h3>
769<blockquote>
770One-time call per protocol indicating
771this protocol won't get used at all after this callback, the
772context is getting destroyed. Take the opportunity to
773deallocate everything that was allocated by the protocol.
Andy Greenc85619d2011-02-13 08:25:26 +0000774<p>
775The next four reasons are optional and only need taking care of if you
776will be integrating libwebsockets sockets into an external polling
777array.
778</blockquote>
779<h3>LWS_CALLBACK_ADD_POLL_FD</h3>
780<blockquote>
781libwebsocket deals with its <b>poll</b> loop
782internally, but in the case you are integrating with another
783server you will need to have libwebsocket sockets share a
784polling array with the other server. This and the other
785POLL_FD related callbacks let you put your specialized
786poll array interface code in the callback for protocol 0, the
787first protocol you support, usually the HTTP protocol in the
788serving case. This callback happens when a socket needs to be
789</blockquote>
790<h3>added to the polling loop</h3>
791<blockquote>
Andy Green50097dd2013-02-15 22:36:30 +0800792<tt><b>in</b></tt> contains the fd, and
Andy Greenc85619d2011-02-13 08:25:26 +0000793<tt><b>len</b></tt> is the events bitmap (like, POLLIN). If you are using the
794internal polling loop (the "service" callback), you can just
795ignore these callbacks.
796</blockquote>
797<h3>LWS_CALLBACK_DEL_POLL_FD</h3>
798<blockquote>
799This callback happens when a socket descriptor
Andy Green50097dd2013-02-15 22:36:30 +0800800needs to be removed from an external polling array. <tt><b>in</b></tt> is
Andy Greenc85619d2011-02-13 08:25:26 +0000801the socket desricptor. If you are using the internal polling
802loop, you can just ignore it.
803</blockquote>
804<h3>LWS_CALLBACK_SET_MODE_POLL_FD</h3>
805<blockquote>
806This callback happens when libwebsockets
Andy Green50097dd2013-02-15 22:36:30 +0800807wants to modify the events for the socket descriptor in <tt><b>in</b></tt>.
Andy Greenc85619d2011-02-13 08:25:26 +0000808The handler should OR <tt><b>len</b></tt> on to the events member of the pollfd
809struct for this socket descriptor. If you are using the
810internal polling loop, you can just ignore it.
811</blockquote>
812<h3>LWS_CALLBACK_CLEAR_MODE_POLL_FD</h3>
813<blockquote>
814This callback occurs when libwebsockets
Andy Green50097dd2013-02-15 22:36:30 +0800815wants to modify the events for the socket descriptor in <tt><b>in</b></tt>.
Andy Greenc85619d2011-02-13 08:25:26 +0000816The handler should AND ~<tt><b>len</b></tt> on to the events member of the
817pollfd struct for this socket descriptor. If you are using the
818internal polling loop, you can just ignore it.
819</blockquote>
Andy Green8f037e42010-12-19 22:13:26 +0000820<hr>
Andy Green57b4e9a2011-03-06 13:14:46 +0000821<h2>extension_callback - Hooks to allow extensions to operate</h2>
Andy Green07b56e62011-10-03 19:30:22 +0800822<i>LWS_EXTERN int</i>
Andy Green57b4e9a2011-03-06 13:14:46 +0000823<b>extension_callback</b>
824(<i>struct libwebsocket_context *</i> <b>context</b>,
Andy Green46c2ea02011-03-22 09:04:01 +0000825<i>struct libwebsocket_extension *</i> <b>ext</b>,
Andy Green57b4e9a2011-03-06 13:14:46 +0000826<i>struct libwebsocket *</i> <b>wsi</b>,
David Brooks2c60d952012-04-20 12:19:01 +0800827<i>enum libwebsocket_extension_callback_reasons</i> <b>reason</b>,
Andy Green57b4e9a2011-03-06 13:14:46 +0000828<i>void *</i> <b>user</b>,
829<i>void *</i> <b>in</b>,
830<i>size_t</i> <b>len</b>)
831<h3>Arguments</h3>
832<dl>
833<dt><b>context</b>
834<dd>Websockets context
Andy Green46c2ea02011-03-22 09:04:01 +0000835<dt><b>ext</b>
836<dd>This extension
Andy Green57b4e9a2011-03-06 13:14:46 +0000837<dt><b>wsi</b>
838<dd>Opaque websocket instance pointer
839<dt><b>reason</b>
840<dd>The reason for the call
841<dt><b>user</b>
842<dd>Pointer to per-session user data allocated by library
843<dt><b>in</b>
844<dd>Pointer used for some callback reasons
845<dt><b>len</b>
846<dd>Length set for some callback reasons
847</dl>
848<h3>Description</h3>
849<blockquote>
850Each extension that is active on a particular connection receives
851callbacks during the connection lifetime to allow the extension to
852operate on websocket data and manage itself.
853<p>
854Libwebsockets takes care of allocating and freeing "user" memory for
855each active extension on each connection. That is what is pointed to
856by the <tt><b>user</b></tt> parameter.
857</blockquote>
858<h3>LWS_EXT_CALLBACK_CONSTRUCT</h3>
859<blockquote>
860called when the server has decided to
861select this extension from the list provided by the client,
862just before the server will send back the handshake accepting
863the connection with this extension active. This gives the
864extension a chance to initialize its connection context found
865in <tt><b>user</b></tt>.
866</blockquote>
Andy Green2366b1c2011-03-06 13:15:31 +0000867<h3>LWS_EXT_CALLBACK_CLIENT_CONSTRUCT</h3>
868<blockquote>
869same as LWS_EXT_CALLBACK_CONSTRUCT
870but called when client is instantiating this extension. Some
871extensions will work the same on client and server side and then
872you can just merge handlers for both CONSTRUCTS.
873</blockquote>
Andy Green57b4e9a2011-03-06 13:14:46 +0000874<h3>LWS_EXT_CALLBACK_DESTROY</h3>
875<blockquote>
876called when the connection the extension was
877being used on is about to be closed and deallocated. It's the
878last chance for the extension to deallocate anything it has
879allocated in the user data (pointed to by <tt><b>user</b></tt>) before the
Andy Green2366b1c2011-03-06 13:15:31 +0000880user data is deleted. This same callback is used whether you
881are in client or server instantiation context.
Andy Green57b4e9a2011-03-06 13:14:46 +0000882</blockquote>
883<h3>LWS_EXT_CALLBACK_PACKET_RX_PREPARSE</h3>
884<blockquote>
885when this extension was active on
886a connection, and a packet of data arrived at the connection,
887it is passed to this callback to give the extension a chance to
888change the data, eg, decompress it. <tt><b>user</b></tt> is pointing to the
889extension's private connection context data, <tt><b>in</b></tt> is pointing
890to an lws_tokens struct, it consists of a char * pointer called
891token, and an int called token_len. At entry, these are
892set to point to the received buffer and set to the content
893length. If the extension will grow the content, it should use
894a new buffer allocated in its private user context data and
895set the pointed-to lws_tokens members to point to its buffer.
896</blockquote>
897<h3>LWS_EXT_CALLBACK_PACKET_TX_PRESEND</h3>
898<blockquote>
899this works the same way as
900LWS_EXT_CALLBACK_PACKET_RX_PREPARSE above, except it gives the
901extension a chance to change websocket data just before it will
902be sent out. Using the same lws_token pointer scheme in <tt><b>in</b></tt>,
903the extension can change the buffer and the length to be
904transmitted how it likes. Again if it wants to grow the
905buffer safely, it should copy the data into its own buffer and
906set the lws_tokens token pointer to it.
907</blockquote>
908<hr>
Andy Green4f3943a2010-11-12 10:44:16 +0000909<h2>struct libwebsocket_protocols - List of protocols and handlers server supports.</h2>
910<b>struct libwebsocket_protocols</b> {<br>
911&nbsp; &nbsp; <i>const char *</i> <b>name</b>;<br>
David Brooks2c60d952012-04-20 12:19:01 +0800912&nbsp; &nbsp; <i>callback_function *</i> <b>callback</b>;<br>
Andy Green4f3943a2010-11-12 10:44:16 +0000913&nbsp; &nbsp; <i>size_t</i> <b>per_session_data_size</b>;<br>
Andy Green54495112013-02-06 21:10:16 +0900914&nbsp; &nbsp; <i>size_t</i> <b>rx_buffer_size</b>;<br>
Andy Greenb45993c2010-12-18 15:13:50 +0000915&nbsp; &nbsp; <i>struct libwebsocket_context *</i> <b>owning_server</b>;<br>
Andy Greenb45993c2010-12-18 15:13:50 +0000916&nbsp; &nbsp; <i>int</i> <b>protocol_index</b>;<br>
Andy Green4f3943a2010-11-12 10:44:16 +0000917};<br>
918<h3>Members</h3>
919<dl>
920<dt><b>name</b>
921<dd>Protocol name that must match the one given in the client
922Javascript new WebSocket(url, 'protocol') name
923<dt><b>callback</b>
924<dd>The service callback used for this protocol. It allows the
925service action for an entire protocol to be encapsulated in
926the protocol-specific callback
927<dt><b>per_session_data_size</b>
928<dd>Each new connection using this protocol gets
929this much memory allocated on connection establishment and
930freed on connection takedown. A pointer to this per-connection
931allocation is passed into the callback in the 'user' parameter
Andy Green54495112013-02-06 21:10:16 +0900932<dt><b>rx_buffer_size</b>
933<dd>if you want atomic frames delivered to the callback, you
934should set this to the size of the biggest legal frame that
935you support. If the frame size is exceeded, there is no
936error, but the buffer will spill to the user callback when
937full, which you can detect by using
938<b>libwebsockets_remaining_packet_payload</b>. Notice that you
939just talk about frame size here, the LWS_SEND_BUFFER_PRE_PADDING
940and post-padding are automatically also allocated on top.
Andy Greenb45993c2010-12-18 15:13:50 +0000941<dt><b>owning_server</b>
942<dd>the server init call fills in this opaque pointer when
943registering this protocol with the server.
Andy Greenb45993c2010-12-18 15:13:50 +0000944<dt><b>protocol_index</b>
945<dd>which protocol we are starting from zero
Andy Green4f3943a2010-11-12 10:44:16 +0000946</dl>
947<h3>Description</h3>
948<blockquote>
949This structure represents one protocol supported by the server. An
950array of these structures is passed to <b>libwebsocket_create_server</b>
951allows as many protocols as you like to be handled by one server.
952</blockquote>
953<hr>
Andy Greend6e09112011-03-05 16:12:15 +0000954<h2>struct libwebsocket_extension - An extension we know how to cope with</h2>
955<b>struct libwebsocket_extension</b> {<br>
956&nbsp; &nbsp; <i>const char *</i> <b>name</b>;<br>
David Brooks2c60d952012-04-20 12:19:01 +0800957&nbsp; &nbsp; <i>extension_callback_function *</i> <b>callback</b>;<br>
Andy Greend6e09112011-03-05 16:12:15 +0000958&nbsp; &nbsp; <i>size_t</i> <b>per_session_data_size</b>;<br>
Andy Greenaa6fc442012-04-12 13:26:49 +0800959&nbsp; &nbsp; <i>void *</i> <b>per_context_private_data</b>;<br>
Andy Greend6e09112011-03-05 16:12:15 +0000960};<br>
961<h3>Members</h3>
962<dl>
963<dt><b>name</b>
964<dd>Formal extension name, eg, "deflate-stream"
965<dt><b>callback</b>
966<dd>Service callback
967<dt><b>per_session_data_size</b>
968<dd>Libwebsockets will auto-malloc this much
969memory for the use of the extension, a pointer
970to it comes in the <tt><b>user</b></tt> callback parameter
Andy Greenaa6fc442012-04-12 13:26:49 +0800971<dt><b>per_context_private_data</b>
Andy Green75020012013-02-07 23:43:56 +0800972<dd>Optional storage for this extension that
Andy Greenaa6fc442012-04-12 13:26:49 +0800973is per-context, so it can track stuff across
974all sessions, etc, if it wants
Andy Greend6e09112011-03-05 16:12:15 +0000975</dl>
976<hr>
Andy Green1b265272013-02-09 14:01:09 +0800977<h2>struct lws_context_creation_info - </h2>
978<b>struct lws_context_creation_info</b> {<br>
979&nbsp; &nbsp; <i>int</i> <b>port</b>;<br>
Andy Green7a506ba2013-02-12 10:13:02 +0800980&nbsp; &nbsp; <i>const char *</i> <b>iface</b>;<br>
Andy Green1b265272013-02-09 14:01:09 +0800981&nbsp; &nbsp; <i>struct libwebsocket_protocols *</i> <b>protocols</b>;<br>
982&nbsp; &nbsp; <i>struct libwebsocket_extension *</i> <b>extensions</b>;<br>
983&nbsp; &nbsp; <i>const char *</i> <b>ssl_cert_filepath</b>;<br>
984&nbsp; &nbsp; <i>const char *</i> <b>ssl_private_key_filepath</b>;<br>
985&nbsp; &nbsp; <i>const char *</i> <b>ssl_ca_filepath</b>;<br>
Andy Green2672fb22013-02-22 09:54:35 +0800986&nbsp; &nbsp; <i>const char *</i> <b>ssl_cipher_list</b>;<br>
Andy Green1b265272013-02-09 14:01:09 +0800987&nbsp; &nbsp; <i>int</i> <b>gid</b>;<br>
988&nbsp; &nbsp; <i>int</i> <b>uid</b>;<br>
989&nbsp; &nbsp; <i>unsigned int</i> <b>options</b>;<br>
990&nbsp; &nbsp; <i>void *</i> <b>user</b>;<br>
Andy Greena690cd02013-02-09 12:25:31 +0800991&nbsp; &nbsp; <i>int</i> <b>ka_time</b>;<br>
992&nbsp; &nbsp; <i>int</i> <b>ka_probes</b>;<br>
993&nbsp; &nbsp; <i>int</i> <b>ka_interval</b>;<br>
Andy Green1b265272013-02-09 14:01:09 +0800994};<br>
995<h3>Members</h3>
996<dl>
997<dt><b>port</b>
998<dd>Port to listen on... you can use 0 to suppress listening on
999any port, that's what you want if you are not running a
1000websocket server at all but just using it as a client
Andy Green7a506ba2013-02-12 10:13:02 +08001001<dt><b>iface</b>
1002<dd>NULL to bind the listen socket to all interfaces, or the
1003interface name, eg, "eth2"
Andy Green1b265272013-02-09 14:01:09 +08001004<dt><b>protocols</b>
1005<dd>Array of structures listing supported protocols and a protocol-
1006specific callback for each one. The list is ended with an
1007entry that has a NULL callback pointer.
1008It's not const because we write the owning_server member
1009<dt><b>extensions</b>
1010<dd>NULL or array of libwebsocket_extension structs listing the
1011extensions this context supports. If you configured with
1012--without-extensions, you should give NULL here.
1013<dt><b>ssl_cert_filepath</b>
1014<dd>If libwebsockets was compiled to use ssl, and you want
1015to listen using SSL, set to the filepath to fetch the
1016server cert from, otherwise NULL for unencrypted
1017<dt><b>ssl_private_key_filepath</b>
1018<dd>filepath to private key if wanting SSL mode,
1019else ignored
1020<dt><b>ssl_ca_filepath</b>
1021<dd>CA certificate filepath or NULL
Andy Green2672fb22013-02-22 09:54:35 +08001022<dt><b>ssl_cipher_list</b>
1023<dd>List of valid ciphers to use (eg,
1024"RC4-MD5:RC4-SHA:AES128-SHA:AES256-SHA:HIGH:!DSS:!aNULL"
1025or you can leave it as NULL to get "DEFAULT"
Andy Green1b265272013-02-09 14:01:09 +08001026<dt><b>gid</b>
1027<dd>group id to change to after setting listen socket, or -1.
1028<dt><b>uid</b>
1029<dd>user id to change to after setting listen socket, or -1.
1030<dt><b>options</b>
1031<dd>0, or LWS_SERVER_OPTION_DEFEAT_CLIENT_MASK
1032<dt><b>user</b>
1033<dd>optional user pointer that can be recovered via the context
1034pointer using libwebsocket_context_user
Andy Greena690cd02013-02-09 12:25:31 +08001035<dt><b>ka_time</b>
1036<dd>0 for no keepalive, otherwise apply this keepalive timeout to
1037all libwebsocket sockets, client or server
1038<dt><b>ka_probes</b>
1039<dd>if ka_time was nonzero, after the timeout expires how many
1040times to try to get a response from the peer before giving up
1041and killing the connection
1042<dt><b>ka_interval</b>
1043<dd>if ka_time was nonzero, how long to wait before each ka_probes
1044attempt
Andy Green1b265272013-02-09 14:01:09 +08001045</dl>
1046<hr>