diff --git a/minimal-examples/README.md b/minimal-examples/README.md index e4fc7515..525ad1ea 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) -http-client|Minimal examples providing an http client -ws-client|Minimal examples providing a ws client 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 +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 2227b7d3..6ca0052b 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 8e9ba0a4..ad19c0fe 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 034e89d8..5c2fe266 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 cf541f5c..088fab83 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 bb666f99..81a2d1f1 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 d73ac729..3507ede7 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 417afb6f..d38c5d48 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 7afd0ffd..c6a29565 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 e82cd3b3..5ad28fd5 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 00000000..c076566e --- /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 00000000..dc0f8633 --- /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 \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 00000000..3d18c928 --- /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 +``` + +On a Linux system, some example files might be + + - /proc/self/fd/0 (stdin) + - /dev/ttyUSB0 (a USB <-> serial converter) + - /dev/input/event (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 00000000..be3e74d0 --- /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 + * + * 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 +#include +#include +#include +#include +#include + +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 " + " 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 d4aee31d..1ae557f4 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 4a925416..98a16bee 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 0112d625..8781b9d9 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 481248ae..18ac0ba6 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 6a1b7150..29e0d7a2 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 1cd9b381..a36343d1 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 d5f255d3..2762739b 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 c4f36574..0da7e386 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 d5397c79..d22a7d7c 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 0f991418..699d9c42 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); }