blob: 5839ac993e636a2029e350843fc64f63733755a9 [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 Green7b405452013-02-01 10:50:15 +080088<h2>lws_get_library_version - </h2>
89<i>const char *</i>
90<b>lws_get_library_version</b>
91(<i></i> <b>void</b>)
92<h3>Arguments</h3>
93<dl>
94<dt><b>void</b>
95<dd>no arguments
96</dl>
97<h3>Description</h3>
98<blockquote>
99<p>
100returns a const char * to a string like "1.1 178d78c"
101representing the library version followed by the git head hash it
102was built from
103</blockquote>
104<hr>
Andy Greenf7ee5492011-02-13 09:04:21 +0000105<h2>libwebsockets_hangup_on_client - Server calls to terminate client connection</h2>
106<i>void</i>
107<b>libwebsockets_hangup_on_client</b>
Peter Hinz56885f32011-03-02 22:03:47 +0000108(<i>struct libwebsocket_context *</i> <b>context</b>,
Andy Greenf7ee5492011-02-13 09:04:21 +0000109<i>int</i> <b>fd</b>)
110<h3>Arguments</h3>
111<dl>
Peter Hinz56885f32011-03-02 22:03:47 +0000112<dt><b>context</b>
Andy Greenf7ee5492011-02-13 09:04:21 +0000113<dd>libwebsockets context
114<dt><b>fd</b>
115<dd>Connection socket descriptor
116</dl>
117<hr>
Andy Green07034092011-02-13 08:37:12 +0000118<h2>libwebsockets_get_peer_addresses - Get client address information</h2>
119<i>void</i>
120<b>libwebsockets_get_peer_addresses</b>
Andy Greenaaf0b9f2013-01-30 08:12:20 +0800121(<i>struct libwebsocket_context *</i> <b>context</b>,
122<i>struct libwebsocket *</i> <b>wsi</b>,
123<i>int</i> <b>fd</b>,
Andy Green07034092011-02-13 08:37:12 +0000124<i>char *</i> <b>name</b>,
125<i>int</i> <b>name_len</b>,
126<i>char *</i> <b>rip</b>,
127<i>int</i> <b>rip_len</b>)
128<h3>Arguments</h3>
129<dl>
Andy Greenaaf0b9f2013-01-30 08:12:20 +0800130<dt><b>context</b>
131<dd>Libwebsockets context
132<dt><b>wsi</b>
133<dd>Local struct libwebsocket associated with
Andy Green07034092011-02-13 08:37:12 +0000134<dt><b>fd</b>
135<dd>Connection socket descriptor
136<dt><b>name</b>
137<dd>Buffer to take client address name
138<dt><b>name_len</b>
139<dd>Length of client address name buffer
140<dt><b>rip</b>
141<dd>Buffer to take client address IP qotted quad
142<dt><b>rip_len</b>
143<dd>Length of client address IP buffer
144</dl>
145<h3>Description</h3>
146<blockquote>
147This function fills in <tt><b>name</b></tt> and <tt><b>rip</b></tt> with the name and IP of
148the client connected with socket descriptor <tt><b>fd</b></tt>. Names may be
149truncated if there is not enough room. If either cannot be
150determined, they will be returned as valid zero-length strings.
151</blockquote>
152<hr>
Andy Green9f990342011-02-12 11:57:45 +0000153<h2>libwebsocket_service_fd - Service polled socket with something waiting</h2>
154<i>int</i>
155<b>libwebsocket_service_fd</b>
Peter Hinz56885f32011-03-02 22:03:47 +0000156(<i>struct libwebsocket_context *</i> <b>context</b>,
Andy Green9f990342011-02-12 11:57:45 +0000157<i>struct pollfd *</i> <b>pollfd</b>)
158<h3>Arguments</h3>
159<dl>
Peter Hinz56885f32011-03-02 22:03:47 +0000160<dt><b>context</b>
Andy Green9f990342011-02-12 11:57:45 +0000161<dd>Websocket context
162<dt><b>pollfd</b>
163<dd>The pollfd entry describing the socket fd and which events
164happened.
165</dl>
166<h3>Description</h3>
167<blockquote>
Andy Green75006172013-01-22 12:32:11 +0800168This function takes a pollfd that has POLLIN or POLLOUT activity and
Andy Greenb5b23192013-02-11 17:13:32 +0800169services it according to the state of the associated
170struct libwebsocket.
Andy Green75006172013-01-22 12:32:11 +0800171<p>
172The one call deals with all "service" that might happen on a socket
173including listen accepts, http files as well as websocket protocol.
Andy Green9f990342011-02-12 11:57:45 +0000174</blockquote>
175<hr>
Andy Green6964bb52011-01-23 16:50:33 +0000176<h2>libwebsocket_context_destroy - Destroy the websocket context</h2>
177<i>void</i>
178<b>libwebsocket_context_destroy</b>
Peter Hinz56885f32011-03-02 22:03:47 +0000179(<i>struct libwebsocket_context *</i> <b>context</b>)
Andy Green6964bb52011-01-23 16:50:33 +0000180<h3>Arguments</h3>
181<dl>
Peter Hinz56885f32011-03-02 22:03:47 +0000182<dt><b>context</b>
Andy Green6964bb52011-01-23 16:50:33 +0000183<dd>Websocket context
184</dl>
185<h3>Description</h3>
186<blockquote>
187This function closes any active connections and then frees the
188context. After calling this, any further use of the context is
189undefined.
190</blockquote>
191<hr>
Andy Greenb5b23192013-02-11 17:13:32 +0800192<h2>libwebsocket_context_user - get the user data associated with the context</h2>
Andy Greend88146d2013-01-22 12:40:35 +0800193<i>LWS_EXTERN void *</i>
194<b>libwebsocket_context_user</b>
195(<i>struct libwebsocket_context *</i> <b>context</b>)
196<h3>Arguments</h3>
197<dl>
198<dt><b>context</b>
199<dd>Websocket context
200</dl>
201<h3>Description</h3>
202<blockquote>
203This returns the optional user allocation that can be attached to
204the context the sockets live in at context_create time. It's a way
205to let all sockets serviced in the same context share data without
206using globals statics in the user code.
207</blockquote>
208<hr>
Andy Green6964bb52011-01-23 16:50:33 +0000209<h2>libwebsocket_service - Service any pending websocket activity</h2>
210<i>int</i>
211<b>libwebsocket_service</b>
Peter Hinz56885f32011-03-02 22:03:47 +0000212(<i>struct libwebsocket_context *</i> <b>context</b>,
Andy Green6964bb52011-01-23 16:50:33 +0000213<i>int</i> <b>timeout_ms</b>)
214<h3>Arguments</h3>
215<dl>
Peter Hinz56885f32011-03-02 22:03:47 +0000216<dt><b>context</b>
Andy Green6964bb52011-01-23 16:50:33 +0000217<dd>Websocket context
218<dt><b>timeout_ms</b>
219<dd>Timeout for poll; 0 means return immediately if nothing needed
220service otherwise block and service immediately, returning
221after the timeout if nothing needed service.
222</dl>
223<h3>Description</h3>
224<blockquote>
225This function deals with any pending websocket traffic, for three
226kinds of event. It handles these events on both server and client
227types of connection the same.
228<p>
2291) Accept new connections to our context's server
230<p>
Andy Green6f520a52013-01-29 17:57:39 +08002312) Call the receive callback for incoming frame data received by
Andy Green6964bb52011-01-23 16:50:33 +0000232server or client connections.
233<p>
234You need to call this service function periodically to all the above
235functions to happen; if your application is single-threaded you can
236just call it in your main event loop.
237<p>
238Alternatively you can fork a new process that asynchronously handles
239calling this service in a loop. In that case you are happy if this
240call blocks your thread until it needs to take care of something and
241would call it with a large nonzero timeout. Your loop then takes no
242CPU while there is nothing happening.
243<p>
244If you are calling it in a single-threaded app, you don't want it to
245wait around blocking other things in your loop from happening, so you
246would call it with a timeout_ms of 0, so it returns immediately if
247nothing is pending, or as soon as it services whatever was pending.
248</blockquote>
249<hr>
Andy Green32375b72011-02-19 08:32:53 +0000250<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 +0000251<i>int</i>
252<b>libwebsocket_callback_on_writable</b>
Peter Hinz56885f32011-03-02 22:03:47 +0000253(<i>struct libwebsocket_context *</i> <b>context</b>,
Andy Green62c54d22011-02-14 09:14:25 +0000254<i>struct libwebsocket *</i> <b>wsi</b>)
Andy Green90c7cbc2011-01-27 06:26:52 +0000255<h3>Arguments</h3>
256<dl>
Peter Hinz56885f32011-03-02 22:03:47 +0000257<dt><b>context</b>
Andy Green32375b72011-02-19 08:32:53 +0000258<dd>libwebsockets context
Andy Green90c7cbc2011-01-27 06:26:52 +0000259<dt><b>wsi</b>
260<dd>Websocket connection instance to get callback for
261</dl>
262<hr>
263<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>
264<i>int</i>
265<b>libwebsocket_callback_on_writable_all_protocol</b>
266(<i>const struct libwebsocket_protocols *</i> <b>protocol</b>)
267<h3>Arguments</h3>
268<dl>
269<dt><b>protocol</b>
270<dd>Protocol whose connections will get callbacks
271</dl>
272<hr>
Andy Greenbe93fef2011-02-14 20:25:43 +0000273<h2>libwebsocket_set_timeout - marks the wsi as subject to a timeout</h2>
274<i>void</i>
275<b>libwebsocket_set_timeout</b>
276(<i>struct libwebsocket *</i> <b>wsi</b>,
277<i>enum pending_timeout</i> <b>reason</b>,
278<i>int</i> <b>secs</b>)
279<h3>Arguments</h3>
280<dl>
281<dt><b>wsi</b>
282<dd>Websocket connection instance
283<dt><b>reason</b>
284<dd>timeout reason
285<dt><b>secs</b>
286<dd>how many seconds
287</dl>
288<h3>Description</h3>
289<blockquote>
290<p>
291You will not need this unless you are doing something special
292</blockquote>
293<hr>
Andy Greena6cbece2011-01-27 20:06:03 +0000294<h2>libwebsocket_get_socket_fd - returns the socket file descriptor</h2>
295<i>int</i>
296<b>libwebsocket_get_socket_fd</b>
297(<i>struct libwebsocket *</i> <b>wsi</b>)
298<h3>Arguments</h3>
299<dl>
300<dt><b>wsi</b>
301<dd>Websocket connection instance
302</dl>
303<h3>Description</h3>
304<blockquote>
305<p>
306You will not need this unless you are doing something special
307</blockquote>
308<hr>
Andy Green90c7cbc2011-01-27 06:26:52 +0000309<h2>libwebsocket_rx_flow_control - Enable and disable socket servicing for receieved packets.</h2>
310<i>int</i>
311<b>libwebsocket_rx_flow_control</b>
312(<i>struct libwebsocket *</i> <b>wsi</b>,
313<i>int</i> <b>enable</b>)
314<h3>Arguments</h3>
315<dl>
316<dt><b>wsi</b>
317<dd>Websocket connection instance to get callback for
318<dt><b>enable</b>
319<dd>0 = disable read servicing for this connection, 1 = enable
320</dl>
321<h3>Description</h3>
322<blockquote>
323<p>
324If the output side of a server process becomes choked, this allows flow
325control for the input side.
326</blockquote>
327<hr>
Andy Green2ac5a6f2011-01-28 10:00:18 +0000328<h2>libwebsocket_canonical_hostname - returns this host's hostname</h2>
329<i>const char *</i>
330<b>libwebsocket_canonical_hostname</b>
Peter Hinz56885f32011-03-02 22:03:47 +0000331(<i>struct libwebsocket_context *</i> <b>context</b>)
Andy Green2ac5a6f2011-01-28 10:00:18 +0000332<h3>Arguments</h3>
333<dl>
Peter Hinz56885f32011-03-02 22:03:47 +0000334<dt><b>context</b>
Andy Green2ac5a6f2011-01-28 10:00:18 +0000335<dd>Websocket context
336</dl>
337<h3>Description</h3>
338<blockquote>
339<p>
340This is typically used by client code to fill in the host parameter
341when making a client connection. You can only call it after the context
342has been created.
343</blockquote>
344<hr>
Andy Green4739e5c2011-01-22 12:51:57 +0000345<h2>libwebsocket_create_context - Create the websocket handler</h2>
Andy Greene92cd172011-01-19 13:11:55 +0000346<i>struct libwebsocket_context *</i>
Andy Green4739e5c2011-01-22 12:51:57 +0000347<b>libwebsocket_create_context</b>
Andy Green1b265272013-02-09 14:01:09 +0800348(<i>struct lws_context_creation_info *</i> <b>info</b>)
Andy Green62a12932010-11-03 11:19:23 +0000349<h3>Arguments</h3>
350<dl>
Andy Green1b265272013-02-09 14:01:09 +0800351<dt><b>info</b>
352<dd>pointer to struct with parameters
Andy Green62a12932010-11-03 11:19:23 +0000353</dl>
354<h3>Description</h3>
355<blockquote>
Andy Green1b265272013-02-09 14:01:09 +0800356This function creates the listening socket (if serving) and takes care
Andy Green62a12932010-11-03 11:19:23 +0000357of all initialization in one step.
358<p>
Andy Greene92cd172011-01-19 13:11:55 +0000359After initialization, it returns a struct libwebsocket_context * that
360represents this server. After calling, user code needs to take care
361of calling <b>libwebsocket_service</b> with the context pointer to get the
362server's sockets serviced. This can be done in the same process context
363or a forked process, or another thread,
Andy Green47943ae2010-11-12 11:15:49 +0000364<p>
365The protocol callback functions are called for a handful of events
366including http requests coming in, websocket connections becoming
Andy Green62a12932010-11-03 11:19:23 +0000367established, and data arriving; it's also called periodically to allow
368async transmission.
369<p>
Andy Green47943ae2010-11-12 11:15:49 +0000370HTTP requests are sent always to the FIRST protocol in <tt><b>protocol</b></tt>, since
371at that time websocket protocol has not been negotiated. Other
372protocols after the first one never see any HTTP callack activity.
373<p>
Andy Green62a12932010-11-03 11:19:23 +0000374The server created is a simple http server by default; part of the
375websocket standard is upgrading this http connection to a websocket one.
376<p>
377This allows the same server to provide files like scripts and favicon /
378images or whatever over http and dynamic data over websockets all in
379one place; they're all handled in the user callback.
380</blockquote>
381<hr>
Andy Greenb45993c2010-12-18 15:13:50 +0000382<h2>libwebsockets_get_protocol - Returns a protocol pointer from a websocket connection.</h2>
383<i>const struct libwebsocket_protocols *</i>
384<b>libwebsockets_get_protocol</b>
385(<i>struct libwebsocket *</i> <b>wsi</b>)
386<h3>Arguments</h3>
387<dl>
388<dt><b>wsi</b>
389<dd>pointer to struct websocket you want to know the protocol of
390</dl>
391<h3>Description</h3>
392<blockquote>
393<p>
Andy Green6f520a52013-01-29 17:57:39 +0800394Some apis can act on all live connections of a given protocol,
395this is how you can get a pointer to the active protocol if needed.
Andy Greenacbaee62013-01-18 22:00:22 +0800396</blockquote>
397<hr>
Andy Green43db0452013-01-10 19:50:35 +0800398<h2>lws_set_log_level - Set the logging bitfield</h2>
399<i>void</i>
400<b>lws_set_log_level</b>
Andy Greende8f27a2013-01-12 09:17:42 +0800401(<i>int</i> <b>level</b>,
Andy Greenb5b23192013-02-11 17:13:32 +0800402<i>void (*</i><b>log_emit_function</b>) <i>(int level, const char *line)</i>)
Andy Green43db0452013-01-10 19:50:35 +0800403<h3>Arguments</h3>
404<dl>
405<dt><b>level</b>
406<dd>OR together the LLL_ debug contexts you want output from
Andy Greende8f27a2013-01-12 09:17:42 +0800407<dt><b>log_emit_function</b>
408<dd>NULL to leave it as it is, or a user-supplied
409function to perform log string emission instead of
410the default stderr one.
Andy Green43db0452013-01-10 19:50:35 +0800411</dl>
412<h3>Description</h3>
413<blockquote>
Andy Greende8f27a2013-01-12 09:17:42 +0800414log level defaults to "err" and "warn" contexts enabled only and
415emission on stderr.
Andy Green43db0452013-01-10 19:50:35 +0800416</blockquote>
417<hr>
Andy Greend88146d2013-01-22 12:40:35 +0800418<h2>libwebsocket_write - Apply protocol then write data to client</h2>
419<i>int</i>
420<b>libwebsocket_write</b>
421(<i>struct libwebsocket *</i> <b>wsi</b>,
422<i>unsigned char *</i> <b>buf</b>,
423<i>size_t</i> <b>len</b>,
424<i>enum libwebsocket_write_protocol</i> <b>protocol</b>)
425<h3>Arguments</h3>
426<dl>
427<dt><b>wsi</b>
428<dd>Websocket instance (available from user callback)
429<dt><b>buf</b>
430<dd>The data to send. For data being sent on a websocket
431connection (ie, not default http), this buffer MUST have
432LWS_SEND_BUFFER_PRE_PADDING bytes valid BEFORE the pointer
433and an additional LWS_SEND_BUFFER_POST_PADDING bytes valid
434in the buffer after (buf + len). This is so the protocol
435header and trailer data can be added in-situ.
436<dt><b>len</b>
437<dd>Count of the data bytes in the payload starting from buf
438<dt><b>protocol</b>
439<dd>Use LWS_WRITE_HTTP to reply to an http connection, and one
440of LWS_WRITE_BINARY or LWS_WRITE_TEXT to send appropriate
441data on a websockets connection. Remember to allow the extra
442bytes before and after buf if LWS_WRITE_BINARY or LWS_WRITE_TEXT
443are used.
444</dl>
445<h3>Description</h3>
446<blockquote>
447This function provides the way to issue data back to the client
448for both http and websocket protocols.
449<p>
450In the case of sending using websocket protocol, be sure to allocate
451valid storage before and after buf as explained above. This scheme
452allows maximum efficiency of sending data and protocol in a single
453packet while not burdening the user code with any protocol knowledge.
454</blockquote>
455<hr>
456<h2>libwebsockets_serve_http_file - Send a file back to the client using http</h2>
457<i>int</i>
458<b>libwebsockets_serve_http_file</b>
459(<i>struct libwebsocket_context *</i> <b>context</b>,
460<i>struct libwebsocket *</i> <b>wsi</b>,
461<i>const char *</i> <b>file</b>,
462<i>const char *</i> <b>content_type</b>)
463<h3>Arguments</h3>
464<dl>
465<dt><b>context</b>
466<dd>libwebsockets context
467<dt><b>wsi</b>
468<dd>Websocket instance (available from user callback)
469<dt><b>file</b>
470<dd>The file to issue over http
471<dt><b>content_type</b>
472<dd>The http content type, eg, text/html
473</dl>
474<h3>Description</h3>
475<blockquote>
476This function is intended to be called from the callback in response
477to http requests from the client. It allows the callback to issue
478local files down the http link in a single step.
Andy Greenb8b247d2013-01-22 07:20:08 +0800479<p>
480Returning &lt;0 indicates error and the wsi should be closed. Returning
481&gt;0 indicates the file was completely sent and the wsi should be closed.
482==0 indicates the file transfer is started and needs more service later,
483the wsi should be left alone.
Andy Greend88146d2013-01-22 12:40:35 +0800484</blockquote>
485<hr>
Andy Green2fd3f2f2013-01-18 09:49:20 +0800486<h2>lws_frame_is_binary - </h2>
487<i>int</i>
488<b>lws_frame_is_binary</b>
489(<i>struct libwebsocket *</i> <b>wsi</b>)
490<h3>Arguments</h3>
491<dl>
492<dt><b>wsi</b>
493<dd>the connection we are inquiring about
494</dl>
495<h3>Description</h3>
496<blockquote>
497This is intended to be called from the LWS_CALLBACK_RECEIVE callback if
498it's interested to see if the frame it's dealing with was sent in binary
499mode.
500</blockquote>
501<hr>
Andy Green38e57bb2011-01-19 12:20:27 +0000502<h2>libwebsockets_remaining_packet_payload - Bytes to come before "overall" rx packet is complete</h2>
503<i>size_t</i>
504<b>libwebsockets_remaining_packet_payload</b>
505(<i>struct libwebsocket *</i> <b>wsi</b>)
506<h3>Arguments</h3>
507<dl>
508<dt><b>wsi</b>
509<dd>Websocket instance (available from user callback)
510</dl>
511<h3>Description</h3>
512<blockquote>
513This function is intended to be called from the callback if the
514user code is interested in "complete packets" from the client.
515libwebsockets just passes through payload as it comes and issues a buffer
516additionally when it hits a built-in limit. The LWS_CALLBACK_RECEIVE
517callback handler can use this API to find out if the buffer it has just
518been given is the last piece of a "complete packet" from the client --
519when that is the case <b>libwebsockets_remaining_packet_payload</b> will return
5200.
521<p>
522Many protocols won't care becuse their packets are always small.
523</blockquote>
524<hr>
Andy Green8f037e42010-12-19 22:13:26 +0000525<h2>callback - User server actions</h2>
Andy Green07b56e62011-10-03 19:30:22 +0800526<i>LWS_EXTERN int</i>
Andy Green8f037e42010-12-19 22:13:26 +0000527<b>callback</b>
Darin Willitsc19456f2011-02-14 17:52:39 +0000528(<i>struct libwebsocket_context *</i> <b>context</b>,
Andy Green62c54d22011-02-14 09:14:25 +0000529<i>struct libwebsocket *</i> <b>wsi</b>,
Andy Green8f037e42010-12-19 22:13:26 +0000530<i>enum libwebsocket_callback_reasons</i> <b>reason</b>,
531<i>void *</i> <b>user</b>,
532<i>void *</i> <b>in</b>,
533<i>size_t</i> <b>len</b>)
534<h3>Arguments</h3>
535<dl>
Andy Green32375b72011-02-19 08:32:53 +0000536<dt><b>context</b>
537<dd>Websockets context
Andy Green8f037e42010-12-19 22:13:26 +0000538<dt><b>wsi</b>
539<dd>Opaque websocket instance pointer
540<dt><b>reason</b>
541<dd>The reason for the call
542<dt><b>user</b>
543<dd>Pointer to per-session user data allocated by library
544<dt><b>in</b>
545<dd>Pointer used for some callback reasons
546<dt><b>len</b>
547<dd>Length set for some callback reasons
548</dl>
549<h3>Description</h3>
550<blockquote>
551This callback is the way the user controls what is served. All the
552protocol detail is hidden and handled by the library.
553<p>
554For each connection / session there is user data allocated that is
555pointed to by "user". You set the size of this user data area when
556the library is initialized with libwebsocket_create_server.
557<p>
558You get an opportunity to initialize user data when called back with
559LWS_CALLBACK_ESTABLISHED reason.
560</blockquote>
561<h3>LWS_CALLBACK_ESTABLISHED</h3>
562<blockquote>
Andy Green90c7cbc2011-01-27 06:26:52 +0000563after the server completes a handshake with
564an incoming client
565</blockquote>
David Brooks2c60d952012-04-20 12:19:01 +0800566<h3>LWS_CALLBACK_CLIENT_CONNECTION_ERROR</h3>
567<blockquote>
568the request client connection has
569been unable to complete a handshake with the remote server
570</blockquote>
Andy Green2b57a342013-02-06 15:15:25 +0900571<h3>LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH</h3>
572<blockquote>
573this is the last chance for the
574client user code to examine the http headers
575and decide to reject the connection. If the
576content in the headers is interesting to the
577client (url, etc) it needs to copy it out at
578this point since it will be destroyed before
579the CLIENT_ESTABLISHED call
580</blockquote>
Andy Green90c7cbc2011-01-27 06:26:52 +0000581<h3>LWS_CALLBACK_CLIENT_ESTABLISHED</h3>
582<blockquote>
583after your client connection completed
584a handshake with the remote server
Andy Green8f037e42010-12-19 22:13:26 +0000585</blockquote>
586<h3>LWS_CALLBACK_CLOSED</h3>
587<blockquote>
588when the websocket session ends
589</blockquote>
Andy Green8f037e42010-12-19 22:13:26 +0000590<h3>LWS_CALLBACK_RECEIVE</h3>
591<blockquote>
Andy Green90c7cbc2011-01-27 06:26:52 +0000592data has appeared for this server endpoint from a
593remote client, it can be found at *in and is
594len bytes long
595</blockquote>
Andy Greena6cbece2011-01-27 20:06:03 +0000596<h3>LWS_CALLBACK_CLIENT_RECEIVE_PONG</h3>
597<blockquote>
598if you elected to see PONG packets,
599they appear with this callback reason. PONG
600packets only exist in 04+ protocol
601</blockquote>
Andy Green90c7cbc2011-01-27 06:26:52 +0000602<h3>LWS_CALLBACK_CLIENT_RECEIVE</h3>
603<blockquote>
604data has appeared from the server for the
605client connection, it can be found at *in and
606is len bytes long
Andy Green8f037e42010-12-19 22:13:26 +0000607</blockquote>
608<h3>LWS_CALLBACK_HTTP</h3>
609<blockquote>
610an http request has come from a client that is not
611asking to upgrade the connection to a websocket
612one. This is a chance to serve http content,
613for example, to send a script to the client
614which will then open the websockets connection.
Andy Green7619c472011-01-23 17:47:08 +0000615<tt><b>in</b></tt> points to the URI path requested and
Andy Green8f037e42010-12-19 22:13:26 +0000616<b>libwebsockets_serve_http_file</b> makes it very
617simple to send back a file to the client.
Andy Green24b588b2013-01-13 09:53:18 +0800618Normally after sending the file you are done
619with the http connection, since the rest of the
620activity will come by websockets from the script
621that was delivered by http, so you will want to
622return 1; to close and free up the connection.
623That's important because it uses a slot in the
624total number of client connections allowed set
625by MAX_CLIENTS.
Andy Green8f037e42010-12-19 22:13:26 +0000626</blockquote>
Andy Greend280b6e2013-01-15 13:40:23 +0800627<h3>LWS_CALLBACK_HTTP_FILE_COMPLETION</h3>
628<blockquote>
629a file requested to be send down
630http link has completed.
631</blockquote>
Andy Greene9739ed2011-03-07 21:40:59 +0000632<h3>LWS_CALLBACK_SERVER_WRITEABLE</h3>
Andy Green90c7cbc2011-01-27 06:26:52 +0000633<blockquote>
Andy Greene9739ed2011-03-07 21:40:59 +0000634If you call
Andy Green90c7cbc2011-01-27 06:26:52 +0000635<b>libwebsocket_callback_on_writable</b> on a connection, you will
Andy Greene9739ed2011-03-07 21:40:59 +0000636get one of these callbacks coming when the connection socket
637is able to accept another write packet without blocking.
638If it already was able to take another packet without blocking,
639you'll get this callback at the next call to the service loop
640function. Notice that CLIENTs get LWS_CALLBACK_CLIENT_WRITEABLE
641and servers get LWS_CALLBACK_SERVER_WRITEABLE.
Andy Green90c7cbc2011-01-27 06:26:52 +0000642</blockquote>
Andy Green07034092011-02-13 08:37:12 +0000643<h3>LWS_CALLBACK_FILTER_NETWORK_CONNECTION</h3>
644<blockquote>
645called when a client connects to
646the server at network level; the connection is accepted but then
647passed to this callback to decide whether to hang up immediately
648or not, based on the client IP. <tt><b>user</b></tt> contains the connection
649socket's descriptor. Return non-zero to terminate
650the connection before sending or receiving anything.
651Because this happens immediately after the network connection
652from the client, there's no websocket protocol selected yet so
653this callback is issued only to protocol 0.
654</blockquote>
Andy Greenc85619d2011-02-13 08:25:26 +0000655<h3>LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION</h3>
656<blockquote>
657called when the handshake has
658been received and parsed from the client, but the response is
659not sent yet. Return non-zero to disallow the connection.
Andy Green07034092011-02-13 08:37:12 +0000660<tt><b>user</b></tt> is a pointer to an array of struct lws_tokens, you can
661use the header enums lws_token_indexes from libwebsockets.h
662to check for and read the supported header presence and
663content before deciding to allow the handshake to proceed or
664to kill the connection.
Andy Green0894bda2011-02-19 09:09:11 +0000665</blockquote>
666<h3>LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS</h3>
667<blockquote>
Andy Green6901cb32011-02-21 08:06:47 +0000668if configured for
Andy Green0894bda2011-02-19 09:09:11 +0000669including OpenSSL support, this callback allows your user code
670to perform extra <b>SSL_CTX_load_verify_locations</b> or similar
671calls to direct OpenSSL where to find certificates the client
672can use to confirm the remote server identity. <tt><b>user</b></tt> is the
673OpenSSL SSL_CTX*
Andy Green6901cb32011-02-21 08:06:47 +0000674</blockquote>
675<h3>LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS</h3>
676<blockquote>
677if configured for
678including OpenSSL support, this callback allows your user code
679to load extra certifcates into the server which allow it to
680verify the validity of certificates returned by clients. <tt><b>user</b></tt>
681is the server's OpenSSL SSL_CTX*
682</blockquote>
683<h3>LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION</h3>
684<blockquote>
685if the
686libwebsockets context was created with the option
687LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT, then this
688callback is generated during OpenSSL verification of the cert
689sent from the client. It is sent to protocol[0] callback as
690no protocol has been negotiated on the connection yet.
691Notice that the libwebsockets context and wsi are both NULL
692during this callback. See
693</blockquote>
694<h3>http</h3>
695<blockquote>
696//www.openssl.org/docs/ssl/SSL_CTX_set_verify.html
697to understand more detail about the OpenSSL callback that
698generates this libwebsockets callback and the meanings of the
699arguments passed. In this callback, <tt><b>user</b></tt> is the x509_ctx,
700<tt><b>in</b></tt> is the ssl pointer and <tt><b>len</b></tt> is preverify_ok
701Notice that this callback maintains libwebsocket return
702conventions, return 0 to mean the cert is OK or 1 to fail it.
703This also means that if you don't handle this callback then
704the default callback action of returning 0 allows the client
705certificates.
Andy Green385e7ad2011-03-01 21:06:02 +0000706</blockquote>
707<h3>LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER</h3>
708<blockquote>
709this callback happens
710when a client handshake is being compiled. <tt><b>user</b></tt> is NULL,
711<tt><b>in</b></tt> is a char **, it's pointing to a char * which holds the
712next location in the header buffer where you can add
713headers, and <tt><b>len</b></tt> is the remaining space in the header buffer,
714which is typically some hundreds of bytes. So, to add a canned
715cookie, your handler code might look similar to:
716<p>
717char **p = (char **)in;
718<p>
719if (len &lt; 100)
720return 1;
721<p>
722*p += sprintf(*p, "Cookie: a=b\x0d\x0a");
723<p>
724return 0;
725<p>
726Notice if you add anything, you just have to take care about
727the CRLF on the line you added. Obviously this callback is
728optional, if you don't handle it everything is fine.
729<p>
730Notice the callback is coming to protocols[0] all the time,
731because there is no specific protocol handshook yet.
Andy Greenc5114822011-03-06 10:29:35 +0000732</blockquote>
733<h3>LWS_CALLBACK_CONFIRM_EXTENSION_OKAY</h3>
734<blockquote>
735When the server handshake code
736sees that it does support a requested extension, before
737accepting the extension by additing to the list sent back to
738the client it gives this callback just to check that it's okay
739to use that extension. It calls back to the requested protocol
740and with <tt><b>in</b></tt> being the extension name, <tt><b>len</b></tt> is 0 and <tt><b>user</b></tt> is
741valid. Note though at this time the ESTABLISHED callback hasn't
742happened yet so if you initialize <tt><b>user</b></tt> content there, <tt><b>user</b></tt>
743content during this callback might not be useful for anything.
744Notice this callback comes to protocols[0].
Andy Greenc6517fa2011-03-06 13:15:29 +0000745</blockquote>
746<h3>LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED</h3>
747<blockquote>
748When a client
749connection is being prepared to start a handshake to a server,
750each supported extension is checked with protocols[0] callback
751with this reason, giving the user code a chance to suppress the
752claim to support that extension by returning non-zero. If
753unhandled, by default 0 will be returned and the extension
754support included in the header to the server. Notice this
755callback comes to protocols[0].
Andy Greena7109e62013-02-11 12:05:54 +0800756</blockquote>
757<h3>LWS_CALLBACK_PROTOCOL_INIT</h3>
758<blockquote>
759One-time call per protocol so it can
760do initial setup / allocations etc
761</blockquote>
762<h3>LWS_CALLBACK_PROTOCOL_DESTROY</h3>
763<blockquote>
764One-time call per protocol indicating
765this protocol won't get used at all after this callback, the
766context is getting destroyed. Take the opportunity to
767deallocate everything that was allocated by the protocol.
Andy Greenc85619d2011-02-13 08:25:26 +0000768<p>
769The next four reasons are optional and only need taking care of if you
770will be integrating libwebsockets sockets into an external polling
771array.
772</blockquote>
773<h3>LWS_CALLBACK_ADD_POLL_FD</h3>
774<blockquote>
775libwebsocket deals with its <b>poll</b> loop
776internally, but in the case you are integrating with another
777server you will need to have libwebsocket sockets share a
778polling array with the other server. This and the other
779POLL_FD related callbacks let you put your specialized
780poll array interface code in the callback for protocol 0, the
781first protocol you support, usually the HTTP protocol in the
782serving case. This callback happens when a socket needs to be
783</blockquote>
784<h3>added to the polling loop</h3>
785<blockquote>
786<tt><b>user</b></tt> contains the fd, and
787<tt><b>len</b></tt> is the events bitmap (like, POLLIN). If you are using the
788internal polling loop (the "service" callback), you can just
789ignore these callbacks.
790</blockquote>
791<h3>LWS_CALLBACK_DEL_POLL_FD</h3>
792<blockquote>
793This callback happens when a socket descriptor
794needs to be removed from an external polling array. <tt><b>user</b></tt> is
795the socket desricptor. If you are using the internal polling
796loop, you can just ignore it.
797</blockquote>
798<h3>LWS_CALLBACK_SET_MODE_POLL_FD</h3>
799<blockquote>
800This callback happens when libwebsockets
801wants to modify the events for the socket descriptor in <tt><b>user</b></tt>.
802The handler should OR <tt><b>len</b></tt> on to the events member of the pollfd
803struct for this socket descriptor. If you are using the
804internal polling loop, you can just ignore it.
805</blockquote>
806<h3>LWS_CALLBACK_CLEAR_MODE_POLL_FD</h3>
807<blockquote>
808This callback occurs when libwebsockets
809wants to modify the events for the socket descriptor in <tt><b>user</b></tt>.
810The handler should AND ~<tt><b>len</b></tt> on to the events member of the
811pollfd struct for this socket descriptor. If you are using the
812internal polling loop, you can just ignore it.
813</blockquote>
Andy Green8f037e42010-12-19 22:13:26 +0000814<hr>
Andy Green57b4e9a2011-03-06 13:14:46 +0000815<h2>extension_callback - Hooks to allow extensions to operate</h2>
Andy Green07b56e62011-10-03 19:30:22 +0800816<i>LWS_EXTERN int</i>
Andy Green57b4e9a2011-03-06 13:14:46 +0000817<b>extension_callback</b>
818(<i>struct libwebsocket_context *</i> <b>context</b>,
Andy Green46c2ea02011-03-22 09:04:01 +0000819<i>struct libwebsocket_extension *</i> <b>ext</b>,
Andy Green57b4e9a2011-03-06 13:14:46 +0000820<i>struct libwebsocket *</i> <b>wsi</b>,
David Brooks2c60d952012-04-20 12:19:01 +0800821<i>enum libwebsocket_extension_callback_reasons</i> <b>reason</b>,
Andy Green57b4e9a2011-03-06 13:14:46 +0000822<i>void *</i> <b>user</b>,
823<i>void *</i> <b>in</b>,
824<i>size_t</i> <b>len</b>)
825<h3>Arguments</h3>
826<dl>
827<dt><b>context</b>
828<dd>Websockets context
Andy Green46c2ea02011-03-22 09:04:01 +0000829<dt><b>ext</b>
830<dd>This extension
Andy Green57b4e9a2011-03-06 13:14:46 +0000831<dt><b>wsi</b>
832<dd>Opaque websocket instance pointer
833<dt><b>reason</b>
834<dd>The reason for the call
835<dt><b>user</b>
836<dd>Pointer to per-session user data allocated by library
837<dt><b>in</b>
838<dd>Pointer used for some callback reasons
839<dt><b>len</b>
840<dd>Length set for some callback reasons
841</dl>
842<h3>Description</h3>
843<blockquote>
844Each extension that is active on a particular connection receives
845callbacks during the connection lifetime to allow the extension to
846operate on websocket data and manage itself.
847<p>
848Libwebsockets takes care of allocating and freeing "user" memory for
849each active extension on each connection. That is what is pointed to
850by the <tt><b>user</b></tt> parameter.
851</blockquote>
852<h3>LWS_EXT_CALLBACK_CONSTRUCT</h3>
853<blockquote>
854called when the server has decided to
855select this extension from the list provided by the client,
856just before the server will send back the handshake accepting
857the connection with this extension active. This gives the
858extension a chance to initialize its connection context found
859in <tt><b>user</b></tt>.
860</blockquote>
Andy Green2366b1c2011-03-06 13:15:31 +0000861<h3>LWS_EXT_CALLBACK_CLIENT_CONSTRUCT</h3>
862<blockquote>
863same as LWS_EXT_CALLBACK_CONSTRUCT
864but called when client is instantiating this extension. Some
865extensions will work the same on client and server side and then
866you can just merge handlers for both CONSTRUCTS.
867</blockquote>
Andy Green57b4e9a2011-03-06 13:14:46 +0000868<h3>LWS_EXT_CALLBACK_DESTROY</h3>
869<blockquote>
870called when the connection the extension was
871being used on is about to be closed and deallocated. It's the
872last chance for the extension to deallocate anything it has
873allocated in the user data (pointed to by <tt><b>user</b></tt>) before the
Andy Green2366b1c2011-03-06 13:15:31 +0000874user data is deleted. This same callback is used whether you
875are in client or server instantiation context.
Andy Green57b4e9a2011-03-06 13:14:46 +0000876</blockquote>
877<h3>LWS_EXT_CALLBACK_PACKET_RX_PREPARSE</h3>
878<blockquote>
879when this extension was active on
880a connection, and a packet of data arrived at the connection,
881it is passed to this callback to give the extension a chance to
882change the data, eg, decompress it. <tt><b>user</b></tt> is pointing to the
883extension's private connection context data, <tt><b>in</b></tt> is pointing
884to an lws_tokens struct, it consists of a char * pointer called
885token, and an int called token_len. At entry, these are
886set to point to the received buffer and set to the content
887length. If the extension will grow the content, it should use
888a new buffer allocated in its private user context data and
889set the pointed-to lws_tokens members to point to its buffer.
890</blockquote>
891<h3>LWS_EXT_CALLBACK_PACKET_TX_PRESEND</h3>
892<blockquote>
893this works the same way as
894LWS_EXT_CALLBACK_PACKET_RX_PREPARSE above, except it gives the
895extension a chance to change websocket data just before it will
896be sent out. Using the same lws_token pointer scheme in <tt><b>in</b></tt>,
897the extension can change the buffer and the length to be
898transmitted how it likes. Again if it wants to grow the
899buffer safely, it should copy the data into its own buffer and
900set the lws_tokens token pointer to it.
901</blockquote>
902<hr>
Andy Green4f3943a2010-11-12 10:44:16 +0000903<h2>struct libwebsocket_protocols - List of protocols and handlers server supports.</h2>
904<b>struct libwebsocket_protocols</b> {<br>
905&nbsp; &nbsp; <i>const char *</i> <b>name</b>;<br>
David Brooks2c60d952012-04-20 12:19:01 +0800906&nbsp; &nbsp; <i>callback_function *</i> <b>callback</b>;<br>
Andy Green4f3943a2010-11-12 10:44:16 +0000907&nbsp; &nbsp; <i>size_t</i> <b>per_session_data_size</b>;<br>
Andy Green54495112013-02-06 21:10:16 +0900908&nbsp; &nbsp; <i>size_t</i> <b>rx_buffer_size</b>;<br>
Andy Greenb45993c2010-12-18 15:13:50 +0000909&nbsp; &nbsp; <i>struct libwebsocket_context *</i> <b>owning_server</b>;<br>
Andy Greenb45993c2010-12-18 15:13:50 +0000910&nbsp; &nbsp; <i>int</i> <b>protocol_index</b>;<br>
Andy Green4f3943a2010-11-12 10:44:16 +0000911};<br>
912<h3>Members</h3>
913<dl>
914<dt><b>name</b>
915<dd>Protocol name that must match the one given in the client
916Javascript new WebSocket(url, 'protocol') name
917<dt><b>callback</b>
918<dd>The service callback used for this protocol. It allows the
919service action for an entire protocol to be encapsulated in
920the protocol-specific callback
921<dt><b>per_session_data_size</b>
922<dd>Each new connection using this protocol gets
923this much memory allocated on connection establishment and
924freed on connection takedown. A pointer to this per-connection
925allocation is passed into the callback in the 'user' parameter
Andy Green54495112013-02-06 21:10:16 +0900926<dt><b>rx_buffer_size</b>
927<dd>if you want atomic frames delivered to the callback, you
928should set this to the size of the biggest legal frame that
929you support. If the frame size is exceeded, there is no
930error, but the buffer will spill to the user callback when
931full, which you can detect by using
932<b>libwebsockets_remaining_packet_payload</b>. Notice that you
933just talk about frame size here, the LWS_SEND_BUFFER_PRE_PADDING
934and post-padding are automatically also allocated on top.
Andy Greenb45993c2010-12-18 15:13:50 +0000935<dt><b>owning_server</b>
936<dd>the server init call fills in this opaque pointer when
937registering this protocol with the server.
Andy Greenb45993c2010-12-18 15:13:50 +0000938<dt><b>protocol_index</b>
939<dd>which protocol we are starting from zero
Andy Green4f3943a2010-11-12 10:44:16 +0000940</dl>
941<h3>Description</h3>
942<blockquote>
943This structure represents one protocol supported by the server. An
944array of these structures is passed to <b>libwebsocket_create_server</b>
945allows as many protocols as you like to be handled by one server.
946</blockquote>
947<hr>
Andy Greend6e09112011-03-05 16:12:15 +0000948<h2>struct libwebsocket_extension - An extension we know how to cope with</h2>
949<b>struct libwebsocket_extension</b> {<br>
950&nbsp; &nbsp; <i>const char *</i> <b>name</b>;<br>
David Brooks2c60d952012-04-20 12:19:01 +0800951&nbsp; &nbsp; <i>extension_callback_function *</i> <b>callback</b>;<br>
Andy Greend6e09112011-03-05 16:12:15 +0000952&nbsp; &nbsp; <i>size_t</i> <b>per_session_data_size</b>;<br>
Andy Greenaa6fc442012-04-12 13:26:49 +0800953&nbsp; &nbsp; <i>void *</i> <b>per_context_private_data</b>;<br>
Andy Greend6e09112011-03-05 16:12:15 +0000954};<br>
955<h3>Members</h3>
956<dl>
957<dt><b>name</b>
958<dd>Formal extension name, eg, "deflate-stream"
959<dt><b>callback</b>
960<dd>Service callback
961<dt><b>per_session_data_size</b>
962<dd>Libwebsockets will auto-malloc this much
963memory for the use of the extension, a pointer
964to it comes in the <tt><b>user</b></tt> callback parameter
Andy Greenaa6fc442012-04-12 13:26:49 +0800965<dt><b>per_context_private_data</b>
Andy Green75020012013-02-07 23:43:56 +0800966<dd>Optional storage for this extension that
Andy Greenaa6fc442012-04-12 13:26:49 +0800967is per-context, so it can track stuff across
968all sessions, etc, if it wants
Andy Greend6e09112011-03-05 16:12:15 +0000969</dl>
970<hr>
Andy Green1b265272013-02-09 14:01:09 +0800971<h2>struct lws_context_creation_info - </h2>
972<b>struct lws_context_creation_info</b> {<br>
973&nbsp; &nbsp; <i>int</i> <b>port</b>;<br>
Andy Green7a506ba2013-02-12 10:13:02 +0800974&nbsp; &nbsp; <i>const char *</i> <b>iface</b>;<br>
Andy Green1b265272013-02-09 14:01:09 +0800975&nbsp; &nbsp; <i>struct libwebsocket_protocols *</i> <b>protocols</b>;<br>
976&nbsp; &nbsp; <i>struct libwebsocket_extension *</i> <b>extensions</b>;<br>
977&nbsp; &nbsp; <i>const char *</i> <b>ssl_cert_filepath</b>;<br>
978&nbsp; &nbsp; <i>const char *</i> <b>ssl_private_key_filepath</b>;<br>
979&nbsp; &nbsp; <i>const char *</i> <b>ssl_ca_filepath</b>;<br>
980&nbsp; &nbsp; <i>int</i> <b>gid</b>;<br>
981&nbsp; &nbsp; <i>int</i> <b>uid</b>;<br>
982&nbsp; &nbsp; <i>unsigned int</i> <b>options</b>;<br>
983&nbsp; &nbsp; <i>void *</i> <b>user</b>;<br>
Andy Greena690cd02013-02-09 12:25:31 +0800984&nbsp; &nbsp; <i>int</i> <b>ka_time</b>;<br>
985&nbsp; &nbsp; <i>int</i> <b>ka_probes</b>;<br>
986&nbsp; &nbsp; <i>int</i> <b>ka_interval</b>;<br>
Andy Green1b265272013-02-09 14:01:09 +0800987};<br>
988<h3>Members</h3>
989<dl>
990<dt><b>port</b>
991<dd>Port to listen on... you can use 0 to suppress listening on
992any port, that's what you want if you are not running a
993websocket server at all but just using it as a client
Andy Green7a506ba2013-02-12 10:13:02 +0800994<dt><b>iface</b>
995<dd>NULL to bind the listen socket to all interfaces, or the
996interface name, eg, "eth2"
Andy Green1b265272013-02-09 14:01:09 +0800997<dt><b>protocols</b>
998<dd>Array of structures listing supported protocols and a protocol-
999specific callback for each one. The list is ended with an
1000entry that has a NULL callback pointer.
1001It's not const because we write the owning_server member
1002<dt><b>extensions</b>
1003<dd>NULL or array of libwebsocket_extension structs listing the
1004extensions this context supports. If you configured with
1005--without-extensions, you should give NULL here.
1006<dt><b>ssl_cert_filepath</b>
1007<dd>If libwebsockets was compiled to use ssl, and you want
1008to listen using SSL, set to the filepath to fetch the
1009server cert from, otherwise NULL for unencrypted
1010<dt><b>ssl_private_key_filepath</b>
1011<dd>filepath to private key if wanting SSL mode,
1012else ignored
1013<dt><b>ssl_ca_filepath</b>
1014<dd>CA certificate filepath or NULL
1015<dt><b>gid</b>
1016<dd>group id to change to after setting listen socket, or -1.
1017<dt><b>uid</b>
1018<dd>user id to change to after setting listen socket, or -1.
1019<dt><b>options</b>
1020<dd>0, or LWS_SERVER_OPTION_DEFEAT_CLIENT_MASK
1021<dt><b>user</b>
1022<dd>optional user pointer that can be recovered via the context
1023pointer using libwebsocket_context_user
Andy Greena690cd02013-02-09 12:25:31 +08001024<dt><b>ka_time</b>
1025<dd>0 for no keepalive, otherwise apply this keepalive timeout to
1026all libwebsocket sockets, client or server
1027<dt><b>ka_probes</b>
1028<dd>if ka_time was nonzero, after the timeout expires how many
1029times to try to get a response from the peer before giving up
1030and killing the connection
1031<dt><b>ka_interval</b>
1032<dd>if ka_time was nonzero, how long to wait before each ka_probes
1033attempt
Andy Green1b265272013-02-09 14:01:09 +08001034</dl>
1035<hr>