diff --git a/doc/webfuse.md b/doc/webfuse.md index a23589c..cc5f72e 100644 --- a/doc/webfuse.md +++ b/doc/webfuse.md @@ -17,6 +17,7 @@ filesystem via fuse and exposes it's API via websockets. | --wf-key | path | - | Optional. Specify the file path of the server's private key | | --wf- authenticator | path | - | Optional. Specify the file path of the authenticator executable | | --wf-auth-header | name | - | Optional. Specify the name of the HTTP header used for authentication | +| --wf-timeout | timeout | 10 | Optional. Specify the communication timeout. | ## Fuse options diff --git a/src/webfuse/webfuse.cpp b/src/webfuse/webfuse.cpp index 742fea6..37916e0 100644 --- a/src/webfuse/webfuse.cpp +++ b/src/webfuse/webfuse.cpp @@ -36,6 +36,7 @@ WEBFUSE options: --wf-key PATH path of the server's private key (optional) --wf-authenticator PATH path of authenticatior app (optional) --wf-auth-header NAME name of the authentication header (optional) + --wf-timeout TIMEOUT communication timeout in seconds (default: 10) )"; } break; diff --git a/src/webfuse/ws/config.cpp b/src/webfuse/ws/config.cpp index df2b737..e8f0120 100644 --- a/src/webfuse/ws/config.cpp +++ b/src/webfuse/ws/config.cpp @@ -10,6 +10,7 @@ namespace constexpr int const default_port = 8081; constexpr char const default_vhost_name[] = "localhost"; +constexpr uint64_t const default_timeout_secs = 10; void verify(webfuse::ws_config & config) { @@ -46,6 +47,7 @@ bool get_arg(webfuse::ws_config & config, webfuse::commandline_reader& reader, s namespace webfuse { +// NOLINTNEXTLINE ws_config::ws_config(int argc, char * argv[]) : exit_code(EXIT_SUCCESS) , args(argv[0], argc) @@ -53,6 +55,7 @@ ws_config::ws_config(int argc, char * argv[]) , port(default_port) , vhost_name(default_vhost_name) , use_tls(false) +, timeout_secs(default_timeout_secs) { commandline_reader reader(argc, argv); @@ -101,6 +104,14 @@ ws_config::ws_config(int argc, char * argv[]) [](auto c) {return std::tolower(c); }); } } + else if (arg == "--wf-timeout") + { + std::string timeout_str; + if (get_arg(*this, reader, timeout_str, "missing TIMEOUT")) + { + timeout_secs = static_cast(std::stoi(timeout_str)); + } + } else { args.push(arg.c_str()); diff --git a/src/webfuse/ws/config.hpp b/src/webfuse/ws/config.hpp index f884a5c..53b2616 100644 --- a/src/webfuse/ws/config.hpp +++ b/src/webfuse/ws/config.hpp @@ -33,6 +33,8 @@ public: std::string authenticator; std::string auth_header; + + uint64_t timeout_secs; }; } diff --git a/src/webfuse/ws/server.cpp b/src/webfuse/ws/server.cpp index 50ba599..731ae77 100644 --- a/src/webfuse/ws/server.cpp +++ b/src/webfuse/ws/server.cpp @@ -19,13 +19,6 @@ #include -namespace -{ - -constexpr int64_t const timeout_secs = 10; - -} - extern "C" { @@ -79,6 +72,7 @@ public: detail(ws_config const & config) : shutdown_requested(false) , data(config.authenticator, config.auth_header) + , timeout_secs(config.timeout_secs) { lws_set_log_level(0, nullptr); @@ -131,6 +125,7 @@ public: lws_context_creation_info info; lws_context * context; server_handler data; + uint64_t timeout_secs; }; ws_server::ws_server(ws_config const & config) @@ -167,7 +162,7 @@ messagereader ws_server::perform(messagewriter writer) auto result = d->data.perform(std::move(writer)); lws_cancel_service(d->context); - if(std::future_status::timeout == result.wait_for(std::chrono::seconds(timeout_secs))) + if(std::future_status::timeout == result.wait_for(std::chrono::seconds(d->timeout_secs))) { throw std::runtime_error("timeout"); }