diff --git a/changelog b/changelog index 87a6942cd..1883c8567 100644 --- a/changelog +++ b/changelog @@ -208,9 +208,17 @@ discover how many threads were actually allowed when the context was created. It's required to implement locking in the user code in the same way that libwebsockets-test-server-pthread does it, for the FD locking callbacks. -There is no knowledge or dependency in lws itself about pthreads. How the -locking is implemented is entirely up to the user code. +If LWS_MAX_SMP=1, then there is no code related to pthreads compiled in the +library. If more than 1, a small amount of pthread mutex code is built into +the library. +8) New API + +LWS_VISIBLE struct lws * +lws_adopt_socket(struct lws_context *context, lws_sockfd_type accept_fd) + +allows foreign sockets accepted by non-lws code to be adopted by lws as if they +had just been accepted by lws' own listen socket. User api changes ---------------- diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index 982516f0d..dcc24581c 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -1673,6 +1673,9 @@ lws_client_connect_extended(struct lws_context *clients, const char *address, LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT lws_client_connect_via_info(struct lws_client_connect_info * ccinfo); +LWS_VISIBLE LWS_EXTERN struct lws * +lws_adopt_socket(struct lws_context *context, lws_sockfd_type accept_fd); + LWS_VISIBLE LWS_EXTERN const char * LWS_WARN_UNUSED_RESULT lws_canonical_hostname(struct lws_context *context); diff --git a/lib/server.c b/lib/server.c index 319e637f0..564a2c472 100644 --- a/lib/server.c +++ b/lib/server.c @@ -702,9 +702,16 @@ lws_http_transaction_completed(struct lws *wsi) return 0; } -/* - * either returns new wsi bound to accept_fd, or closes accept_fd and - * returns NULL, having cleaned up any new wsi pieces +/** + * lws_adopt_socket() - adopt foreign socket as if listen socket accepted it + * @context: lws context + * @accept_fd: fd of already-accepted socket to adopt + * + * Either returns new wsi bound to accept_fd, or closes accept_fd and + * returns NULL, having cleaned up any new wsi pieces. + * + * LWS adopts the socket in http serving mode, it's ready to accept an upgrade + * to ws or just serve http. */ LWS_VISIBLE struct lws * diff --git a/libwebsockets-api-doc.html b/libwebsockets-api-doc.html index e6772fc18..423af55e4 100644 --- a/libwebsockets-api-doc.html +++ b/libwebsockets-api-doc.html @@ -1,122 +1,51 @@ -

lws_write - Apply protocol then write data to client

-int -lws_write -(struct lws * wsi, -unsigned char * buf, -size_t len, -enum lws_write_protocol wp) -

Arguments

-
-
wsi -
Websocket instance (available from user callback) -
buf -
The data to send. For data being sent on a websocket -connection (ie, not default http), this buffer MUST have -LWS_PRE bytes valid BEFORE the pointer. -This is so the protocol header data can be added in-situ. -
len -
Count of the data bytes in the payload starting from buf -
-

Description

-
-This function provides the way to issue data back to the client -for both http and websocket protocols. -

-In the case of sending using websocket protocol, be sure to allocate -valid storage before and after buf as explained above. This scheme -allows maximum efficiency of sending data and protocol in a single -packet while not burdening the user code with any protocol knowledge. -

-Return may be -1 for a fatal error needing connection close, or a -positive number reflecting the amount of bytes actually sent. This -can be less than the requested number of bytes due to OS memory -pressure at any given time. -

-
-

lws_http_transaction_completed - wait for new http transaction or close

-int -lws_http_transaction_completed -(struct lws * wsi) -

Arguments

-
-
wsi -
websocket connection -
-

Description

-
-Returns 1 if the HTTP connection must close now -Returns 0 and resets connection to wait for new HTTP header / -transaction if possible -
-
-

lws_serve_http_file - Send a file back to the client using http

-int -lws_serve_http_file -(struct lws * wsi, -const char * file, -const char * content_type, -const char * other_headers, -int other_headers_len) -

