diff --git a/src/webfuse/webfuse.cpp b/src/webfuse/webfuse.cpp index 8158417..64eb26b 100644 --- a/src/webfuse/webfuse.cpp +++ b/src/webfuse/webfuse.cpp @@ -2,44 +2,18 @@ #include "webfuse/fuse.hpp" #include "webfuse/filesystem/empty_filesystem.hpp" #include "webfuse/ws/server.hpp" -#include "webfuse/ws/config.hpp" - -#include - -namespace -{ - -bool shutdown_requested = false; - -void on_shutdown_requested(int) -{ - shutdown_requested = true; -} - -} namespace webfuse { int app::run(int argc, char * argv[]) { -/* empty_filesystem filesystem; fuse fuse_fs(filesystem); - - return fuse_fs.run(argc, argv); -*/ - signal(SIGINT, &on_shutdown_requested); - ws_config config; ws_server server(config); - while (!shutdown_requested) - { - server.service(); - } - - return 0; + return fuse_fs.run(argc, argv); } } \ No newline at end of file diff --git a/src/webfuse/ws/server.cpp b/src/webfuse/ws/server.cpp index 4942cf8..b346cc0 100644 --- a/src/webfuse/ws/server.cpp +++ b/src/webfuse/ws/server.cpp @@ -3,6 +3,8 @@ #include #include +#include +#include extern "C" { @@ -48,6 +50,7 @@ class ws_server::detail detail& operator=(detail &&) = delete; public: detail(ws_config const & config) + : shutdown_requested(false) { memset(reinterpret_cast(protocols), 0, sizeof(protocols)); protocols[0].name = "webfuse2"; @@ -65,13 +68,27 @@ public: lws_vhost * const vhost = lws_create_vhost(context, &info); // port = lws_get_vhost_port(vhost); + + + thread = std::thread([this]() { + while (!shutdown_requested) + { + lws_service(context, 0); + } + + }); } ~detail() { + shutdown_requested = true; + lws_cancel_service(context); + thread.join(); lws_context_destroy(context); } + std::thread thread; + std::atomic shutdown_requested; lws_protocols protocols[2]; lws_context_creation_info info; lws_context * context; @@ -106,15 +123,4 @@ ws_server& ws_server::operator=(ws_server && other) return *this; } -void ws_server::service() -{ - lws_service(d->context, 0); -} - -void ws_server::interrupt() -{ - lws_cancel_service(d->context); -} - - } \ No newline at end of file diff --git a/src/webfuse/ws/server.hpp b/src/webfuse/ws/server.hpp index fd752ac..68492a3 100644 --- a/src/webfuse/ws/server.hpp +++ b/src/webfuse/ws/server.hpp @@ -15,8 +15,6 @@ public: ~ws_server(); ws_server(ws_server && other); ws_server& operator=(ws_server && other); - void service(); - void interrupt(); private: class detail; detail * d;