Bump version to 0.3.
[profile/ivi/settings-daemon.git] / src / websocket_server.cpp
index c9b15da..636e893 100644 (file)
@@ -30,7 +30,7 @@
 #include "../lib/manager.hpp"
 
 #include <stdexcept>
-#include <thread>
+
 
 
 namespace
@@ -136,7 +136,7 @@ ivi::settings::websocket_server::websocket_server(
 
   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";
@@ -150,30 +150,15 @@ ivi::settings::websocket_server::~websocket_server()
 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++