Arguments

-
-
wsi -
Websocket instance (available from user callback) -
file -
The file to issue over http -
content_type -
The http content type, eg, text/html -
other_headers -
NULL or pointer to header string -
other_headers_len -
length of the other headers if non-NULL -
-

Description

-
-This function is intended to be called from the callback in response -to http requests from the client. It allows the callback to issue -local files down the http link in a single step. -

-Returning <0 indicates error and the wsi should be closed. Returning ->0 indicates the file was completely sent and -lws_http_transaction_completed called on the wsi (and close if != 0) -==0 indicates the file transfer is started and needs more service later, -the wsi should be left alone. -

-
-

lws_return_http_status - Return simple http status

-int -lws_return_http_status -(struct lws * wsi, -unsigned int code, -const char * html_body) -

Arguments

-
-
wsi -
Websocket instance (available from user callback) -
code -
Status index, eg, 404 -
html_body -
User-readable HTML description < 1KB, or NULL -
-

Description

-
-Helper to report HTTP errors back to the client cleanly and -consistently -
-
-

lws_client_connect_info - Connect to another websocket server

+

lws_client_reset - retarget a connected wsi to start over with a new connection (ie, redirect) this only works if still in HTTP, ie, not upgraded yet

struct lws * -lws_client_connect_info +lws_client_reset +(struct lws * wsi, +int ssl, +const char * address, +int port, +const char * path, +const char * host) +

Arguments

+
+
+

wsi

+
+connection to reset +
+

address

+
+network address of the new server +
+

port

+
+port to connect to +
+

path

+
+uri path to connect to on the new server +
+

host

+
+host header to send to the new server +
+
+

lws_client_connect_via_info - Connect to another websocket server

+struct lws * +lws_client_connect_via_info (struct lws_client_connect_info * i)

Arguments

+
i +
pointer to lws_client_connect_info struct

Description

This function creates a connection to a remote server

-

lws_client_connect_extended - Connect to another websocket server DEPRECAATED use lws_client_connect_info

+

lws_client_connect_extended - Connect to another websocket server DEPRECATED use lws_client_connect_via_info

struct lws * lws_client_connect_extended (struct lws_context * context, @@ -161,206 +90,159 @@ protocol supported, or the specific protocol ordinal This function creates a connection to a remote server
-

lws_service_fd - Service polled socket with something waiting

-int -lws_service_fd +

lws_client_connect - Connect to another websocket server DEPRECATED use lws_client_connect_via_info

+struct lws * +lws_client_connect (struct lws_context * context, -struct lws_pollfd * pollfd) +const char * address, +int port, +int ssl_connection, +const char * path, +const char * host, +const char * origin, +const char * protocol, +int ietf_version_or_minus_one)

Arguments

context
Websocket context -
pollfd -
The pollfd entry describing the socket fd and which events -happened. +
address +
Remote server address, eg, "myserver.com" +
port +
Port to connect to on the remote server, eg, 80 +
ssl_connection +
0 = ws://, 1 = wss:// encrypted, 2 = wss:// allow self +signed certs +
path +
Websocket path on server +
host +
Hostname on server +
origin +
Socket origin name +
protocol +
Comma-separated list of protocols being asked for from +the server, or just one. The server will pick the one it +likes best. If you don't want to specify a protocol, which is +legal, use NULL here. +
ietf_version_or_minus_one +
-1 to ask to connect using the default, latest +protocol supported, or the specific protocol ordinal

Description

-This function takes a pollfd that has POLLIN or POLLOUT activity and -services it according to the state of the associated -struct lws. -

-The one call deals with all "service" that might happen on a socket -including listen accepts, http files as well as websocket protocol. -

-If a pollfd says it has something, you can just pass it to -lws_service_fd whether it is a socket handled by lws or not. -If it sees it is a lws socket, the traffic will be handled and -pollfd->revents will be zeroed now. -

