diff --git a/core/SipCtrlInterface.cpp b/core/SipCtrlInterface.cpp index 0cc13a61..095b0128 100644 --- a/core/SipCtrlInterface.cpp +++ b/core/SipCtrlInterface.cpp @@ -113,6 +113,7 @@ int SipCtrlInterface::load() } SipCtrlInterface::SipCtrlInterface() + : stopped(false) { trans_layer::instance()->register_ua(this); } @@ -222,13 +223,12 @@ int SipCtrlInterface::send(AmSipRequest &req) void SipCtrlInterface::run(const string& bind_addr, unsigned short bind_port) { - INFO("Starting SIP control interface\n"); + DBG("Starting SIP control interface\n"); udp_trsp_socket* udp_socket = new udp_trsp_socket; udp_socket->bind(bind_addr,bind_port); trans_layer::instance()->register_transport(udp_socket); - udp_trsp** udp_servers = new udp_trsp*[AmConfig::SIPServerThreads]; wheeltimer::instance()->start(); @@ -237,8 +237,15 @@ void SipCtrlInterface::run(const string& bind_addr, unsigned short bind_port) udp_servers[i] = new udp_trsp(udp_socket); udp_servers[i]->start(); } - + + while (!stopped.get()) { + stopped.wait_for(); + } + + DBG("Stopping SIP control interface threads\n"); + for(int i=0; istop(); udp_servers[i]->join(); delete udp_servers[i]; } @@ -247,6 +254,11 @@ void SipCtrlInterface::run(const string& bind_addr, unsigned short bind_port) delete udp_socket; } +void SipCtrlInterface::stop() +{ + stopped.set(true); +} + int SipCtrlInterface::send(const AmSipReply &rep) { sip_msg msg; diff --git a/core/SipCtrlInterface.h b/core/SipCtrlInterface.h index a0a2885d..45fc95bd 100644 --- a/core/SipCtrlInterface.h +++ b/core/SipCtrlInterface.h @@ -51,6 +51,8 @@ class SipCtrlInterface: friend class udp_trsp; + AmCondition stopped; + public: static string outbound_host; @@ -66,7 +68,8 @@ public: int load(); void run(const string& bind_addr, unsigned short bind_port); - + void stop(); + /** * Sends a SIP request. *