[ekiga] Made sure the STUN detector code doesn't crash if we quit-at-startup



commit 6f144112b2a89bf1d02aaf10e223ec0f71058054
Author: Julien Puydt <jpuydt free fr>
Date:   Mon Feb 11 10:59:39 2013 +0100

    Made sure the STUN detector code doesn't crash if we quit-at-startup

 lib/engine/components/opal/opal-call-manager.cpp |    9 +++++++--
 lib/engine/components/opal/opal-call-manager.h   |    1 +
 2 files changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/lib/engine/components/opal/opal-call-manager.cpp b/lib/engine/components/opal/opal-call-manager.cpp
index 5d91815..d1457bb 100644
--- a/lib/engine/components/opal/opal-call-manager.cpp
+++ b/lib/engine/components/opal/opal-call-manager.cpp
@@ -117,6 +117,8 @@ CallManager::CallManager (Ekiga::ServiceCore& core)
   call_core = core.get<Ekiga::CallCore> ("call-core");
   notification_core = core.get<Ekiga::NotificationCore> ("notification-core");
 
+  stun_thread = 0;
+
   /* Initialise the endpoint parameters */
 #if P_HAS_IPV6
   char * ekiga_ipv6 = getenv("EKIGA_IPV6");
@@ -178,6 +180,8 @@ CallManager::CallManager (Ekiga::ServiceCore& core)
 
 CallManager::~CallManager ()
 {
+  if (stun_thread)
+    stun_thread->WaitForTermination ();
   ClearAllCalls (OpalConnection::EndedByLocalUser, true);
   ShutDownEndpoints ();
 
@@ -565,10 +569,10 @@ void CallManager::set_stun_server (const std::string & server)
 void CallManager::set_stun_enabled (bool enabled)
 {
   stun_enabled = enabled;
-  if (stun_enabled) {
+  if (stun_enabled && stun_thread) {
 
     // Ready
-    new StunDetector (stun_server, *this, queue);
+    stun_thread = new StunDetector (stun_server, *this, queue);
     patience = 20;
     Ekiga::Runtime::run_in_main (boost::bind (&CallManager::HandleSTUNResult, this), 1);
   } else
@@ -846,6 +850,7 @@ CallManager::HandleSTUNResult ()
     PSTUNClient::NatTypes result
       = (PSTUNClient::NatTypes)(GPOINTER_TO_UINT (g_async_queue_pop (queue))-1);
     got_answer = true;
+    stun_thread = 0;
 
     if (result == PSTUNClient::SymmetricNat
 	|| result == PSTUNClient::BlockedNat
diff --git a/lib/engine/components/opal/opal-call-manager.h b/lib/engine/components/opal/opal-call-manager.h
index 5e05d21..fbfb22a 100644
--- a/lib/engine/components/opal/opal-call-manager.h
+++ b/lib/engine/components/opal/opal-call-manager.h
@@ -190,6 +190,7 @@ private:
 
     void GetAllowedFormats (OpalMediaFormatList & full_list);
 
+    PThread* stun_thread;
     void HandleSTUNResult ();
 
     void ReportSTUNError (const std::string error);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]