-If the socket is foreign to lws, it leaves revents alone. So you can -see if you should service yourself by checking the pollfd revents -after letting lws try to service it. +This function creates a connection to a remote server


-

lws_service - Service any pending websocket activity

-int -lws_service -(struct lws_context * context, -int timeout_ms) +

lws_get_library_version -

+const char * +lws_get_library_version +( void) +

Arguments

+
+
void +
no arguments +
+

Description

+
+

+returns a const char * to a string like "1.1 178d78c" +representing the library version followed by the git head hash it +was built from +

+
+

lws_create_context - Create the websocket handler

+struct lws_context * +lws_create_context +(struct lws_context_creation_info * info) +

Arguments

+
+
info +
pointer to struct with parameters +
+

Description

+
+This function creates the listening socket (if serving) and takes care +of all initialization in one step. +

+After initialization, it returns a struct lws_context * that +represents this server. After calling, user code needs to take care +of calling lws_service with the context pointer to get the +server's sockets serviced. This must be done in the same process +context as the initialization call. +

+The protocol callback functions are called for a handful of events +including http requests coming in, websocket connections becoming +established, and data arriving; it's also called periodically to allow +async transmission. +

+HTTP requests are sent always to the FIRST protocol in protocol, since +at that time websocket protocol has not been negotiated. Other +protocols after the first one never see any HTTP callack activity. +

+The server created is a simple http server by default; part of the +websocket standard is upgrading this http connection to a websocket one. +

+This allows the same server to provide files like scripts and favicon / +images or whatever over http and dynamic data over websockets all in +one place; they're all handled in the user callback. +

+
+

lws_context_destroy - Destroy the websocket context

+void +lws_context_destroy +(struct lws_context * context)

Arguments

context
Websocket context -
timeout_ms -
Timeout for poll; 0 means return immediately if nothing needed -service otherwise block and service immediately, returning -after the timeout if nothing needed service.

Description

-This function deals with any pending websocket traffic, for three -kinds of event. It handles these events on both server and client -types of connection the same. -

-1) Accept new connections to our context's server -

-2) Call the receive callback for incoming frame data received by -server or client connections. -

-You need to call this service function periodically to all the above -functions to happen; if your application is single-threaded you can -just call it in your main event loop. -

-Alternatively you can fork a new process that asynchronously handles -calling this service in a loop. In that case you are happy if this -call blocks your thread until it needs to take care of something and -would call it with a large nonzero timeout. Your loop then takes no -CPU while there is nothing happening. -

-If you are calling it in a single-threaded app, you don't want it to -wait around blocking other things in your loop from happening, so you -would call it with a timeout_ms of 0, so it returns immediately if -nothing is pending, or as soon as it services whatever was pending. +This function closes any active connections and then frees the +context. After calling this, any further use of the context is +undefined.


-

lws_hdr_fragment_length -

+

lws_return_http_status - Return simple http status

int -lws_hdr_fragment_length +lws_return_http_status (struct lws * wsi, -enum lws_token_indexes h, -int frag_idx) -

Arguments

-
-
wsi -
websocket connection -
h -
which header index we are interested in -
frag_idx -
which fragment of h we want to get the length of -
-

Description

-
-The returned length does not include the space for a -terminating '\0' -
-
-

lws_hdr_total_length -

-int -lws_hdr_total_length -(struct lws * wsi, -enum lws_token_indexes h) -

Arguments

-
-
wsi -
websocket connection -
h -
which header index we are interested in -
-

Description

-
-The returned length does not include the space for a -terminating '\0' -
-
-

lws_hdr_copy_fragment -

-int -lws_hdr_copy_fragment -(struct lws * wsi, -char * dst, -int len, -enum lws_token_indexes h, -int frag_idx) -

Arguments

-
-
wsi -
websocket connection -
dst -
destination buffer -
len -
length of destination buffer -
h -
which header index we are interested in -
-

Description

