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