From 79964329b38dc12f66d55ac34aa3b036a52f46fa Mon Sep 17 00:00:00 2001
From: Sergi Hernandez Juan <shernand@iri.upc.edu>
Date: Fri, 7 May 2021 16:14:42 +0200
Subject: [PATCH] When the communication thread catches an exception, it sets
 the communication object to the created state before finishing the thread.

---
 src/comm.cpp | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/comm.cpp b/src/comm.cpp
index a1078ba..0cb3c14 100644
--- a/src/comm.cpp
+++ b/src/comm.cpp
@@ -261,6 +261,15 @@ void *CComm::comm_thread(void *param)
       }
       comm_dev->access_comm.exit();
     }catch(CException &e){
+      try{
+        comm_dev->hard_close();
+      }catch(CException &close){
+        std::cout << close.what() << std::endl;
+      }
+      /* flush the data queues */
+      comm_dev->receive_queue.flush();
+      /* change the current state */
+      comm_dev->state=created;
       comm_dev->access_comm.exit();
       std::cout << e.what() << std::endl;
       end=true;
-- 
GitLab