-
-The buffer length len must include space for an additional -terminating '\0', or it will fail returning -1. -If the requested fragment index is not present, it fails -returning -1. -
-
-

lws_hdr_copy -

-int -lws_hdr_copy -(struct lws * wsi, -char * dst, -int len, -enum lws_token_indexes h) -

Arguments

-
-
wsi -
websocket connection -
dst -
destination buffer -
len -
length of destination buffer -
h -
which header index we are interested in -
-

Description

-
-The buffer length len must include space for an additional -terminating '\0', or it will fail returning -1. -
-
-

lws_frame_is_binary -

-int -lws_frame_is_binary -(struct lws * wsi) -

Arguments

-
-
wsi -
the connection we are inquiring about -
-

Description

-
-This is intended to be called from the LWS_CALLBACK_RECEIVE callback if -it's interested to see if the frame it's dealing with was sent in binary -mode. -
-
-

lws_remaining_packet_payload - Bytes to come before "overall" rx packet is complete

-size_t -lws_remaining_packet_payload -(struct lws * wsi) +unsigned int code, +const char * html_body)

Arguments

wsi
Websocket instance (available from user callback) +
code +
Status index, eg, 404 +
html_body +
User-readable HTML description < 1KB, or NULL +
+

Description

+
+Helper to report HTTP errors back to the client cleanly and +consistently +
+
+

lws_set_timeout - marks the wsi as subject to a timeout

+void +lws_set_timeout +(struct lws * wsi, +enum pending_timeout reason, +int secs) +

Arguments

+
+
wsi +
Websocket connection instance +
reason +
timeout reason +
secs +
how many seconds

Description

-This function is intended to be called from the callback if the -user code is interested in "complete packets" from the client. -libwebsockets just passes through payload as it comes and issues a buffer -additionally when it hits a built-in limit. The LWS_CALLBACK_RECEIVE -callback handler can use this API to find out if the buffer it has just -been given is the last piece of a "complete packet" from the client -- -when that is the case lws_remaining_packet_payload will return -0.

-Many protocols won't care becuse their packets are always small. +You will not need this unless you are doing something special


lws_get_peer_addresses - Get client address information

@@ -426,27 +308,6 @@ using globals statics in the user code.
Callback reason index
-

lws_set_timeout - marks the wsi as subject to a timeout

-void -lws_set_timeout -(struct lws * wsi, -enum pending_timeout reason, -int secs) -

Arguments

-
-
wsi -
Websocket connection instance -
reason -
timeout reason -
secs -
how many seconds -
-

Description

-
-

-You will not need this unless you are doing something special -

-

lws_get_socket_fd - returns the socket file descriptor

int lws_get_socket_fd @@ -615,63 +476,35 @@ This is never set at the start of a writeable callback, but any write may set it.
-

lws_get_library_version -

-const char * -lws_get_library_version -( void) +

lws_parse_uri -

+LWS_EXTERN int +lws_parse_uri +(char * p, +const char ** prot, +const char ** ads, +int * port, +const char ** path)

Arguments

