#include "../lib/manager.hpp"
#include <stdexcept>
-#include <thread>
+
namespace
context_ = libwebsocket_create_context(&info);
if (context_ == nullptr)
- throw std::runtime_error("Unable to initialize websocket.\n");
+ throw std::runtime_error("Unable to initialize websocket.");
std::cout << "\n" PACKAGE_NAME " listening for requests on port "
<< info.port << ".\n";
void
ivi::settings::websocket_server::run()
{
- // Run the websocket event loop in its own thread.
- std::thread(
- [](libwebsocket_context * context){
- try {
- // Run the libwebsockets event loop with an infinite timeout.
- // The negative timeout causes the underlying call poll() to
- // block indefinitely until an event occurs.
- constexpr int const timeout = -1;
- while (libwebsocket_service(context, timeout) >= 0) {
- }
-
- std::cerr << "WebSocket event loop ended.\n";
- } catch(std::exception & e) {
- std::cerr << e.what() << std::endl;
- }
- },
- context_).detach();
-}
+ // Run the libwebsockets event loop with an infinite timeout. The
+ // negative timeout causes the underlying call poll() to block
+ // indefinitely until an event occurs.
+ constexpr int const timeout = -1;
+ while (libwebsocket_service(context_, timeout) == 0) {
+ }
+}
-/**
- * @todo Add 'state' event do determine whether technology is
- * enabled/disabled.
- */
// Local Variables:
// mode:c++