diff --git a/minimal-examples/README.md b/minimal-examples/README.md index e4fc7515f7f5b5642456bd90becaaefe0016b017..525ad1eaf5fcf15e98753b360a7aedec0ca34833 100644 --- a/minimal-examples/README.md +++ b/minimal-examples/README.md @@ -1,10 +1,11 @@ |name|demonstrates| ---|--- -http-server|Minimal examples providing an http server -ws-server|Minimal examples providing a ws server (and an http server) +client-server|Minimal examples providing client and server connections simultaneously http-client|Minimal examples providing an http client +http-server|Minimal examples providing an http server +raw|Minimal examples related to adopting raw file or socket descriptors into the event loop ws-client|Minimal examples providing a ws client -client-server|Minimal examples providing client and server connections simultaneously +ws-server|Minimal examples providing a ws server (and an http server) ## FAQ diff --git a/minimal-examples/client-server/minimal-ws-proxy/minimal-ws-proxy.c b/minimal-examples/client-server/minimal-ws-proxy/minimal-ws-proxy.c index 2227b7d311441827ac9b4173436d85bc0fa87da6..6ca0052b996f2652e7dfd3092213e4382e126862 100644 --- a/minimal-examples/client-server/minimal-ws-proxy/minimal-ws-proxy.c +++ b/minimal-examples/client-server/minimal-ws-proxy/minimal-ws-proxy.c @@ -70,8 +70,13 @@ int main(int argc, char **argv) info.mounts = &mount; info.protocols = protocols; - lws_set_log_level(LLL_ERR | LLL_WARN | LLL_NOTICE | LLL_USER - /* | LLL_INFO */ /* | LLL_DEBUG */, NULL); + lws_set_log_level(LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE + /* for LLL_ verbosity above NOTICE to be built into lws, + * lws must have been configured and built with + * -DCMAKE_BUILD_TYPE=DEBUG instead of =RELEASE */ + /* | LLL_INFO */ /* | LLL_PARSER */ /* | LLL_HEADER */ + /* | LLL_EXT */ /* | LLL_CLIENT */ /* | LLL_LATENCY */ + /* | LLL_DEBUG */, NULL); lwsl_user("LWS minimal ws proxy | visit http://localhost:7681\n"); diff --git a/minimal-examples/http-client/minimal-http-client/minimal-http-client.c b/minimal-examples/http-client/minimal-http-client/minimal-http-client.c index 8e9ba0a4b64e605d9ea7f3d3c2a6d9b2675b6a12..ad19c0fe61da8a98583b5db2a500a81047fda5f9 100644 --- a/minimal-examples/http-client/minimal-http-client/minimal-http-client.c +++ b/minimal-examples/http-client/minimal-http-client/minimal-http-client.c @@ -95,8 +95,14 @@ int main(int argc, char **argv) int n = 0; signal(SIGINT, sigint_handler); - lws_set_log_level(LLL_ERR | LLL_WARN | LLL_NOTICE | LLL_USER - /* | LLL_INFO */ /* | LLL_DEBUG */, NULL); + lws_set_log_level(LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE + /* for LLL_ verbosity above NOTICE to be built into lws, + * lws must have been configured and built with + * -DCMAKE_BUILD_TYPE=DEBUG instead of =RELEASE */ + /* | LLL_INFO */ /* | LLL_PARSER */ /* | LLL_HEADER */ + /* | LLL_EXT */ /* | LLL_CLIENT */ /* | LLL_LATENCY */ + /* | LLL_DEBUG */, NULL); + lwsl_user("LWS minimal http client\n"); memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ diff --git a/minimal-examples/http-server/README.md b/minimal-examples/http-server/README.md index 034e89d8bdb81d6d9f0aeb1eb86fd7e93aeccb0c..5c2fe2665a102e9d129b8e733006a7f76c5e3e28 100644 --- a/minimal-examples/http-server/README.md +++ b/minimal-examples/http-server/README.md @@ -1,8 +1,9 @@ |Example|Demonstrates| ---|--- -minimal-http-server|Serves a directory over http/1, custom 404 handler -minimal-http-server-tls|Serves a directory over http/1 or http/2 with TLS (SSL), custom 404 handler +minimal-http-server-dynamic|Serves both static and dynamically generated http content minimal-http-server-libuv|Same as minimal-http-server but libuv event loop minimal-http-server-multivhost|Same as minimal-http-server but three different vhosts minimal-http-server-smp|Multiple service threads -minimal-http-server-dynamic|Serves both static and dynamically generated http content +minimal-http-server-tls|Serves a directory over http/1 or http/2 with TLS (SSL), custom 404 handler +minimal-http-server|Serves a directory over http/1, custom 404 handler + diff --git a/minimal-examples/http-server/minimal-http-server-dynamic/minimal-http-server-dynamic.c b/minimal-examples/http-server/minimal-http-server-dynamic/minimal-http-server-dynamic.c index cf541f5ce4b88c836a79f8edff75767b583798cc..088fab833270d1768e1a1e34d65f61f0e3bfdfec 100644 --- a/minimal-examples/http-server/minimal-http-server-dynamic/minimal-http-server-dynamic.c +++ b/minimal-examples/http-server/minimal-http-server-dynamic/minimal-http-server-dynamic.c @@ -164,8 +164,13 @@ int main(int argc, char **argv) info.protocols = protocols; info.mounts = &mount; - lws_set_log_level(LLL_ERR | LLL_WARN | LLL_NOTICE | LLL_USER - /* | LLL_INFO */ /* | LLL_DEBUG */, NULL); + lws_set_log_level(LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE + /* for LLL_ verbosity above NOTICE to be built into lws, + * lws must have been configured and built with + * -DCMAKE_BUILD_TYPE=DEBUG instead of =RELEASE */ + /* | LLL_INFO */ /* | LLL_PARSER */ /* | LLL_HEADER */ + /* | LLL_EXT */ /* | LLL_CLIENT */ /* | LLL_LATENCY */ + /* | LLL_DEBUG */, NULL); lwsl_user("LWS minimal http server dynamic | visit http://localhost:7681\n"); diff --git a/minimal-examples/http-server/minimal-http-server-libuv/minimal-http-server.c b/minimal-examples/http-server/minimal-http-server-libuv/minimal-http-server.c index bb666f99639d27b7dc27d642184dda5932a2e8ee..81a2d1f1d2758a4c97129c1bbba81530cddff91e 100644 --- a/minimal-examples/http-server/minimal-http-server-libuv/minimal-http-server.c +++ b/minimal-examples/http-server/minimal-http-server-libuv/minimal-http-server.c @@ -65,8 +65,13 @@ int main(int argc, char **argv) info.error_document_404 = "/404.html"; info.options = LWS_SERVER_OPTION_LIBUV; - lws_set_log_level(LLL_ERR | LLL_WARN | LLL_NOTICE | LLL_USER - /* | LLL_INFO */ /* | LLL_DEBUG */, NULL); + lws_set_log_level(LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE + /* for LLL_ verbosity above NOTICE to be built into lws, + * lws must have been configured and built with + * -DCMAKE_BUILD_TYPE=DEBUG instead of =RELEASE */ + /* | LLL_INFO */ /* | LLL_PARSER */ /* | LLL_HEADER */ + /* | LLL_EXT */ /* | LLL_CLIENT */ /* | LLL_LATENCY */ + /* | LLL_DEBUG */, NULL); lwsl_user("LWS minimal http server libuv | visit http://localhost:7681\n"); diff --git a/minimal-examples/http-server/minimal-http-server-multivhost/minimal-http-server.c b/minimal-examples/http-server/minimal-http-server-multivhost/minimal-http-server.c index d73ac72930fe45da49baafea488006e50ea75f69..3507ede7c3d9b13a2317870f1c59295c96ae0e15 100644 --- a/minimal-examples/http-server/minimal-http-server-multivhost/minimal-http-server.c +++ b/minimal-examples/http-server/minimal-http-server-multivhost/minimal-http-server.c @@ -91,8 +91,13 @@ int main(int argc, char **argv) memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ info.options = LWS_SERVER_OPTION_EXPLICIT_VHOSTS; - lws_set_log_level(LLL_ERR | LLL_WARN | LLL_NOTICE | LLL_USER - /* | LLL_INFO */ /* | LLL_DEBUG */, NULL); + lws_set_log_level(LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE + /* for LLL_ verbosity above NOTICE to be built into lws, + * lws must have been configured and built with + * -DCMAKE_BUILD_TYPE=DEBUG instead of =RELEASE */ + /* | LLL_INFO */ /* | LLL_PARSER */ /* | LLL_HEADER */ + /* | LLL_EXT */ /* | LLL_CLIENT */ /* | LLL_LATENCY */ + /* | LLL_DEBUG */, NULL); lwsl_user("LWS minimal http server-multivhost | visit http://localhost:7681 / 7682\n"); diff --git a/minimal-examples/http-server/minimal-http-server-smp/minimal-http-server-smp.c b/minimal-examples/http-server/minimal-http-server-smp/minimal-http-server-smp.c index 417afb6f813e099f8e6f28e5fa0ba9df3a6ed863..d38c5d48ca7907b837a8ab1d839386c81782d26e 100644 --- a/minimal-examples/http-server/minimal-http-server-smp/minimal-http-server-smp.c +++ b/minimal-examples/http-server/minimal-http-server-smp/minimal-http-server-smp.c @@ -79,8 +79,13 @@ int main(int argc, char **argv) // info.max_http_header_pool = 10; info.count_threads = COUNT_THREADS; - lws_set_log_level(LLL_ERR | LLL_WARN | LLL_NOTICE | LLL_USER - /* | LLL_INFO */ /* | LLL_DEBUG */, NULL); + lws_set_log_level(LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE + /* for LLL_ verbosity above NOTICE to be built into lws, + * lws must have been configured and built with + * -DCMAKE_BUILD_TYPE=DEBUG instead of =RELEASE */ + /* | LLL_INFO */ /* | LLL_PARSER */ /* | LLL_HEADER */ + /* | LLL_EXT */ /* | LLL_CLIENT */ /* | LLL_LATENCY */ + /* | LLL_DEBUG */, NULL); lwsl_user("LWS minimal http server SMP | visit http://127.0.0.1:7681\n"); diff --git a/minimal-examples/http-server/minimal-http-server-tls/minimal-http-server-tls.c b/minimal-examples/http-server/minimal-http-server-tls/minimal-http-server-tls.c index 7afd0ffde278adf95369aedd42a8e5da86955586..c6a29565cc93aff73e5c4ab9d751e6182a212388 100644 --- a/minimal-examples/http-server/minimal-http-server-tls/minimal-http-server-tls.c +++ b/minimal-examples/http-server/minimal-http-server-tls/minimal-http-server-tls.c @@ -64,8 +64,13 @@ int main(int argc, char **argv) info.ssl_cert_filepath = "localhost-100y.cert"; info.ssl_private_key_filepath = "localhost-100y.key"; - lws_set_log_level(LLL_ERR | LLL_WARN | LLL_NOTICE | LLL_USER - /* | LLL_INFO */ /* | LLL_DEBUG */, NULL); + lws_set_log_level(LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE + /* for LLL_ verbosity above NOTICE to be built into lws, + * lws must have been configured and built with + * -DCMAKE_BUILD_TYPE=DEBUG instead of =RELEASE */ + /* | LLL_INFO */ /* | LLL_PARSER */ /* | LLL_HEADER */ + /* | LLL_EXT */ /* | LLL_CLIENT */ /* | LLL_LATENCY */ + /* | LLL_DEBUG */, NULL); lwsl_user("LWS minimal http server TLS | visit https://localhost:7681\n"); diff --git a/minimal-examples/http-server/minimal-http-server/minimal-http-server.c b/minimal-examples/http-server/minimal-http-server/minimal-http-server.c index e82cd3b333a46ea10f55b9da4c8580b465db2500..5ad28fd5111493dbdc7caaa343b27fd4d9782ad7 100644 --- a/minimal-examples/http-server/minimal-http-server/minimal-http-server.c +++ b/minimal-examples/http-server/minimal-http-server/minimal-http-server.c @@ -57,7 +57,12 @@ int main(int argc, char **argv) info.mounts = &mount; info.error_document_404 = "/404.html"; - lws_set_log_level(LLL_ERR | LLL_WARN | LLL_NOTICE | LLL_USER + lws_set_log_level(LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE + /* for LLL_ verbosity above NOTICE to be built into lws, + * lws must have been configured and built with + * -DCMAKE_BUILD_TYPE=DEBUG instead of =RELEASE */ + /* | LLL_INFO */ /* | LLL_PARSER */ /* | LLL_HEADER */ + /* | LLL_EXT */ /* | LLL_CLIENT */ /* | LLL_LATENCY */ /* | LLL_INFO */ /* | LLL_DEBUG */, NULL); lwsl_user("LWS minimal http server | visit http://localhost:7681\n"); diff --git a/minimal-examples/raw/README.md b/minimal-examples/raw/README.md new file mode 100644 index 0000000000000000000000000000000000000000..c076566e2a4075811ac3125c0b6a248df38d98c1 --- /dev/null +++ b/minimal-examples/raw/README.md @@ -0,0 +1,3 @@ +|name|demonstrates| +---|--- +minimal-raw-file|Shows how to adopt a file descriptor (device node, fifo, file, etc) into the lws event loop and handle events diff --git a/minimal-examples/raw/minimal-raw-file/CMakeLists.txt b/minimal-examples/raw/minimal-raw-file/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..dc0f8633b8e7129c7b51dce988898b0d6e2e64b5 --- /dev/null +++ b/minimal-examples/raw/minimal-raw-file/CMakeLists.txt @@ -0,0 +1,77 @@ +cmake_minimum_required(VERSION 2.8) +include(CheckCSourceCompiles) + +set(SAMP lws-minimal-raw-file) +set(SRCS minimal-raw-file.c) + +# If we are being built as part of lws, confirm current build config supports +# reqconfig, else skip building ourselves. +# +# If we are being built externally, confirm installed lws was configured to +# support reqconfig, else error out with a helpful message about the problem. +# +MACRO(require_lws_config reqconfig _val result) + + if (DEFINED ${reqconfig}) + if (${reqconfig}) + set (rq 1) + else() + set (rq 0) + endif() + else() + set(rq 0) + endif() + + if (${_val} EQUAL ${rq}) + set(SAME 1) + else() + set(SAME 0) + endif() + + if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME}) + if (${_val}) + message("${SAMP}: skipping as lws being built without ${reqconfig}") + else() + message("${SAMP}: skipping as lws built with ${reqconfig}") + endif() + set(${result} 0) + else() + if (LWS_WITH_MINIMAL_EXAMPLES) + set(MET ${SAME}) + else() + CHECK_C_SOURCE_COMPILES("#include <libwebsockets.h>\nint main(void) {\n#if defined(${reqconfig})\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" HAS_${reqconfig}) + if (NOT DEFINED HAS_${reqconfig} OR NOT HAS_${reqconfig}) + set(HAS_${reqconfig} 0) + else() + set(HAS_${reqconfig} 1) + endif() + if ((HAS_${reqconfig} AND ${_val}) OR (NOT HAS_${reqconfig} AND NOT ${_val})) + set(MET 1) + else() + set(MET 0) + endif() + endif() + if (NOT MET) + if (${_val}) + message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}") + else() + message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project") + endif() + endif() + + endif() +ENDMACRO() + +set(requirements 1) +require_lws_config(LWS_WITHOUT_SERVER 0 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets) + endif() +endif() \ No newline at end of file diff --git a/minimal-examples/raw/minimal-raw-file/README.md b/minimal-examples/raw/minimal-raw-file/README.md new file mode 100644 index 0000000000000000000000000000000000000000..3d18c9285e19680c8d853ef835ee397386729b65 --- /dev/null +++ b/minimal-examples/raw/minimal-raw-file/README.md @@ -0,0 +1,48 @@ +# lws minimal ws server + +This demonstrates adopting a file descriptor into the lws event +loop. The filepath is given as an argument to the example app, eg + +``` + $ ./lws-minimal-raw-file <file> +``` + +On a Linux system, some example files might be + + - /proc/self/fd/0 (stdin) + - /dev/ttyUSB0 (a USB <-> serial converter) + - /dev/input/event<n> (needs root... input device events) + +The example application opens the file in the protocol init +handler, and hexdumps data from the file to the lws log +as it becomes available. + +This isn't very useful standalone as shown here for clarity, but you can +freely combine raw file descriptor adoption with other lws server +and client features. + +Becuase raw file events have their own callback, the handlers can +be integrated in a single protocol that also handles http and ws +server and client callbacks without conflict. + +## build + +``` + $ cmake . && make +``` + +## usage + +``` + $ ./lws-minimal-raw-file /proc/self/fd/0 +[2018/03/22 10:48:53:9709] USER: LWS minimal raw file +[2018/03/22 10:48:53:9876] NOTICE: Creating Vhost 'default' port -2, 1 protocols, IPv6 off +[2018/03/22 10:48:55:0037] NOTICE: LWS_CALLBACK_RAW_ADOPT_FILE + +[2018/03/22 10:48:55:9370] NOTICE: LWS_CALLBACK_RAW_RX_FILE +[2018/03/22 10:48:55:9377] NOTICE: +[2018/03/22 10:48:55:9408] NOTICE: 0000: 0A . + +``` + +The example logs above show the result of typing the Enter key. diff --git a/minimal-examples/raw/minimal-raw-file/minimal-raw-file.c b/minimal-examples/raw/minimal-raw-file/minimal-raw-file.c new file mode 100644 index 0000000000000000000000000000000000000000..be3e74d0a0dae20dcb554098a1d315308a0fe2e6 --- /dev/null +++ b/minimal-examples/raw/minimal-raw-file/minimal-raw-file.c @@ -0,0 +1,152 @@ +/* + * lws-minimal-raw-file + * + * Copyright (C) 2018 Andy Green <andy@warmcat.com> + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * This demonstrates adopting a file descriptor into the lws event + * loop. + */ + +#include <libwebsockets.h> +#include <string.h> +#include <signal.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + +struct raw_vhd { + lws_sock_file_fd_type u; +}; + +static char filepath[256]; + +static int +callback_raw_test(struct lws *wsi, enum lws_callback_reasons reason, + void *user, void *in, size_t len) +{ + struct raw_vhd *vhd = (struct raw_vhd *)lws_protocol_vh_priv_get( + lws_get_vhost(wsi), lws_get_protocol(wsi)); + uint8_t buf[1024]; + int n; + + switch (reason) { + case LWS_CALLBACK_PROTOCOL_INIT: + vhd = lws_protocol_vh_priv_zalloc(lws_get_vhost(wsi), + lws_get_protocol(wsi), sizeof(struct raw_vhd)); + vhd->u.filefd = open(filepath, O_RDWR); + if (vhd->u.filefd == -1) { + lwsl_err("Unable to open %s\n", filepath); + + return 1; + } + if (!lws_adopt_descriptor_vhost(lws_get_vhost(wsi), + LWS_ADOPT_RAW_FILE_DESC, vhd->u, + "raw-test", NULL)) { + lwsl_err("Failed to adopt fifo descriptor\n"); + close(vhd->u.filefd); + vhd->u.filefd = -1; + + return 1; + } + break; + + case LWS_CALLBACK_PROTOCOL_DESTROY: + if (vhd->u.filefd != -1) + close(vhd->u.filefd); + break; + + /* callbacks related to raw file descriptor */ + + case LWS_CALLBACK_RAW_ADOPT_FILE: + lwsl_notice("LWS_CALLBACK_RAW_ADOPT_FILE\n"); + break; + + case LWS_CALLBACK_RAW_RX_FILE: + lwsl_notice("LWS_CALLBACK_RAW_RX_FILE\n"); + n = read(vhd->u.filefd, buf, sizeof(buf)); + if (n < 0) { + lwsl_err("Reading from %s failed\n", filepath); + + return 1; + } + lwsl_hexdump_level(LLL_NOTICE, buf, n); + break; + + case LWS_CALLBACK_RAW_CLOSE_FILE: + lwsl_notice("LWS_CALLBACK_RAW_CLOSE_FILE\n"); + break; + + case LWS_CALLBACK_RAW_WRITEABLE_FILE: + lwsl_notice("LWS_CALLBACK_RAW_WRITEABLE_FILE\n"); + /* + * you can call lws_callback_on_writable() on a raw file wsi as + * usual, and then write directly into the raw filefd here. + */ + break; + + default: + break; + } + + return 0; +} + +static struct lws_protocols protocols[] = { + { "raw-test", callback_raw_test, 0, 0 }, + { NULL, NULL, 0, 0 } /* terminator */ +}; + +static int interrupted; + +void sigint_handler(int sig) +{ + interrupted = 1; +} + +int main(int argc, char **argv) +{ + struct lws_context_creation_info info; + struct lws_context *context; + int n = 0; + + signal(SIGINT, sigint_handler); + + memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ + info.port = CONTEXT_PORT_NO_LISTEN_SERVER; /* no listen socket for demo */ + info.protocols = protocols; + + lws_set_log_level(LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE + /* for LLL_ verbosity above NOTICE to be built into lws, + * lws must have been configured and built with + * -DCMAKE_BUILD_TYPE=DEBUG instead of =RELEASE */ + /* | LLL_INFO */ /* | LLL_PARSER */ /* | LLL_HEADER */ + /* | LLL_EXT */ /* | LLL_CLIENT */ /* | LLL_LATENCY */ + /* | LLL_DEBUG */, NULL); + + lwsl_user("LWS minimal raw file\n"); + if (argc < 2) { + lwsl_user("Usage: %s <file to monitor> " + " eg, /dev/ttyUSB0 or /dev/input/event0 or " + "/proc/self/fd/0\n", argv[0]); + + return 1; + } + + lws_strncpy(filepath, argv[1], sizeof(filepath)); + + context = lws_create_context(&info); + if (!context) { + lwsl_err("lws init failed\n"); + return 1; + } + + while (n >= 0 && !interrupted) + n = lws_service(context, 1000); + + lws_context_destroy(context); + + return 0; +} diff --git a/minimal-examples/ws-client/minimal-ws-client-rx/minimal-ws-client.c b/minimal-examples/ws-client/minimal-ws-client-rx/minimal-ws-client.c index d4aee31dedcc4db1e4944c986538cfe4a93a6bb1..1ae557f4dba2d6f89cd112da3bcaa848704950c3 100644 --- a/minimal-examples/ws-client/minimal-ws-client-rx/minimal-ws-client.c +++ b/minimal-examples/ws-client/minimal-ws-client-rx/minimal-ws-client.c @@ -78,8 +78,14 @@ int main(int argc, char **argv) signal(SIGINT, sigint_handler); - lws_set_log_level(LLL_ERR | LLL_WARN | LLL_NOTICE | LLL_USER - /* | LLL_INFO */ /* | LLL_DEBUG */, NULL); + lws_set_log_level(LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE + /* for LLL_ verbosity above NOTICE to be built into lws, + * lws must have been configured and built with + * -DCMAKE_BUILD_TYPE=DEBUG instead of =RELEASE */ + /* | LLL_INFO */ /* | LLL_PARSER */ /* | LLL_HEADER */ + /* | LLL_EXT */ /* | LLL_CLIENT */ /* | LLL_LATENCY */ + /* | LLL_DEBUG */, NULL); + lwsl_user("LWS minimal ws client rx\n"); memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ diff --git a/minimal-examples/ws-client/minimal-ws-client-tx/minimal-ws-client.c b/minimal-examples/ws-client/minimal-ws-client-tx/minimal-ws-client.c index 4a925416415e14b90150c88eab089261987365c5..98a16bee02048d35ebea512ab3574c611e146f64 100644 --- a/minimal-examples/ws-client/minimal-ws-client-tx/minimal-ws-client.c +++ b/minimal-examples/ws-client/minimal-ws-client-tx/minimal-ws-client.c @@ -294,8 +294,14 @@ int main(int argc, char **argv) signal(SIGINT, sigint_handler); - lws_set_log_level(LLL_ERR | LLL_WARN | LLL_NOTICE | LLL_USER - /* | LLL_INFO */ /* | LLL_DEBUG */, NULL); + lws_set_log_level(LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE + /* for LLL_ verbosity above NOTICE to be built into lws, + * lws must have been configured and built with + * -DCMAKE_BUILD_TYPE=DEBUG instead of =RELEASE */ + /* | LLL_INFO */ /* | LLL_PARSER */ /* | LLL_HEADER */ + /* | LLL_EXT */ /* | LLL_CLIENT */ /* | LLL_LATENCY */ + /* | LLL_DEBUG */, NULL); + lwsl_user("LWS minimal ws client tx\n"); lwsl_user(" Run minimal-ws-broker and browse to that\n"); diff --git a/minimal-examples/ws-server/README.md b/minimal-examples/ws-server/README.md index 0112d62579ce643b6d29f5ff61ea3e54dc5193dd..8781b9d9c25bef109d527c50ee63c95bb1b1f953 100644 --- a/minimal-examples/ws-server/README.md +++ b/minimal-examples/ws-server/README.md @@ -1,8 +1,9 @@ |Example|Demonstrates| ---|--- -minimal-ws-server|Serves an index.html over http that opens a ws shared chat client in a browser -minimal-ws-server-pmd|Simple ws server with permessage-deflate support +minimal-ws-broker|Simple ws server with a publish / broker / subscribe architecture minimal-ws-server-pmd-bulk|Simple ws server showing how to pass bulk data with permessage-deflate +minimal-ws-server-pmd|Simple ws server with permessage-deflate support minimal-ws-server-ring|Like minimal-ws-server but holds the chat in a multi-tail ringbuffer minimal-ws-server-threads|Simple ws server where data is produced by different threads -minimal-ws-broker|Simple ws server with a publish / broker / subscribe architecture +minimal-ws-server|Serves an index.html over http that opens a ws shared chat client in a browser + diff --git a/minimal-examples/ws-server/minimal-ws-broker/minimal-ws-broker.c b/minimal-examples/ws-server/minimal-ws-broker/minimal-ws-broker.c index 481248ae1f063bfa725a565bb57612402c9745fa..18ac0ba6c1aaca3ad506db3cdba95c7946531cc0 100644 --- a/minimal-examples/ws-server/minimal-ws-broker/minimal-ws-broker.c +++ b/minimal-examples/ws-server/minimal-ws-broker/minimal-ws-broker.c @@ -67,8 +67,13 @@ int main(int argc, char **argv) info.mounts = &mount; info.protocols = protocols; - lws_set_log_level(LLL_ERR | LLL_WARN | LLL_NOTICE | LLL_USER - /* | LLL_INFO */ /* | LLL_DEBUG */, NULL); + lws_set_log_level(LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE + /* for LLL_ verbosity above NOTICE to be built into lws, + * lws must have been configured and built with + * -DCMAKE_BUILD_TYPE=DEBUG instead of =RELEASE */ + /* | LLL_INFO */ /* | LLL_PARSER */ /* | LLL_HEADER */ + /* | LLL_EXT */ /* | LLL_CLIENT */ /* | LLL_LATENCY */ + /* | LLL_DEBUG */, NULL); lwsl_user("LWS minimal ws broker | visit http://localhost:7681\n"); diff --git a/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/minimal-ws-server-pmd-bulk.c b/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/minimal-ws-server-pmd-bulk.c index 6a1b7150a6d323d9d69ae4e2fdbf8b37162d955c..29e0d7a2c3ad4a63918c53d33b376857766992ac 100644 --- a/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/minimal-ws-server-pmd-bulk.c +++ b/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/minimal-ws-server-pmd-bulk.c @@ -79,8 +79,13 @@ int main(int argc, char **argv) info.extensions = extensions; info.pt_serv_buf_size = 32 * 1024; - lws_set_log_level(LLL_ERR | LLL_WARN | LLL_NOTICE | LLL_USER - /* | LLL_INFO */ /* | LLL_DEBUG */, NULL); + lws_set_log_level(LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE + /* for LLL_ verbosity above NOTICE to be built into lws, + * lws must have been configured and built with + * -DCMAKE_BUILD_TYPE=DEBUG instead of =RELEASE */ + /* | LLL_INFO */ /* | LLL_PARSER */ /* | LLL_HEADER */ + /* | LLL_EXT */ /* | LLL_CLIENT */ /* | LLL_LATENCY */ + /* | LLL_DEBUG */, NULL); lwsl_user("LWS minimal ws server + permessage-deflate | visit http://localhost:7681\n"); diff --git a/minimal-examples/ws-server/minimal-ws-server-pmd/minimal-ws-server-pmd.c b/minimal-examples/ws-server/minimal-ws-server-pmd/minimal-ws-server-pmd.c index 1cd9b3814741bc1c55075fdfff8b48eba1705d73..a36343d1701081fd3f3092489d511093741bf941 100644 --- a/minimal-examples/ws-server/minimal-ws-server-pmd/minimal-ws-server-pmd.c +++ b/minimal-examples/ws-server/minimal-ws-server-pmd/minimal-ws-server-pmd.c @@ -78,8 +78,13 @@ int main(int argc, char **argv) info.protocols = protocols; info.extensions = extensions; - lws_set_log_level(LLL_ERR | LLL_WARN | LLL_NOTICE | LLL_USER - /* | LLL_INFO */ /* | LLL_DEBUG */, NULL); + lws_set_log_level(LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE + /* for LLL_ verbosity above NOTICE to be built into lws, + * lws must have been configured and built with + * -DCMAKE_BUILD_TYPE=DEBUG instead of =RELEASE */ + /* | LLL_INFO */ /* | LLL_PARSER */ /* | LLL_HEADER */ + /* | LLL_EXT */ /* | LLL_CLIENT */ /* | LLL_LATENCY */ + /* | LLL_DEBUG */, NULL); lwsl_user("LWS minimal ws server + permessage-deflate | visit http://localhost:7681\n"); diff --git a/minimal-examples/ws-server/minimal-ws-server-ring/minimal-ws-server.c b/minimal-examples/ws-server/minimal-ws-server-ring/minimal-ws-server.c index d5f255d3d9803df909f8a5f1abefb4a4a9106625..2762739b00c3682c26d73de32da699cb048b9713 100644 --- a/minimal-examples/ws-server/minimal-ws-server-ring/minimal-ws-server.c +++ b/minimal-examples/ws-server/minimal-ws-server-ring/minimal-ws-server.c @@ -67,8 +67,13 @@ int main(int argc, char **argv) info.mounts = &mount; info.protocols = protocols; - lws_set_log_level(LLL_ERR | LLL_WARN | LLL_NOTICE | LLL_USER - /* | LLL_INFO */ /* | LLL_DEBUG */, NULL); + lws_set_log_level(LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE + /* for LLL_ verbosity above NOTICE to be built into lws, + * lws must have been configured and built with + * -DCMAKE_BUILD_TYPE=DEBUG instead of =RELEASE */ + /* | LLL_INFO */ /* | LLL_PARSER */ /* | LLL_HEADER */ + /* | LLL_EXT */ /* | LLL_CLIENT */ /* | LLL_LATENCY */ + /* | LLL_DEBUG */, NULL); lwsl_user("LWS minimal ws server (lws_ring) | visit http://localhost:7681\n"); diff --git a/minimal-examples/ws-server/minimal-ws-server-threads/minimal-ws-server.c b/minimal-examples/ws-server/minimal-ws-server-threads/minimal-ws-server.c index c4f365744ab655ace9cda9994b3b675fb670bdf3..0da7e38624ab647497cfa512a89610331d8e48df 100644 --- a/minimal-examples/ws-server/minimal-ws-server-threads/minimal-ws-server.c +++ b/minimal-examples/ws-server/minimal-ws-server-threads/minimal-ws-server.c @@ -95,8 +95,13 @@ int main(int argc, char **argv) info.protocols = protocols; info.pvo = &pvo; /* per-vhost options */ - lws_set_log_level(LLL_ERR | LLL_WARN | LLL_NOTICE | LLL_USER - /* | LLL_INFO */ /* | LLL_DEBUG */, NULL); + lws_set_log_level(LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE + /* for LLL_ verbosity above NOTICE to be built into lws, + * lws must have been configured and built with + * -DCMAKE_BUILD_TYPE=DEBUG instead of =RELEASE */ + /* | LLL_INFO */ /* | LLL_PARSER */ /* | LLL_HEADER */ + /* | LLL_EXT */ /* | LLL_CLIENT */ /* | LLL_LATENCY */ + /* | LLL_DEBUG */, NULL); lwsl_user("LWS minimal ws server + threads | visit http://localhost:7681\n"); diff --git a/minimal-examples/ws-server/minimal-ws-server/minimal-ws-server.c b/minimal-examples/ws-server/minimal-ws-server/minimal-ws-server.c index d5397c7949f0385ff3807f438e6c767236eee445..d22a7d7c87df66a0be3e6e52f3ddedac1013329c 100644 --- a/minimal-examples/ws-server/minimal-ws-server/minimal-ws-server.c +++ b/minimal-examples/ws-server/minimal-ws-server/minimal-ws-server.c @@ -67,8 +67,13 @@ int main(int argc, char **argv) info.mounts = &mount; info.protocols = protocols; - lws_set_log_level(LLL_ERR | LLL_WARN | LLL_NOTICE | LLL_USER - /* | LLL_INFO */ /* | LLL_DEBUG */, NULL); + lws_set_log_level(LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE + /* for LLL_ verbosity above NOTICE to be built into lws, + * lws must have been configured and built with + * -DCMAKE_BUILD_TYPE=DEBUG instead of =RELEASE */ + /* | LLL_INFO */ /* | LLL_PARSER */ /* | LLL_HEADER */ + /* | LLL_EXT */ /* | LLL_CLIENT */ /* | LLL_LATENCY */ + /* | LLL_DEBUG */, NULL); lwsl_user("LWS minimal ws server | visit http://localhost:7681\n"); diff --git a/plugins/protocol_lws_raw_test.c b/plugins/protocol_lws_raw_test.c index 0f99141879a0ac5336867e4d64c595c1862598ff..699d9c428dead3bde09ef733121c400884d605a1 100644 --- a/plugins/protocol_lws_raw_test.c +++ b/plugins/protocol_lws_raw_test.c @@ -136,7 +136,8 @@ callback_raw_test(struct lws *wsi, enum lws_callback_reasons reason, } lwsl_notice("FIFO %s created\n", vhd->fifo_path); u.filefd = vhd->fifo; - if (!lws_adopt_descriptor_vhost(vhd->vhost, 0, u, + if (!lws_adopt_descriptor_vhost(vhd->vhost, + LWS_ADOPT_RAW_FILE_DESC, u, "protocol-lws-raw-test", NULL)) { lwsl_err("Failed to adopt fifo descriptor\n"); @@ -149,7 +150,7 @@ callback_raw_test(struct lws *wsi, enum lws_callback_reasons reason, case LWS_CALLBACK_PROTOCOL_DESTROY: if (!vhd) break; - if (vhd->fifo >- 0) { + if (vhd->fifo >= 0) { close(vhd->fifo); unlink(vhd->fifo_path); }