-
void -
no arguments +
p +
incoming uri string.. will get written to +
prot +
result pointer for protocol part (https://) +
ads +
result pointer for address part +
port +
result pointer for port part +
path +
result pointer for path part

Description

-

-returns a const char * to a string like "1.1 178d78c" -representing the library version followed by the git head hash it -was built from +Notice it does so by dropping '\0' into input string


-

lws_create_context - Create the websocket handler

-struct lws_context * -lws_create_context -(struct lws_context_creation_info * info) -

Arguments

-
-
info -
pointer to struct with parameters -
-

Description

-
-This function creates the listening socket (if serving) and takes care -of all initialization in one step. -

-After initialization, it returns a struct lws_context * that -represents this server. After calling, user code needs to take care -of calling lws_service with the context pointer to get the -server's sockets serviced. This must be done in the same process -context as the initialization call. -

-The protocol callback functions are called for a handful of events -including http requests coming in, websocket connections becoming -established, and data arriving; it's also called periodically to allow -async transmission. -

-HTTP requests are sent always to the FIRST protocol in protocol, since -at that time websocket protocol has not been negotiated. Other -protocols after the first one never see any HTTP callack activity. -

-The server created is a simple http server by default; part of the -websocket standard is upgrading this http connection to a websocket one. -

-This allows the same server to provide files like scripts and favicon / -images or whatever over http and dynamic data over websockets all in -one place; they're all handled in the user callback. -

-
-

lws_context_destroy - Destroy the websocket context

+

lws_cancel_service - Cancel servicing of pending websocket activity

void -lws_context_destroy +lws_cancel_service (struct lws_context * context)

Arguments

@@ -680,9 +513,220 @@ one place; they're all handled in the user callback.

Description

-This function closes any active connections and then frees the -context. After calling this, any further use of the context is -undefined. +This function let a call to lws_service waiting for a timeout +immediately return. +

+There is no poll in MBED3, he will fire callbacks when he feels like +it. +

+
+

lws_cancel_service_pt - Cancel servicing of pending socket activity on one thread

+void +lws_cancel_service_pt +(struct lws * wsi) +

Arguments

+
+
wsi +
Cancel service on the thread this wsi is serviced by +
+

Description

+
+This function let a call to lws_service waiting for a timeout +immediately return. +
+
+

lws_cancel_service - Cancel ALL servicing of pending socket activity

+void +lws_cancel_service +(struct lws_context * context) +

Arguments

+
+
context +
Websocket context +
+

Description

+
+This function let a call to lws_service waiting for a timeout +immediately return. +
+
+

lws_cancel_service - Cancel servicing of pending websocket activity

+void +lws_cancel_service +(struct lws_context * context) +

Arguments

+
+
context +
Websocket context +
+

Description

+
+This function let a call to lws_service waiting for a timeout +immediately return. +
+
+

lws_write - Apply protocol then write data to client

+int +lws_write +(struct lws * wsi, +unsigned char * buf, +size_t len, +enum lws_write_protocol wp) +

Arguments

+
+
wsi +
Websocket instance (available from user callback) +
buf +
The data to send. For data being sent on a websocket +connection (ie, not default http), this buffer MUST have +LWS_PRE bytes valid BEFORE the pointer. +This is so the protocol header data can be added in-situ. +
len +
Count of the data bytes in the payload starting from buf +
+

Description

+
+This function provides the way to issue data back to the client +for both http and websocket protocols. +

+In the case of sending using websocket protocol, be sure to allocate +valid storage before and after buf as explained above. This scheme +allows maximum efficiency of sending data and protocol in a single +packet while not burdening the user code with any protocol knowledge. +

+Return may be -1 for a fatal error needing connection close, or a +positive number reflecting the amount of bytes actually sent. This +can be less than the requested number of bytes due to OS memory +pressure at any given time. +

+
+

lws_hdr_fragment_length -

+int +lws_hdr_fragment_length +(struct lws * wsi, +enum lws_token_indexes h, +int frag_idx) +

Arguments

+
+
wsi +
websocket connection +
h +
which header index we are interested in +
frag_idx +
which fragment of h we want to get the length of +
+

Description

+
+The returned length does not include the space for a +terminating '\0' +
+
+

lws_hdr_total_length -

+int +lws_hdr_total_length +(struct lws * wsi, +enum lws_token_indexes h) +

Arguments

+
+
wsi +
websocket connection +
h +
which header index we are interested in +
+

Description

+
+The returned length does not include the space for a +terminating '\0' +
+
+

lws_hdr_copy_fragment -

+int +lws_hdr_copy_fragment +(struct lws * wsi, +char * dst, +int len, +enum lws_token_indexes h, +int frag_idx) +

Arguments

+
+
wsi +
websocket connection +
dst +
destination buffer +
len +
length of destination buffer +
h +
which header index we are interested in +
+

Description

+
+The buffer length len must include space for an additional +terminating '\0', or it will fail returning -1. +If the requested fragment index is not present, it fails +returning -1. +
+
+

lws_hdr_copy -

+int +lws_hdr_copy +(struct lws * wsi, +char * dst, +int len, +enum lws_token_indexes h) +

Arguments

+
+
wsi +
websocket connection +
dst +
destination buffer +
len +
length of destination buffer +
h +
which header index we are interested in +
+

Description

+
+The buffer length len must include space for an additional +terminating '\0', or it will fail returning -1. +
+
+

lws_frame_is_binary -

+int +lws_frame_is_binary +(struct lws * wsi) +

Arguments

+
+
wsi +
the connection we are inquiring about +
+

Description

+
+This is intended to be called from the LWS_CALLBACK_RECEIVE callback if +it's interested to see if the frame it's dealing with was sent in binary +mode. +
+
+

lws_remaining_packet_payload - Bytes to come before "overall" rx packet is complete

+size_t +lws_remaining_packet_payload +(struct lws * wsi) +

Arguments

+
+
wsi +
Websocket instance (available from user callback) +
+

Description

+
+This function is intended to be called from the callback if the +user code is interested in "complete packets" from the client. +libwebsockets just passes through payload as it comes and issues a buffer +additionally when it hits a built-in limit. The LWS_CALLBACK_RECEIVE +callback handler can use this API to find out if the buffer it has just +been given is the last piece of a "complete packet" from the client -- +when that is the case lws_remaining_packet_payload will return +0. +

+Many protocols won't care becuse their packets are always small.


lws_callback_on_writable - Request a callback when this socket becomes able to be written to without blocking

@@ -708,52 +752,149 @@ undefined.
Protocol whose connections will get callbacks
-

lws_cancel_service - Cancel servicing of pending websocket activity

-void -lws_cancel_service -(struct lws_context * context) +

lws_http_transaction_completed - wait for new http transaction or close

+int LWS_WARN_UNUSED_RESULT +lws_http_transaction_completed +(struct lws * wsi)

Arguments

-
context -
Websocket context +
wsi +
websocket connection

Description

-This function let a call to lws_service waiting for a timeout -immediately return. +Returns 1 if the HTTP connection must close now +Returns 0 and resets connection to wait for new HTTP header / +transaction if possible

-

lws_cancel_service - Cancel servicing of pending websocket activity

-void -lws_cancel_service -(struct lws_context * context) +

lws_adopt_socket - adopt foreign socket as if listen socket accepted it

+struct lws * +lws_adopt_socket +(struct lws_context * context, +lws_sockfd_type accept_fd)

Arguments

context -
Websocket context +
lws context +
accept_fd +
fd of already-accepted socket to adopt

Description

-This function let a call to lws_service waiting for a timeout -immediately return. -
-
-

lws_cancel_service - Cancel servicing of pending websocket activity

-void -lws_cancel_service -(struct lws_context * context) -

Arguments

-
-
context -
Websocket context -
-

Description

-
-This function let a call to lws_service waiting for a timeout -immediately return. +Either returns new wsi bound to accept_fd, or closes accept_fd and +returns NULL, having cleaned up any new wsi pieces.

-There is no poll in MBED3, he will fire callbacks when he feels like -it. +LWS adopts the socket in http serving mode, it's ready to accept an upgrade +to ws or just serve http. +

+
+

lws_serve_http_file - Send a file back to the client using http

+int +lws_serve_http_file +(struct lws * wsi, +const char * file, +const char * content_type, +const char * other_headers, +int other_headers_len) +

Arguments

+
+
wsi +
Websocket instance (available from user callback) +
file +
The file to issue over http +
content_type +
The http content type, eg, text/html +
other_headers +
NULL or pointer to header string +
other_headers_len +
length of the other headers if non-NULL +
+

Description

+
+This function is intended to be called from the callback in response +to http requests from the client. It allows the callback to issue +local files down the http link in a single step. +

+Returning <0 indicates error and the wsi should be closed. Returning +>0 indicates the file was completely sent and +lws_http_transaction_completed called on the wsi (and close if != 0) +==0 indicates the file transfer is started and needs more service later, +the wsi should be left alone. +

+
+

lws_service_fd_tsi - Service polled socket with something waiting

+int +lws_service_fd_tsi +(struct lws_context * context, +struct lws_pollfd * pollfd, +int tsi) +

Arguments

+
+
context +
Websocket context +
pollfd +
The pollfd entry describing the socket fd and which events +happened. +
+

Description

+
+This function takes a pollfd that has POLLIN or POLLOUT activity and +services it according to the state of the associated +struct lws. +

+The one call deals with all "service" that might happen on a socket +including listen accepts, http files as well as websocket protocol. +

+If a pollfd says it has something, you can just pass it to +lws_service_fd whether it is a socket handled by lws or not. +If it sees it is a lws socket, the traffic will be handled and +pollfd->revents will be zeroed now. +

+If the socket is foreign to lws, it leaves revents alone. So you can +see if you should service yourself by checking the pollfd revents +after letting lws try to service it. +

+
+

lws_service - Service any pending websocket activity

+int +lws_service +(struct lws_context * context, +int timeout_ms) +

Arguments

+
+
context +
Websocket context +
timeout_ms +
Timeout for poll; 0 means return immediately if nothing needed +service otherwise block and service immediately, returning +after the timeout if nothing needed service. +
+

Description

+
+This function deals with any pending websocket traffic, for three +kinds of event. It handles these events on both server and client +types of connection the same. +

+1) Accept new connections to our context's server +

