blob: 1415ff5effbf694f8f7e051ed27ee7d42ce8b105 [file] [log] [blame]
Andy Greenf7ee5492011-02-13 09:04:21 +00001<h2>libwebsockets_hangup_on_client - Server calls to terminate client connection</h2>
2<i>void</i>
3<b>libwebsockets_hangup_on_client</b>
4(<i>struct libwebsocket_context *</i> <b>this</b>,
5<i>int</i> <b>fd</b>)
6<h3>Arguments</h3>
7<dl>
8<dt><b>this</b>
9<dd>libwebsockets context
10<dt><b>fd</b>
11<dd>Connection socket descriptor
12</dl>
13<hr>
Andy Green07034092011-02-13 08:37:12 +000014<h2>libwebsockets_get_peer_addresses - Get client address information</h2>
15<i>void</i>
16<b>libwebsockets_get_peer_addresses</b>
17(<i>int</i> <b>fd</b>,
18<i>char *</i> <b>name</b>,
19<i>int</i> <b>name_len</b>,
20<i>char *</i> <b>rip</b>,
21<i>int</i> <b>rip_len</b>)
22<h3>Arguments</h3>
23<dl>
24<dt><b>fd</b>
25<dd>Connection socket descriptor
26<dt><b>name</b>
27<dd>Buffer to take client address name
28<dt><b>name_len</b>
29<dd>Length of client address name buffer
30<dt><b>rip</b>
31<dd>Buffer to take client address IP qotted quad
32<dt><b>rip_len</b>
33<dd>Length of client address IP buffer
34</dl>
35<h3>Description</h3>
36<blockquote>
37This function fills in <tt><b>name</b></tt> and <tt><b>rip</b></tt> with the name and IP of
38the client connected with socket descriptor <tt><b>fd</b></tt>. Names may be
39truncated if there is not enough room. If either cannot be
40determined, they will be returned as valid zero-length strings.
41</blockquote>
42<hr>
Andy Green9f990342011-02-12 11:57:45 +000043<h2>libwebsocket_service_fd - Service polled socket with something waiting</h2>
44<i>int</i>
45<b>libwebsocket_service_fd</b>
46(<i>struct libwebsocket_context *</i> <b>this</b>,
47<i>struct pollfd *</i> <b>pollfd</b>)
48<h3>Arguments</h3>
49<dl>
50<dt><b>this</b>
51<dd>Websocket context
52<dt><b>pollfd</b>
53<dd>The pollfd entry describing the socket fd and which events
54happened.
55</dl>
56<h3>Description</h3>
57<blockquote>
58This function closes any active connections and then frees the
59context. After calling this, any further use of the context is
60undefined.
61</blockquote>
62<hr>
Andy Green6964bb52011-01-23 16:50:33 +000063<h2>libwebsocket_context_destroy - Destroy the websocket context</h2>
64<i>void</i>
65<b>libwebsocket_context_destroy</b>
66(<i>struct libwebsocket_context *</i> <b>this</b>)
67<h3>Arguments</h3>
68<dl>
69<dt><b>this</b>
70<dd>Websocket context
71</dl>
72<h3>Description</h3>
73<blockquote>
74This function closes any active connections and then frees the
75context. After calling this, any further use of the context is
76undefined.
77</blockquote>
78<hr>
79<h2>libwebsocket_service - Service any pending websocket activity</h2>
80<i>int</i>
81<b>libwebsocket_service</b>
82(<i>struct libwebsocket_context *</i> <b>this</b>,
83<i>int</i> <b>timeout_ms</b>)
84<h3>Arguments</h3>
85<dl>
86<dt><b>this</b>
87<dd>Websocket context
88<dt><b>timeout_ms</b>
89<dd>Timeout for poll; 0 means return immediately if nothing needed
90service otherwise block and service immediately, returning
91after the timeout if nothing needed service.
92</dl>
93<h3>Description</h3>
94<blockquote>
95This function deals with any pending websocket traffic, for three
96kinds of event. It handles these events on both server and client
97types of connection the same.
98<p>
991) Accept new connections to our context's server
100<p>
1012) Perform pending broadcast writes initiated from other forked
102processes (effectively serializing asynchronous broadcasts)
103<p>
1043) Call the receive callback for incoming frame data received by
105server or client connections.
106<p>
107You need to call this service function periodically to all the above
108functions to happen; if your application is single-threaded you can
109just call it in your main event loop.
110<p>
111Alternatively you can fork a new process that asynchronously handles
112calling this service in a loop. In that case you are happy if this
113call blocks your thread until it needs to take care of something and
114would call it with a large nonzero timeout. Your loop then takes no
115CPU while there is nothing happening.
116<p>
117If you are calling it in a single-threaded app, you don't want it to
118wait around blocking other things in your loop from happening, so you
119would call it with a timeout_ms of 0, so it returns immediately if
120nothing is pending, or as soon as it services whatever was pending.
121</blockquote>
122<hr>
Andy Green3221f922011-02-12 13:14:11 +0000123<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 +0000124<i>int</i>
125<b>libwebsocket_callback_on_writable</b>
126(<i>struct libwebsocket *</i> <b>wsi</b>)
127<h3>Arguments</h3>
128<dl>
129<dt><b>wsi</b>
130<dd>Websocket connection instance to get callback for
131</dl>
132<hr>
133<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>
134<i>int</i>
135<b>libwebsocket_callback_on_writable_all_protocol</b>
136(<i>const struct libwebsocket_protocols *</i> <b>protocol</b>)
137<h3>Arguments</h3>
138<dl>
139<dt><b>protocol</b>
140<dd>Protocol whose connections will get callbacks
141</dl>
142<hr>
Andy Greena6cbece2011-01-27 20:06:03 +0000143<h2>libwebsocket_get_socket_fd - returns the socket file descriptor</h2>
144<i>int</i>
145<b>libwebsocket_get_socket_fd</b>
146(<i>struct libwebsocket *</i> <b>wsi</b>)
147<h3>Arguments</h3>
148<dl>
149<dt><b>wsi</b>
150<dd>Websocket connection instance
151</dl>
152<h3>Description</h3>
153<blockquote>
154<p>
155You will not need this unless you are doing something special
156</blockquote>
157<hr>
Andy Green90c7cbc2011-01-27 06:26:52 +0000158<h2>libwebsocket_rx_flow_control - Enable and disable socket servicing for receieved packets.</h2>
159<i>int</i>
160<b>libwebsocket_rx_flow_control</b>
161(<i>struct libwebsocket *</i> <b>wsi</b>,
162<i>int</i> <b>enable</b>)
163<h3>Arguments</h3>
164<dl>
165<dt><b>wsi</b>
166<dd>Websocket connection instance to get callback for
167<dt><b>enable</b>
168<dd>0 = disable read servicing for this connection, 1 = enable
169</dl>
170<h3>Description</h3>
171<blockquote>
172<p>
173If the output side of a server process becomes choked, this allows flow
174control for the input side.
175</blockquote>
176<hr>
Andy Green2ac5a6f2011-01-28 10:00:18 +0000177<h2>libwebsocket_canonical_hostname - returns this host's hostname</h2>
178<i>const char *</i>
179<b>libwebsocket_canonical_hostname</b>
180(<i>struct libwebsocket_context *</i> <b>this</b>)
181<h3>Arguments</h3>
182<dl>
183<dt><b>this</b>
184<dd>Websocket context
185</dl>
186<h3>Description</h3>
187<blockquote>
188<p>
189This is typically used by client code to fill in the host parameter
190when making a client connection. You can only call it after the context
191has been created.
192</blockquote>
193<hr>
Andy Green4739e5c2011-01-22 12:51:57 +0000194<h2>libwebsocket_create_context - Create the websocket handler</h2>
Andy Greene92cd172011-01-19 13:11:55 +0000195<i>struct libwebsocket_context *</i>
Andy Green4739e5c2011-01-22 12:51:57 +0000196<b>libwebsocket_create_context</b>
Andy Green62a12932010-11-03 11:19:23 +0000197(<i>int</i> <b>port</b>,
Andy Greenb45993c2010-12-18 15:13:50 +0000198<i>struct libwebsocket_protocols *</i> <b>protocols</b>,
Andy Green3faa9c72010-11-08 17:03:03 +0000199<i>const char *</i> <b>ssl_cert_filepath</b>,
200<i>const char *</i> <b>ssl_private_key_filepath</b>,
201<i>int</i> <b>gid</b>,
Andy Green8014b292011-01-30 20:57:25 +0000202<i>int</i> <b>uid</b>,
203<i>unsigned int</i> <b>options</b>)
Andy Green62a12932010-11-03 11:19:23 +0000204<h3>Arguments</h3>
205<dl>
206<dt><b>port</b>
Andy Green4739e5c2011-01-22 12:51:57 +0000207<dd>Port to listen on... you can use 0 to suppress listening on
208any port, that's what you want if you are not running a
209websocket server at all but just using it as a client
Andy Green4f3943a2010-11-12 10:44:16 +0000210<dt><b>protocols</b>
211<dd>Array of structures listing supported protocols and a protocol-
212specific callback for each one. The list is ended with an
213entry that has a NULL callback pointer.
Andy Greenb45993c2010-12-18 15:13:50 +0000214It's not const because we write the owning_server member
Andy Green3faa9c72010-11-08 17:03:03 +0000215<dt><b>ssl_cert_filepath</b>
216<dd>If libwebsockets was compiled to use ssl, and you want
217to listen using SSL, set to the filepath to fetch the
218server cert from, otherwise NULL for unencrypted
219<dt><b>ssl_private_key_filepath</b>
220<dd>filepath to private key if wanting SSL mode,
221else ignored
222<dt><b>gid</b>
223<dd>group id to change to after setting listen socket, or -1.
224<dt><b>uid</b>
225<dd>user id to change to after setting listen socket, or -1.
Andy Greenbfb051f2011-02-09 08:49:14 +0000226<dt><b>options</b>
227<dd>0, or LWS_SERVER_OPTION_DEFEAT_CLIENT_MASK
Andy Green62a12932010-11-03 11:19:23 +0000228</dl>
229<h3>Description</h3>
230<blockquote>
Andy Green47943ae2010-11-12 11:15:49 +0000231This function creates the listening socket and takes care
Andy Green62a12932010-11-03 11:19:23 +0000232of all initialization in one step.
233<p>
Andy Greene92cd172011-01-19 13:11:55 +0000234After initialization, it returns a struct libwebsocket_context * that
235represents this server. After calling, user code needs to take care
236of calling <b>libwebsocket_service</b> with the context pointer to get the
237server's sockets serviced. This can be done in the same process context
238or a forked process, or another thread,
Andy Green47943ae2010-11-12 11:15:49 +0000239<p>
240The protocol callback functions are called for a handful of events
241including http requests coming in, websocket connections becoming
Andy Green62a12932010-11-03 11:19:23 +0000242established, and data arriving; it's also called periodically to allow
243async transmission.
244<p>
Andy Green47943ae2010-11-12 11:15:49 +0000245HTTP requests are sent always to the FIRST protocol in <tt><b>protocol</b></tt>, since
246at that time websocket protocol has not been negotiated. Other
247protocols after the first one never see any HTTP callack activity.
248<p>
Andy Green62a12932010-11-03 11:19:23 +0000249The server created is a simple http server by default; part of the
250websocket standard is upgrading this http connection to a websocket one.
251<p>
252This allows the same server to provide files like scripts and favicon /
253images or whatever over http and dynamic data over websockets all in
254one place; they're all handled in the user callback.
255</blockquote>
256<hr>
Andy Greene92cd172011-01-19 13:11:55 +0000257<h2>libwebsockets_fork_service_loop - Optional helper function forks off a process for the websocket server loop. You don't have to use this but if not, you have to make sure you are calling libwebsocket_service periodically to service the websocket traffic</h2>
258<i>int</i>
259<b>libwebsockets_fork_service_loop</b>
260(<i>struct libwebsocket_context *</i> <b>this</b>)
261<h3>Arguments</h3>
262<dl>
263<dt><b>this</b>
264<dd>server context returned by creation function
265</dl>
266<hr>
Andy Greenb45993c2010-12-18 15:13:50 +0000267<h2>libwebsockets_get_protocol - Returns a protocol pointer from a websocket connection.</h2>
268<i>const struct libwebsocket_protocols *</i>
269<b>libwebsockets_get_protocol</b>
270(<i>struct libwebsocket *</i> <b>wsi</b>)
271<h3>Arguments</h3>
272<dl>
273<dt><b>wsi</b>
274<dd>pointer to struct websocket you want to know the protocol of
275</dl>
276<h3>Description</h3>
277<blockquote>
278<p>
279This is useful to get the protocol to broadcast back to from inside
280the callback.
281</blockquote>
282<hr>
Andy Greene92cd172011-01-19 13:11:55 +0000283<h2>libwebsockets_broadcast - Sends a buffer to the callback for all active connections of the given protocol.</h2>
Andy Greenb45993c2010-12-18 15:13:50 +0000284<i>int</i>
285<b>libwebsockets_broadcast</b>
286(<i>const struct libwebsocket_protocols *</i> <b>protocol</b>,
287<i>unsigned char *</i> <b>buf</b>,
288<i>size_t</i> <b>len</b>)
289<h3>Arguments</h3>
290<dl>
291<dt><b>protocol</b>
292<dd>pointer to the protocol you will broadcast to all members of
293<dt><b>buf</b>
294<dd>buffer containing the data to be broadcase. NOTE: this has to be
295allocated with LWS_SEND_BUFFER_PRE_PADDING valid bytes before
296the pointer and LWS_SEND_BUFFER_POST_PADDING afterwards in the
297case you are calling this function from callback context.
298<dt><b>len</b>
299<dd>length of payload data in buf, starting from buf.
300</dl>
301<h3>Description</h3>
302<blockquote>
303This function allows bulk sending of a packet to every connection using
304the given protocol. It does not send the data directly; instead it calls
305the callback with a reason type of LWS_CALLBACK_BROADCAST. If the callback
306wants to actually send the data for that connection, the callback itself
307should call <b>libwebsocket_write</b>.
308<p>
309<b>libwebsockets_broadcast</b> can be called from another fork context without
310having to take any care about data visibility between the processes, it'll
311"just work".
312</blockquote>
313<hr>
Andy Green62a12932010-11-03 11:19:23 +0000314<h2>libwebsocket_write - Apply protocol then write data to client</h2>
315<i>int</i>
316<b>libwebsocket_write</b>
317(<i>struct libwebsocket *</i> <b>wsi</b>,
318<i>unsigned char *</i> <b>buf</b>,
319<i>size_t</i> <b>len</b>,
320<i>enum libwebsocket_write_protocol</i> <b>protocol</b>)
321<h3>Arguments</h3>
322<dl>
323<dt><b>wsi</b>
324<dd>Websocket instance (available from user callback)
325<dt><b>buf</b>
326<dd>The data to send. For data being sent on a websocket
327connection (ie, not default http), this buffer MUST have
328LWS_SEND_BUFFER_PRE_PADDING bytes valid BEFORE the pointer
329and an additional LWS_SEND_BUFFER_POST_PADDING bytes valid
330in the buffer after (buf + len). This is so the protocol
331header and trailer data can be added in-situ.
332<dt><b>len</b>
333<dd>Count of the data bytes in the payload starting from buf
334<dt><b>protocol</b>
335<dd>Use LWS_WRITE_HTTP to reply to an http connection, and one
336of LWS_WRITE_BINARY or LWS_WRITE_TEXT to send appropriate
337data on a websockets connection. Remember to allow the extra
338bytes before and after buf if LWS_WRITE_BINARY or LWS_WRITE_TEXT
339are used.
340</dl>
341<h3>Description</h3>
342<blockquote>
343This function provides the way to issue data back to the client
344for both http and websocket protocols.
345<p>
346In the case of sending using websocket protocol, be sure to allocate
347valid storage before and after buf as explained above. This scheme
348allows maximum efficiency of sending data and protocol in a single
349packet while not burdening the user code with any protocol knowledge.
350</blockquote>
351<hr>
352<h2>libwebsockets_serve_http_file - Send a file back to the client using http</h2>
353<i>int</i>
354<b>libwebsockets_serve_http_file</b>
355(<i>struct libwebsocket *</i> <b>wsi</b>,
356<i>const char *</i> <b>file</b>,
357<i>const char *</i> <b>content_type</b>)
358<h3>Arguments</h3>
359<dl>
360<dt><b>wsi</b>
361<dd>Websocket instance (available from user callback)
362<dt><b>file</b>
363<dd>The file to issue over http
364<dt><b>content_type</b>
365<dd>The http content type, eg, text/html
366</dl>
367<h3>Description</h3>
368<blockquote>
369This function is intended to be called from the callback in response
370to http requests from the client. It allows the callback to issue
371local files down the http link in a single step.
372</blockquote>
373<hr>
Andy Green38e57bb2011-01-19 12:20:27 +0000374<h2>libwebsockets_remaining_packet_payload - Bytes to come before "overall" rx packet is complete</h2>
375<i>size_t</i>
376<b>libwebsockets_remaining_packet_payload</b>
377(<i>struct libwebsocket *</i> <b>wsi</b>)
378<h3>Arguments</h3>
379<dl>
380<dt><b>wsi</b>
381<dd>Websocket instance (available from user callback)
382</dl>
383<h3>Description</h3>
384<blockquote>
385This function is intended to be called from the callback if the
386user code is interested in "complete packets" from the client.
387libwebsockets just passes through payload as it comes and issues a buffer
388additionally when it hits a built-in limit. The LWS_CALLBACK_RECEIVE
389callback handler can use this API to find out if the buffer it has just
390been given is the last piece of a "complete packet" from the client --
391when that is the case <b>libwebsockets_remaining_packet_payload</b> will return
3920.
393<p>
394Many protocols won't care becuse their packets are always small.
395</blockquote>
396<hr>
Andy Green90c7cbc2011-01-27 06:26:52 +0000397<h2>libwebsocket_client_connect - Connect to another websocket server</h2>
398<i>struct libwebsocket *</i>
399<b>libwebsocket_client_connect</b>
400(<i>struct libwebsocket_context *</i> <b>this</b>,
401<i>const char *</i> <b>address</b>,
402<i>int</i> <b>port</b>,
403<i>int</i> <b>ssl_connection</b>,
404<i>const char *</i> <b>path</b>,
405<i>const char *</i> <b>host</b>,
406<i>const char *</i> <b>origin</b>,
Andy Greenbfb051f2011-02-09 08:49:14 +0000407<i>const char *</i> <b>protocol</b>,
408<i>int</i> <b>ietf_version_or_minus_one</b>)
Andy Green90c7cbc2011-01-27 06:26:52 +0000409<h3>Arguments</h3>
410<dl>
411<dt><b>this</b>
412<dd>Websocket context
413<dt><b>address</b>
414<dd>Remote server address, eg, "myserver.com"
415<dt><b>port</b>
416<dd>Port to connect to on the remote server, eg, 80
417<dt><b>ssl_connection</b>
418<dd>0 = ws://, 1 = wss:// encrypted, 2 = wss:// allow self
419signed certs
420<dt><b>path</b>
421<dd>Websocket path on server
422<dt><b>host</b>
423<dd>Hostname on server
424<dt><b>origin</b>
425<dd>Socket origin name
426<dt><b>protocol</b>
427<dd>Comma-separated list of protocols being asked for from
428the server, or just one. The server will pick the one it
429likes best.
Andy Greenbfb051f2011-02-09 08:49:14 +0000430<dt><b>ietf_version_or_minus_one</b>
431<dd>-1 to ask to connect using the default, latest
432protocol supported, or the specific protocol ordinal
Andy Green90c7cbc2011-01-27 06:26:52 +0000433</dl>
434<h3>Description</h3>
435<blockquote>
436This function creates a connection to a remote server
437</blockquote>
438<hr>
Andy Green8f037e42010-12-19 22:13:26 +0000439<h2>callback - User server actions</h2>
440<i>int</i>
441<b>callback</b>
442(<i>struct libwebsocket *</i> <b>wsi</b>,
443<i>enum libwebsocket_callback_reasons</i> <b>reason</b>,
444<i>void *</i> <b>user</b>,
445<i>void *</i> <b>in</b>,
446<i>size_t</i> <b>len</b>)
447<h3>Arguments</h3>
448<dl>
449<dt><b>wsi</b>
450<dd>Opaque websocket instance pointer
451<dt><b>reason</b>
452<dd>The reason for the call
453<dt><b>user</b>
454<dd>Pointer to per-session user data allocated by library
455<dt><b>in</b>
456<dd>Pointer used for some callback reasons
457<dt><b>len</b>
458<dd>Length set for some callback reasons
459</dl>
460<h3>Description</h3>
461<blockquote>
462This callback is the way the user controls what is served. All the
463protocol detail is hidden and handled by the library.
464<p>
465For each connection / session there is user data allocated that is
466pointed to by "user". You set the size of this user data area when
467the library is initialized with libwebsocket_create_server.
468<p>
469You get an opportunity to initialize user data when called back with
470LWS_CALLBACK_ESTABLISHED reason.
471</blockquote>
472<h3>LWS_CALLBACK_ESTABLISHED</h3>
473<blockquote>
Andy Green90c7cbc2011-01-27 06:26:52 +0000474after the server completes a handshake with
475an incoming client
476</blockquote>
477<h3>LWS_CALLBACK_CLIENT_ESTABLISHED</h3>
478<blockquote>
479after your client connection completed
480a handshake with the remote server
Andy Green8f037e42010-12-19 22:13:26 +0000481</blockquote>
482<h3>LWS_CALLBACK_CLOSED</h3>
483<blockquote>
484when the websocket session ends
485</blockquote>
486<h3>LWS_CALLBACK_BROADCAST</h3>
487<blockquote>
488signal to send to client (you would use
489<b>libwebsocket_write</b> taking care about the
490special buffer requirements
491</blockquote>
492<h3>LWS_CALLBACK_RECEIVE</h3>
493<blockquote>
Andy Green90c7cbc2011-01-27 06:26:52 +0000494data has appeared for this server endpoint from a
495remote client, it can be found at *in and is
496len bytes long
497</blockquote>
Andy Greena6cbece2011-01-27 20:06:03 +0000498<h3>LWS_CALLBACK_CLIENT_RECEIVE_PONG</h3>
499<blockquote>
500if you elected to see PONG packets,
501they appear with this callback reason. PONG
502packets only exist in 04+ protocol
503</blockquote>
Andy Green90c7cbc2011-01-27 06:26:52 +0000504<h3>LWS_CALLBACK_CLIENT_RECEIVE</h3>
505<blockquote>
506data has appeared from the server for the
507client connection, it can be found at *in and
508is len bytes long
Andy Green8f037e42010-12-19 22:13:26 +0000509</blockquote>
510<h3>LWS_CALLBACK_HTTP</h3>
511<blockquote>
512an http request has come from a client that is not
513asking to upgrade the connection to a websocket
514one. This is a chance to serve http content,
515for example, to send a script to the client
516which will then open the websockets connection.
Andy Green7619c472011-01-23 17:47:08 +0000517<tt><b>in</b></tt> points to the URI path requested and
Andy Green8f037e42010-12-19 22:13:26 +0000518<b>libwebsockets_serve_http_file</b> makes it very
519simple to send back a file to the client.
520</blockquote>
Andy Green90c7cbc2011-01-27 06:26:52 +0000521<h3>LWS_CALLBACK_CLIENT_WRITEABLE</h3>
522<blockquote>
523if you call
524<b>libwebsocket_callback_on_writable</b> on a connection, you will
525get this callback coming when the connection socket is able to
526accept another write packet without blocking. If it already
527was able to take another packet without blocking, you'll get
528this callback at the next call to the service loop function.
529</blockquote>
Andy Green07034092011-02-13 08:37:12 +0000530<h3>LWS_CALLBACK_FILTER_NETWORK_CONNECTION</h3>
531<blockquote>
532called when a client connects to
533the server at network level; the connection is accepted but then
534passed to this callback to decide whether to hang up immediately
535or not, based on the client IP. <tt><b>user</b></tt> contains the connection
536socket's descriptor. Return non-zero to terminate
537the connection before sending or receiving anything.
538Because this happens immediately after the network connection
539from the client, there's no websocket protocol selected yet so
540this callback is issued only to protocol 0.
541</blockquote>
Andy Greenc85619d2011-02-13 08:25:26 +0000542<h3>LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION</h3>
543<blockquote>
544called when the handshake has
545been received and parsed from the client, but the response is
546not sent yet. Return non-zero to disallow the connection.
Andy Green07034092011-02-13 08:37:12 +0000547<tt><b>user</b></tt> is a pointer to an array of struct lws_tokens, you can
548use the header enums lws_token_indexes from libwebsockets.h
549to check for and read the supported header presence and
550content before deciding to allow the handshake to proceed or
551to kill the connection.
Andy Greenc85619d2011-02-13 08:25:26 +0000552<p>
553<p>
554The next four reasons are optional and only need taking care of if you
555will be integrating libwebsockets sockets into an external polling
556array.
557</blockquote>
558<h3>LWS_CALLBACK_ADD_POLL_FD</h3>
559<blockquote>
560libwebsocket deals with its <b>poll</b> loop
561internally, but in the case you are integrating with another
562server you will need to have libwebsocket sockets share a
563polling array with the other server. This and the other
564POLL_FD related callbacks let you put your specialized
565poll array interface code in the callback for protocol 0, the
566first protocol you support, usually the HTTP protocol in the
567serving case. This callback happens when a socket needs to be
568</blockquote>
569<h3>added to the polling loop</h3>
570<blockquote>
571<tt><b>user</b></tt> contains the fd, and
572<tt><b>len</b></tt> is the events bitmap (like, POLLIN). If you are using the
573internal polling loop (the "service" callback), you can just
574ignore these callbacks.
575</blockquote>
576<h3>LWS_CALLBACK_DEL_POLL_FD</h3>
577<blockquote>
578This callback happens when a socket descriptor
579needs to be removed from an external polling array. <tt><b>user</b></tt> is
580the socket desricptor. If you are using the internal polling
581loop, you can just ignore it.
582</blockquote>
583<h3>LWS_CALLBACK_SET_MODE_POLL_FD</h3>
584<blockquote>
585This callback happens when libwebsockets
586wants to modify the events for the socket descriptor in <tt><b>user</b></tt>.
587The handler should OR <tt><b>len</b></tt> on to the events member of the pollfd
588struct for this socket descriptor. If you are using the
589internal polling loop, you can just ignore it.
590</blockquote>
591<h3>LWS_CALLBACK_CLEAR_MODE_POLL_FD</h3>
592<blockquote>
593This callback occurs when libwebsockets
594wants to modify the events for the socket descriptor in <tt><b>user</b></tt>.
595The handler should AND ~<tt><b>len</b></tt> on to the events member of the
596pollfd struct for this socket descriptor. If you are using the
597internal polling loop, you can just ignore it.
598</blockquote>
Andy Green8f037e42010-12-19 22:13:26 +0000599<hr>
Andy Green4f3943a2010-11-12 10:44:16 +0000600<h2>struct libwebsocket_protocols - List of protocols and handlers server supports.</h2>
601<b>struct libwebsocket_protocols</b> {<br>
602&nbsp; &nbsp; <i>const char *</i> <b>name</b>;<br>
Andy Greene77ddd82010-11-13 10:03:47 +0000603&nbsp; &nbsp; <i>int (*</i><b>callback</b>) <i>(struct libwebsocket *wsi,enum libwebsocket_callback_reasons reason, void *user,void *in, size_t len)</i>;<br>
Andy Green4f3943a2010-11-12 10:44:16 +0000604&nbsp; &nbsp; <i>size_t</i> <b>per_session_data_size</b>;<br>
Andy Greenb45993c2010-12-18 15:13:50 +0000605&nbsp; &nbsp; <i>struct libwebsocket_context *</i> <b>owning_server</b>;<br>
606&nbsp; &nbsp; <i>int</i> <b>broadcast_socket_port</b>;<br>
607&nbsp; &nbsp; <i>int</i> <b>broadcast_socket_user_fd</b>;<br>
608&nbsp; &nbsp; <i>int</i> <b>protocol_index</b>;<br>
Andy Green4f3943a2010-11-12 10:44:16 +0000609};<br>
610<h3>Members</h3>
611<dl>
612<dt><b>name</b>
613<dd>Protocol name that must match the one given in the client
614Javascript new WebSocket(url, 'protocol') name
615<dt><b>callback</b>
616<dd>The service callback used for this protocol. It allows the
617service action for an entire protocol to be encapsulated in
618the protocol-specific callback
619<dt><b>per_session_data_size</b>
620<dd>Each new connection using this protocol gets
621this much memory allocated on connection establishment and
622freed on connection takedown. A pointer to this per-connection
623allocation is passed into the callback in the 'user' parameter
Andy Greenb45993c2010-12-18 15:13:50 +0000624<dt><b>owning_server</b>
625<dd>the server init call fills in this opaque pointer when
626registering this protocol with the server.
627<dt><b>broadcast_socket_port</b>
628<dd>the server init call fills this in with the
629localhost port number used to forward broadcasts for this
630protocol
631<dt><b>broadcast_socket_user_fd</b>
632<dd>the server init call fills this in ... the <b>main</b>
633process context can write to this socket to perform broadcasts
634(use the <b>libwebsockets_broadcast</b> api to do this instead,
635it works from any process context)
636<dt><b>protocol_index</b>
637<dd>which protocol we are starting from zero
Andy Green4f3943a2010-11-12 10:44:16 +0000638</dl>
639<h3>Description</h3>
640<blockquote>
641This structure represents one protocol supported by the server. An
642array of these structures is passed to <b>libwebsocket_create_server</b>
643allows as many protocols as you like to be handled by one server.
644</blockquote>
645<hr>