1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

minimal: minimal-raw-file

This commit is contained in:
Andy Green 2018-03-22 11:43:19 +08:00
parent a4161780df
commit b80cef6919
24 changed files with 410 additions and 43 deletions

View file

@ -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

View file

@ -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");

View file

@ -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 */

View file

@ -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

View file

@ -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");

View file

@ -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");

View file

@ -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");

View file

@ -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");

View file

@ -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");

View file

@ -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");

View file

@ -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

View file

@ -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()

View file

@ -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.

View file

@ -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;
}

View file

@ -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 */

View file

@ -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");

View file

@ -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

View file

@ -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");

View file

@ -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");

View file

@ -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");

View file

@ -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");

View file

@ -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");

View file

@ -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");

View file

@ -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);
}