Fix third start fails 09/183009/1
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Tue, 26 Jun 2018 20:34:52 +0000 (23:34 +0300)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Wed, 27 Jun 2018 10:59:44 +0000 (13:59 +0300)
Problem:
  - RequestQueue::do_all() can not processed all requests
    because Request::execute() can throw exception.

Solution:
  - Encapsulate catching exceptions to Request::execute().

Change-Id: I5d9bba24c3d57948068997ccd61438853ab3fbcf
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
daemon/cpp/events/evloop.cpp
daemon/cpp/events/evloop_request.h

index 4806233..ed6b128 100644 (file)
@@ -88,13 +88,13 @@ public:
         handler_(handler)
     {}
 
-    void execute()
+private:
+    void do_execute() override
     {
         LOGI("ADD: handler[%p fd=%d]\n", handler_, handler_->fd());
         epoll_add_handler(efd_, handler_);
     }
 
-private:
     int efd_;
     Handler *handler_;
 };
@@ -109,7 +109,8 @@ public:
         deleter_(deleter)
     {}
 
-    void execute()
+private:
+    void do_execute() override
     {
         skip_list_->add(handler_);
 
@@ -119,7 +120,6 @@ public:
         deleter_(handler_);
     }
 
-private:
     int efd_;
     SkipList<Handler *> *skip_list_;
 
index c882c14..e8963d4 100644 (file)
@@ -28,6 +28,7 @@
 
 #include <queue>
 #include <memory>
+#include <swap_debug.h>
 
 
 namespace EvLoop {
@@ -36,7 +37,19 @@ namespace EvLoop {
 class Request {
 public:
     virtual ~Request() {}
-    virtual void execute() = 0;
+    void execute()
+    {
+        try {
+            do_execute();
+        } catch (const std::runtime_error &e) {
+            LOGE("%s\n", e.what());
+        } catch (...) {
+            LOGE("Unknown error\n");
+        }
+    }
+
+private:
+    virtual void do_execute() = 0;
 };