make timeout configurable

pull/105/head
Falk Werner 1 year ago
parent 8a68ecd0b7
commit b3bc3144bf

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

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

@ -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<uint64_t>(std::stoi(timeout_str));
}
}
else
{
args.push(arg.c_str());

@ -33,6 +33,8 @@ public:
std::string authenticator;
std::string auth_header;
uint64_t timeout_secs;
};
}

@ -19,13 +19,6 @@
#include <unordered_map>
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");
}

Loading…
Cancel
Save