1 <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>)
18 <dd>Remote server address, eg, "myserver.com"
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
25 <dd>Websocket path on server
27 <dd>Hostname on server
29 <dd>Socket origin name
31 <dd>Comma-separated list of protocols being asked for from
32 the server, or just one. The server will pick the one it
34 <dt><b>ietf_version_or_minus_one</b>
35 <dd>-1 to ask to connect using the default, latest
36 protocol supported, or the specific protocol ordinal
40 This function creates a connection to a remote server
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>)
61 <dd>Remote server address, eg, "myserver.com"
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
68 <dd>Websocket path on server
70 <dd>Hostname on server
72 <dd>Socket origin name
74 <dd>Comma-separated list of protocols being asked for from
75 the server, or just one. The server will pick the one it
77 <dt><b>ietf_version_or_minus_one</b>
78 <dd>-1 to ask to connect using the default, latest
79 protocol supported, or the specific protocol ordinal
81 <dd>Pre-allocated user data
85 This function creates a connection to a remote server
88 <h2>lws_get_library_version - </h2>
90 <b>lws_get_library_version</b>
100 returns a const char * to a string like "1.1 178d78c"
101 representing the library version followed by the git head hash it
105 <h2>libwebsockets_hangup_on_client - Server calls to terminate client connection</h2>
107 <b>libwebsockets_hangup_on_client</b>
108 (<i>struct libwebsocket_context *</i> <b>context</b>,
109 <i>int</i> <b>fd</b>)
113 <dd>libwebsockets context
115 <dd>Connection socket descriptor
118 <h2>libwebsockets_get_peer_addresses - Get client address information</h2>
120 <b>libwebsockets_get_peer_addresses</b>
121 (<i>struct libwebsocket_context *</i> <b>context</b>,
122 <i>struct libwebsocket *</i> <b>wsi</b>,
123 <i>int</i> <b>fd</b>,
124 <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>)
131 <dd>Libwebsockets context
133 <dd>Local struct libwebsocket associated with
135 <dd>Connection socket descriptor
137 <dd>Buffer to take client address name
139 <dd>Length of client address name buffer
141 <dd>Buffer to take client address IP qotted quad
143 <dd>Length of client address IP buffer
147 This function fills in <tt><b>name</b></tt> and <tt><b>rip</b></tt> with the name and IP of
148 the client connected with socket descriptor <tt><b>fd</b></tt>. Names may be
149 truncated if there is not enough room. If either cannot be
150 determined, they will be returned as valid zero-length strings.
153 <h2>libwebsocket_service_fd - Service polled socket with something waiting</h2>
155 <b>libwebsocket_service_fd</b>
156 (<i>struct libwebsocket_context *</i> <b>context</b>,
157 <i>struct pollfd *</i> <b>pollfd</b>)
161 <dd>Websocket context
163 <dd>The pollfd entry describing the socket fd and which events
168 This function takes a pollfd that has POLLIN or POLLOUT activity and
169 services it according to the state of the associated struct libwebsocket.
171 The one call deals with all "service" that might happen on a socket
172 including listen accepts, http files as well as websocket protocol.
175 <h2>libwebsocket_context_destroy - Destroy the websocket context</h2>
177 <b>libwebsocket_context_destroy</b>
178 (<i>struct libwebsocket_context *</i> <b>context</b>)
182 <dd>Websocket context
186 This function closes any active connections and then frees the
187 context. After calling this, any further use of the context is
191 <h2>libwebsocket_context_user - get the user data associated with the whole context</h2>
192 <i>LWS_EXTERN void *</i>
193 <b>libwebsocket_context_user</b>
194 (<i>struct libwebsocket_context *</i> <b>context</b>)
198 <dd>Websocket context
202 This returns the optional user allocation that can be attached to
203 the context the sockets live in at context_create time. It's a way
204 to let all sockets serviced in the same context share data without
205 using globals statics in the user code.
208 <h2>libwebsocket_service - Service any pending websocket activity</h2>
210 <b>libwebsocket_service</b>
211 (<i>struct libwebsocket_context *</i> <b>context</b>,
212 <i>int</i> <b>timeout_ms</b>)
216 <dd>Websocket context
217 <dt><b>timeout_ms</b>
218 <dd>Timeout for poll; 0 means return immediately if nothing needed
219 service otherwise block and service immediately, returning
220 after the timeout if nothing needed service.
224 This function deals with any pending websocket traffic, for three
225 kinds of event. It handles these events on both server and client
226 types of connection the same.
228 1) Accept new connections to our context's server
230 2) Call the receive callback for incoming frame data received by
231 server or client connections.
233 You need to call this service function periodically to all the above
234 functions to happen; if your application is single-threaded you can
235 just call it in your main event loop.
237 Alternatively you can fork a new process that asynchronously handles
238 calling this service in a loop. In that case you are happy if this
239 call blocks your thread until it needs to take care of something and
240 would call it with a large nonzero timeout. Your loop then takes no
241 CPU while there is nothing happening.
243 If you are calling it in a single-threaded app, you don't want it to
244 wait around blocking other things in your loop from happening, so you
245 would call it with a timeout_ms of 0, so it returns immediately if
246 nothing is pending, or as soon as it services whatever was pending.
249 <h2>libwebsocket_callback_on_writable - Request a callback when this socket becomes able to be written to without blocking</h2>
251 <b>libwebsocket_callback_on_writable</b>
252 (<i>struct libwebsocket_context *</i> <b>context</b>,
253 <i>struct libwebsocket *</i> <b>wsi</b>)
257 <dd>libwebsockets context
259 <dd>Websocket connection instance to get callback for
262 <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 <b>libwebsocket_callback_on_writable_all_protocol</b>
265 (<i>const struct libwebsocket_protocols *</i> <b>protocol</b>)
269 <dd>Protocol whose connections will get callbacks
272 <h2>libwebsocket_set_timeout - marks the wsi as subject to a timeout</h2>
274 <b>libwebsocket_set_timeout</b>
275 (<i>struct libwebsocket *</i> <b>wsi</b>,
276 <i>enum pending_timeout</i> <b>reason</b>,
277 <i>int</i> <b>secs</b>)
281 <dd>Websocket connection instance
290 You will not need this unless you are doing something special
293 <h2>libwebsocket_get_socket_fd - returns the socket file descriptor</h2>
295 <b>libwebsocket_get_socket_fd</b>
296 (<i>struct libwebsocket *</i> <b>wsi</b>)
300 <dd>Websocket connection instance
305 You will not need this unless you are doing something special
308 <h2>libwebsocket_rx_flow_control - Enable and disable socket servicing for receieved packets.</h2>
310 <b>libwebsocket_rx_flow_control</b>
311 (<i>struct libwebsocket *</i> <b>wsi</b>,
312 <i>int</i> <b>enable</b>)
316 <dd>Websocket connection instance to get callback for
318 <dd>0 = disable read servicing for this connection, 1 = enable
323 If the output side of a server process becomes choked, this allows flow
324 control for the input side.
327 <h2>libwebsocket_canonical_hostname - returns this host's hostname</h2>
329 <b>libwebsocket_canonical_hostname</b>
330 (<i>struct libwebsocket_context *</i> <b>context</b>)
334 <dd>Websocket context
339 This is typically used by client code to fill in the host parameter
340 when making a client connection. You can only call it after the context
344 <h2>libwebsocket_create_context - Create the websocket handler</h2>
345 <i>struct libwebsocket_context *</i>
346 <b>libwebsocket_create_context</b>
347 (<i>struct lws_context_creation_info *</i> <b>info</b>)
351 <dd>pointer to struct with parameters
355 This function creates the listening socket (if serving) and takes care
356 of all initialization in one step.
358 After initialization, it returns a struct libwebsocket_context * that
359 represents this server. After calling, user code needs to take care
360 of calling <b>libwebsocket_service</b> with the context pointer to get the
361 server's sockets serviced. This can be done in the same process context
362 or a forked process, or another thread,
364 The protocol callback functions are called for a handful of events
365 including http requests coming in, websocket connections becoming
366 established, and data arriving; it's also called periodically to allow
369 HTTP requests are sent always to the FIRST protocol in <tt><b>protocol</b></tt>, since
370 at that time websocket protocol has not been negotiated. Other
371 protocols after the first one never see any HTTP callack activity.
373 The server created is a simple http server by default; part of the
374 websocket standard is upgrading this http connection to a websocket one.
376 This allows the same server to provide files like scripts and favicon /
377 images or whatever over http and dynamic data over websockets all in
378 one place; they're all handled in the user callback.
381 <h2>libwebsockets_get_protocol - Returns a protocol pointer from a websocket connection.</h2>
382 <i>const struct libwebsocket_protocols *</i>
383 <b>libwebsockets_get_protocol</b>
384 (<i>struct libwebsocket *</i> <b>wsi</b>)
388 <dd>pointer to struct websocket you want to know the protocol of
393 Some apis can act on all live connections of a given protocol,
394 this is how you can get a pointer to the active protocol if needed.
397 <h2>lws_set_log_level - Set the logging bitfield</h2>
399 <b>lws_set_log_level</b>
400 (<i>int</i> <b>level</b>,
401 <i>void (*</i><b>log_emit_function</b>) <i>(int level, const char *line)</i>)
405 <dd>OR together the LLL_ debug contexts you want output from
406 <dt><b>log_emit_function</b>
407 <dd>NULL to leave it as it is, or a user-supplied
408 function to perform log string emission instead of
409 the default stderr one.
413 log level defaults to "err" and "warn" contexts enabled only and
417 <h2>libwebsocket_write - Apply protocol then write data to client</h2>
419 <b>libwebsocket_write</b>
420 (<i>struct libwebsocket *</i> <b>wsi</b>,
421 <i>unsigned char *</i> <b>buf</b>,
422 <i>size_t</i> <b>len</b>,
423 <i>enum libwebsocket_write_protocol</i> <b>protocol</b>)
427 <dd>Websocket instance (available from user callback)
429 <dd>The data to send. For data being sent on a websocket
430 connection (ie, not default http), this buffer MUST have
431 LWS_SEND_BUFFER_PRE_PADDING bytes valid BEFORE the pointer
432 and an additional LWS_SEND_BUFFER_POST_PADDING bytes valid
433 in the buffer after (buf + len). This is so the protocol
434 header and trailer data can be added in-situ.
436 <dd>Count of the data bytes in the payload starting from buf
438 <dd>Use LWS_WRITE_HTTP to reply to an http connection, and one
439 of LWS_WRITE_BINARY or LWS_WRITE_TEXT to send appropriate
440 data on a websockets connection. Remember to allow the extra
441 bytes before and after buf if LWS_WRITE_BINARY or LWS_WRITE_TEXT
446 This function provides the way to issue data back to the client
447 for both http and websocket protocols.
449 In the case of sending using websocket protocol, be sure to allocate
450 valid storage before and after buf as explained above. This scheme
451 allows maximum efficiency of sending data and protocol in a single
452 packet while not burdening the user code with any protocol knowledge.
455 <h2>libwebsockets_serve_http_file - Send a file back to the client using http</h2>
457 <b>libwebsockets_serve_http_file</b>
458 (<i>struct libwebsocket_context *</i> <b>context</b>,
459 <i>struct libwebsocket *</i> <b>wsi</b>,
460 <i>const char *</i> <b>file</b>,
461 <i>const char *</i> <b>content_type</b>)
465 <dd>libwebsockets context
467 <dd>Websocket instance (available from user callback)
469 <dd>The file to issue over http
470 <dt><b>content_type</b>
471 <dd>The http content type, eg, text/html
475 This function is intended to be called from the callback in response
476 to http requests from the client. It allows the callback to issue
477 local files down the http link in a single step.
479 Returning <0 indicates error and the wsi should be closed. Returning
480 >0 indicates the file was completely sent and the wsi should be closed.
481 ==0 indicates the file transfer is started and needs more service later,
482 the wsi should be left alone.
485 <h2>lws_frame_is_binary - </h2>
487 <b>lws_frame_is_binary</b>
488 (<i>struct libwebsocket *</i> <b>wsi</b>)
492 <dd>the connection we are inquiring about
496 This is intended to be called from the LWS_CALLBACK_RECEIVE callback if
497 it's interested to see if the frame it's dealing with was sent in binary
501 <h2>libwebsockets_remaining_packet_payload - Bytes to come before "overall" rx packet is complete</h2>
503 <b>libwebsockets_remaining_packet_payload</b>
504 (<i>struct libwebsocket *</i> <b>wsi</b>)
508 <dd>Websocket instance (available from user callback)
512 This function is intended to be called from the callback if the
513 user code is interested in "complete packets" from the client.
514 libwebsockets just passes through payload as it comes and issues a buffer
515 additionally when it hits a built-in limit. The LWS_CALLBACK_RECEIVE
516 callback handler can use this API to find out if the buffer it has just
517 been given is the last piece of a "complete packet" from the client --
518 when that is the case <b>libwebsockets_remaining_packet_payload</b> will return
521 Many protocols won't care becuse their packets are always small.
524 <h2>callback - User server actions</h2>
525 <i>LWS_EXTERN int</i>
527 (<i>struct libwebsocket_context *</i> <b>context</b>,
528 <i>struct libwebsocket *</i> <b>wsi</b>,
529 <i>enum libwebsocket_callback_reasons</i> <b>reason</b>,
530 <i>void *</i> <b>user</b>,
531 <i>void *</i> <b>in</b>,
532 <i>size_t</i> <b>len</b>)
536 <dd>Websockets context
538 <dd>Opaque websocket instance pointer
540 <dd>The reason for the call
542 <dd>Pointer to per-session user data allocated by library
544 <dd>Pointer used for some callback reasons
546 <dd>Length set for some callback reasons
550 This callback is the way the user controls what is served. All the
551 protocol detail is hidden and handled by the library.
553 For each connection / session there is user data allocated that is
554 pointed to by "user". You set the size of this user data area when
555 the library is initialized with libwebsocket_create_server.
557 You get an opportunity to initialize user data when called back with
558 LWS_CALLBACK_ESTABLISHED reason.
560 <h3>LWS_CALLBACK_ESTABLISHED</h3>
562 after the server completes a handshake with
565 <h3>LWS_CALLBACK_CLIENT_CONNECTION_ERROR</h3>
567 the request client connection has
568 been unable to complete a handshake with the remote server
570 <h3>LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH</h3>
572 this is the last chance for the
573 client user code to examine the http headers
574 and decide to reject the connection. If the
575 content in the headers is interesting to the
576 client (url, etc) it needs to copy it out at
577 this point since it will be destroyed before
578 the CLIENT_ESTABLISHED call
580 <h3>LWS_CALLBACK_CLIENT_ESTABLISHED</h3>
582 after your client connection completed
583 a handshake with the remote server
585 <h3>LWS_CALLBACK_CLOSED</h3>
587 when the websocket session ends
589 <h3>LWS_CALLBACK_RECEIVE</h3>
591 data has appeared for this server endpoint from a
592 remote client, it can be found at *in and is
595 <h3>LWS_CALLBACK_CLIENT_RECEIVE_PONG</h3>
597 if you elected to see PONG packets,
598 they appear with this callback reason. PONG
599 packets only exist in 04+ protocol
601 <h3>LWS_CALLBACK_CLIENT_RECEIVE</h3>
603 data has appeared from the server for the
604 client connection, it can be found at *in and
607 <h3>LWS_CALLBACK_HTTP</h3>
609 an http request has come from a client that is not
610 asking to upgrade the connection to a websocket
611 one. This is a chance to serve http content,
612 for example, to send a script to the client
613 which will then open the websockets connection.
614 <tt><b>in</b></tt> points to the URI path requested and
615 <b>libwebsockets_serve_http_file</b> makes it very
616 simple to send back a file to the client.
617 Normally after sending the file you are done
618 with the http connection, since the rest of the
619 activity will come by websockets from the script
620 that was delivered by http, so you will want to
621 return 1; to close and free up the connection.
622 That's important because it uses a slot in the
623 total number of client connections allowed set
626 <h3>LWS_CALLBACK_HTTP_FILE_COMPLETION</h3>
628 a file requested to be send down
629 http link has completed.
631 <h3>LWS_CALLBACK_SERVER_WRITEABLE</h3>
634 <b>libwebsocket_callback_on_writable</b> on a connection, you will
635 get one of these callbacks coming when the connection socket
636 is able to accept another write packet without blocking.
637 If it already was able to take another packet without blocking,
638 you'll get this callback at the next call to the service loop
639 function. Notice that CLIENTs get LWS_CALLBACK_CLIENT_WRITEABLE
640 and servers get LWS_CALLBACK_SERVER_WRITEABLE.
642 <h3>LWS_CALLBACK_FILTER_NETWORK_CONNECTION</h3>
644 called when a client connects to
645 the server at network level; the connection is accepted but then
646 passed to this callback to decide whether to hang up immediately
647 or not, based on the client IP. <tt><b>user</b></tt> contains the connection
648 socket's descriptor. Return non-zero to terminate
649 the connection before sending or receiving anything.
650 Because this happens immediately after the network connection
651 from the client, there's no websocket protocol selected yet so
652 this callback is issued only to protocol 0.
654 <h3>LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION</h3>
656 called when the handshake has
657 been received and parsed from the client, but the response is
658 not sent yet. Return non-zero to disallow the connection.
659 <tt><b>user</b></tt> is a pointer to an array of struct lws_tokens, you can
660 use the header enums lws_token_indexes from libwebsockets.h
661 to check for and read the supported header presence and
662 content before deciding to allow the handshake to proceed or
663 to kill the connection.
665 <h3>LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS</h3>
668 including OpenSSL support, this callback allows your user code
669 to perform extra <b>SSL_CTX_load_verify_locations</b> or similar
670 calls to direct OpenSSL where to find certificates the client
671 can use to confirm the remote server identity. <tt><b>user</b></tt> is the
674 <h3>LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS</h3>
677 including OpenSSL support, this callback allows your user code
678 to load extra certifcates into the server which allow it to
679 verify the validity of certificates returned by clients. <tt><b>user</b></tt>
680 is the server's OpenSSL SSL_CTX*
682 <h3>LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION</h3>
685 libwebsockets context was created with the option
686 LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT, then this
687 callback is generated during OpenSSL verification of the cert
688 sent from the client. It is sent to protocol[0] callback as
689 no protocol has been negotiated on the connection yet.
690 Notice that the libwebsockets context and wsi are both NULL
691 during this callback. See
695 //www.openssl.org/docs/ssl/SSL_CTX_set_verify.html
696 to understand more detail about the OpenSSL callback that
697 generates this libwebsockets callback and the meanings of the
698 arguments passed. In this callback, <tt><b>user</b></tt> is the x509_ctx,
699 <tt><b>in</b></tt> is the ssl pointer and <tt><b>len</b></tt> is preverify_ok
700 Notice that this callback maintains libwebsocket return
701 conventions, return 0 to mean the cert is OK or 1 to fail it.
702 This also means that if you don't handle this callback then
703 the default callback action of returning 0 allows the client
706 <h3>LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER</h3>
708 this callback happens
709 when a client handshake is being compiled. <tt><b>user</b></tt> is NULL,
710 <tt><b>in</b></tt> is a char **, it's pointing to a char * which holds the
711 next location in the header buffer where you can add
712 headers, and <tt><b>len</b></tt> is the remaining space in the header buffer,
713 which is typically some hundreds of bytes. So, to add a canned
714 cookie, your handler code might look similar to:
716 char **p = (char **)in;
721 *p += sprintf(*p, "Cookie: a=b\x0d\x0a");
725 Notice if you add anything, you just have to take care about
726 the CRLF on the line you added. Obviously this callback is
727 optional, if you don't handle it everything is fine.
729 Notice the callback is coming to protocols[0] all the time,
730 because there is no specific protocol handshook yet.
732 <h3>LWS_CALLBACK_CONFIRM_EXTENSION_OKAY</h3>
734 When the server handshake code
735 sees that it does support a requested extension, before
736 accepting the extension by additing to the list sent back to
737 the client it gives this callback just to check that it's okay
738 to use that extension. It calls back to the requested protocol
739 and with <tt><b>in</b></tt> being the extension name, <tt><b>len</b></tt> is 0 and <tt><b>user</b></tt> is
740 valid. Note though at this time the ESTABLISHED callback hasn't
741 happened yet so if you initialize <tt><b>user</b></tt> content there, <tt><b>user</b></tt>
742 content during this callback might not be useful for anything.
743 Notice this callback comes to protocols[0].
745 <h3>LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED</h3>
748 connection is being prepared to start a handshake to a server,
749 each supported extension is checked with protocols[0] callback
750 with this reason, giving the user code a chance to suppress the
751 claim to support that extension by returning non-zero. If
752 unhandled, by default 0 will be returned and the extension
753 support included in the header to the server. Notice this
754 callback comes to protocols[0].
756 The next four reasons are optional and only need taking care of if you
757 will be integrating libwebsockets sockets into an external polling
760 <h3>LWS_CALLBACK_ADD_POLL_FD</h3>
762 libwebsocket deals with its <b>poll</b> loop
763 internally, but in the case you are integrating with another
764 server you will need to have libwebsocket sockets share a
765 polling array with the other server. This and the other
766 POLL_FD related callbacks let you put your specialized
767 poll array interface code in the callback for protocol 0, the
768 first protocol you support, usually the HTTP protocol in the
769 serving case. This callback happens when a socket needs to be
771 <h3>added to the polling loop</h3>
773 <tt><b>user</b></tt> contains the fd, and
774 <tt><b>len</b></tt> is the events bitmap (like, POLLIN). If you are using the
775 internal polling loop (the "service" callback), you can just
776 ignore these callbacks.
778 <h3>LWS_CALLBACK_DEL_POLL_FD</h3>
780 This callback happens when a socket descriptor
781 needs to be removed from an external polling array. <tt><b>user</b></tt> is
782 the socket desricptor. If you are using the internal polling
783 loop, you can just ignore it.
785 <h3>LWS_CALLBACK_SET_MODE_POLL_FD</h3>
787 This callback happens when libwebsockets
788 wants to modify the events for the socket descriptor in <tt><b>user</b></tt>.
789 The handler should OR <tt><b>len</b></tt> on to the events member of the pollfd
790 struct for this socket descriptor. If you are using the
791 internal polling loop, you can just ignore it.
793 <h3>LWS_CALLBACK_CLEAR_MODE_POLL_FD</h3>
795 This callback occurs when libwebsockets
796 wants to modify the events for the socket descriptor in <tt><b>user</b></tt>.
797 The handler should AND ~<tt><b>len</b></tt> on to the events member of the
798 pollfd struct for this socket descriptor. If you are using the
799 internal polling loop, you can just ignore it.
802 <h2>extension_callback - Hooks to allow extensions to operate</h2>
803 <i>LWS_EXTERN int</i>
804 <b>extension_callback</b>
805 (<i>struct libwebsocket_context *</i> <b>context</b>,
806 <i>struct libwebsocket_extension *</i> <b>ext</b>,
807 <i>struct libwebsocket *</i> <b>wsi</b>,
808 <i>enum libwebsocket_extension_callback_reasons</i> <b>reason</b>,
809 <i>void *</i> <b>user</b>,
810 <i>void *</i> <b>in</b>,
811 <i>size_t</i> <b>len</b>)
815 <dd>Websockets context
819 <dd>Opaque websocket instance pointer
821 <dd>The reason for the call
823 <dd>Pointer to per-session user data allocated by library
825 <dd>Pointer used for some callback reasons
827 <dd>Length set for some callback reasons
831 Each extension that is active on a particular connection receives
832 callbacks during the connection lifetime to allow the extension to
833 operate on websocket data and manage itself.
835 Libwebsockets takes care of allocating and freeing "user" memory for
836 each active extension on each connection. That is what is pointed to
837 by the <tt><b>user</b></tt> parameter.
839 <h3>LWS_EXT_CALLBACK_CONSTRUCT</h3>
841 called when the server has decided to
842 select this extension from the list provided by the client,
843 just before the server will send back the handshake accepting
844 the connection with this extension active. This gives the
845 extension a chance to initialize its connection context found
846 in <tt><b>user</b></tt>.
848 <h3>LWS_EXT_CALLBACK_CLIENT_CONSTRUCT</h3>
850 same as LWS_EXT_CALLBACK_CONSTRUCT
851 but called when client is instantiating this extension. Some
852 extensions will work the same on client and server side and then
853 you can just merge handlers for both CONSTRUCTS.
855 <h3>LWS_EXT_CALLBACK_DESTROY</h3>
857 called when the connection the extension was
858 being used on is about to be closed and deallocated. It's the
859 last chance for the extension to deallocate anything it has
860 allocated in the user data (pointed to by <tt><b>user</b></tt>) before the
861 user data is deleted. This same callback is used whether you
862 are in client or server instantiation context.
864 <h3>LWS_EXT_CALLBACK_PACKET_RX_PREPARSE</h3>
866 when this extension was active on
867 a connection, and a packet of data arrived at the connection,
868 it is passed to this callback to give the extension a chance to
869 change the data, eg, decompress it. <tt><b>user</b></tt> is pointing to the
870 extension's private connection context data, <tt><b>in</b></tt> is pointing
871 to an lws_tokens struct, it consists of a char * pointer called
872 token, and an int called token_len. At entry, these are
873 set to point to the received buffer and set to the content
874 length. If the extension will grow the content, it should use
875 a new buffer allocated in its private user context data and
876 set the pointed-to lws_tokens members to point to its buffer.
878 <h3>LWS_EXT_CALLBACK_PACKET_TX_PRESEND</h3>
880 this works the same way as
881 LWS_EXT_CALLBACK_PACKET_RX_PREPARSE above, except it gives the
882 extension a chance to change websocket data just before it will
883 be sent out. Using the same lws_token pointer scheme in <tt><b>in</b></tt>,
884 the extension can change the buffer and the length to be
885 transmitted how it likes. Again if it wants to grow the
886 buffer safely, it should copy the data into its own buffer and
887 set the lws_tokens token pointer to it.
890 <h2>struct libwebsocket_protocols - List of protocols and handlers server supports.</h2>
891 <b>struct libwebsocket_protocols</b> {<br>
892 <i>const char *</i> <b>name</b>;<br>
893 <i>callback_function *</i> <b>callback</b>;<br>
894 <i>size_t</i> <b>per_session_data_size</b>;<br>
895 <i>size_t</i> <b>rx_buffer_size</b>;<br>
896 <i>struct libwebsocket_context *</i> <b>owning_server</b>;<br>
897 <i>int</i> <b>protocol_index</b>;<br>
902 <dd>Protocol name that must match the one given in the client
903 Javascript new WebSocket(url, 'protocol') name
905 <dd>The service callback used for this protocol. It allows the
906 service action for an entire protocol to be encapsulated in
907 the protocol-specific callback
908 <dt><b>per_session_data_size</b>
909 <dd>Each new connection using this protocol gets
910 this much memory allocated on connection establishment and
911 freed on connection takedown. A pointer to this per-connection
912 allocation is passed into the callback in the 'user' parameter
913 <dt><b>rx_buffer_size</b>
914 <dd>if you want atomic frames delivered to the callback, you
915 should set this to the size of the biggest legal frame that
916 you support. If the frame size is exceeded, there is no
917 error, but the buffer will spill to the user callback when
918 full, which you can detect by using
919 <b>libwebsockets_remaining_packet_payload</b>. Notice that you
920 just talk about frame size here, the LWS_SEND_BUFFER_PRE_PADDING
921 and post-padding are automatically also allocated on top.
922 <dt><b>owning_server</b>
923 <dd>the server init call fills in this opaque pointer when
924 registering this protocol with the server.
925 <dt><b>protocol_index</b>
926 <dd>which protocol we are starting from zero
930 This structure represents one protocol supported by the server. An
931 array of these structures is passed to <b>libwebsocket_create_server</b>
932 allows as many protocols as you like to be handled by one server.
935 <h2>struct libwebsocket_extension - An extension we know how to cope with</h2>
936 <b>struct libwebsocket_extension</b> {<br>
937 <i>const char *</i> <b>name</b>;<br>
938 <i>extension_callback_function *</i> <b>callback</b>;<br>
939 <i>size_t</i> <b>per_session_data_size</b>;<br>
940 <i>void *</i> <b>per_context_private_data</b>;<br>
945 <dd>Formal extension name, eg, "deflate-stream"
948 <dt><b>per_session_data_size</b>
949 <dd>Libwebsockets will auto-malloc this much
950 memory for the use of the extension, a pointer
951 to it comes in the <tt><b>user</b></tt> callback parameter
952 <dt><b>per_context_private_data</b>
953 <dd>Optional storage for this extension that
954 is per-context, so it can track stuff across
955 all sessions, etc, if it wants
958 <h2>struct lws_context_creation_info - </h2>
959 <b>struct lws_context_creation_info</b> {<br>
960 <i>int</i> <b>port</b>;<br>
961 <i>const char *</i> <b>interface</b>;<br>
962 <i>struct libwebsocket_protocols *</i> <b>protocols</b>;<br>
963 <i>struct libwebsocket_extension *</i> <b>extensions</b>;<br>
964 <i>const char *</i> <b>ssl_cert_filepath</b>;<br>
965 <i>const char *</i> <b>ssl_private_key_filepath</b>;<br>
966 <i>const char *</i> <b>ssl_ca_filepath</b>;<br>
967 <i>int</i> <b>gid</b>;<br>
968 <i>int</i> <b>uid</b>;<br>
969 <i>unsigned int</i> <b>options</b>;<br>
970 <i>void *</i> <b>user</b>;<br>
971 <i>int</i> <b>ka_time</b>;<br>
972 <i>int</i> <b>ka_probes</b>;<br>
973 <i>int</i> <b>ka_interval</b>;<br>
978 <dd>Port to listen on... you can use 0 to suppress listening on
979 any port, that's what you want if you are not running a
980 websocket server at all but just using it as a client
982 <dd>NULL to bind the listen socket to all interfaces, or the
983 interface name, eg, "eth2"
985 <dd>Array of structures listing supported protocols and a protocol-
986 specific callback for each one. The list is ended with an
987 entry that has a NULL callback pointer.
988 It's not const because we write the owning_server member
989 <dt><b>extensions</b>
990 <dd>NULL or array of libwebsocket_extension structs listing the
991 extensions this context supports. If you configured with
992 --without-extensions, you should give NULL here.
993 <dt><b>ssl_cert_filepath</b>
994 <dd>If libwebsockets was compiled to use ssl, and you want
995 to listen using SSL, set to the filepath to fetch the
996 server cert from, otherwise NULL for unencrypted
997 <dt><b>ssl_private_key_filepath</b>
998 <dd>filepath to private key if wanting SSL mode,
1000 <dt><b>ssl_ca_filepath</b>
1001 <dd>CA certificate filepath or NULL
1003 <dd>group id to change to after setting listen socket, or -1.
1005 <dd>user id to change to after setting listen socket, or -1.
1007 <dd>0, or LWS_SERVER_OPTION_DEFEAT_CLIENT_MASK
1009 <dd>optional user pointer that can be recovered via the context
1010 pointer using libwebsocket_context_user
1012 <dd>0 for no keepalive, otherwise apply this keepalive timeout to
1013 all libwebsocket sockets, client or server
1014 <dt><b>ka_probes</b>
1015 <dd>if ka_time was nonzero, after the timeout expires how many
1016 times to try to get a response from the peer before giving up
1017 and killing the connection
1018 <dt><b>ka_interval</b>
1019 <dd>if ka_time was nonzero, how long to wait before each ka_probes