+2) Call the receive callback for incoming frame data received by +server or client connections. +

+You need to call this service function periodically to all the above +functions to happen; if your application is single-threaded you can +just call it in your main event loop. +

+Alternatively you can fork a new process that asynchronously handles +calling this service in a loop. In that case you are happy if this +call blocks your thread until it needs to take care of something and +would call it with a large nonzero timeout. Your loop then takes no +CPU while there is nothing happening. +

+If you are calling it in a single-threaded app, you don't want it to +wait around blocking other things in your loop from happening, so you +would call it with a timeout_ms of 0, so it returns immediately if +nothing is pending, or as soon as it services whatever was pending.


struct lws_plat_file_ops - Platform-specific file operations

@@ -1373,6 +1514,8 @@ header. #endif
    short max_http_header_data;
    short max_http_header_pool;
+    unsigned int count_threads;
+    unsigned int fd_limit_per_thread;
};

Members

@@ -1457,6 +1600,52 @@ can be processed simultaneously (the corresponding memory is allocated for the lifetime of the context). If the pool is busy new incoming connections must wait for accept until one becomes free. +
count_threads +
how many contexts to create in an array, 0 = 1 +
fd_limit_per_thread +
nonzero means restrict each service thread to this +many fds, 0 means the default which is divide the process fd +limit by the number of threads. +
+
+

struct lws_client_connect_info - parameters to connect with when using lws_client_connect_via_info()

+struct lws_client_connect_info {
+    struct lws_context * context;
+    const char * address;
+    int port;
+    int ssl_connection;
+    const char * path;
+    const char * host;
+    const char * origin;
+    const char * protocol;
+    int ietf_version_or_minus_one;
+    void * userdata;
+    const struct lws_extension * client_exts;
+};
+

Members

+
+
context +
lws context to create connection in +
address +
remote address to connect to +
port +
remote port to connect to +
ssl_connection +
nonzero for ssl +
path +
uri path +
host +
content of host header +
origin +
content of origin header +
protocol +
list of ws protocols +
ietf_version_or_minus_one +
currently leave at 0 or -1 +
userdata +
if non-NULL, use this as wsi user_data instead of malloc it +
client_exts +
array of extensions that may be used on connection

lws_close_reason - Set reason and aux data to send with Close packet If you are going to return nonzero from the callback requesting the connection to close, you can optionally call this to set the reason the peer will be told if possible.