Listener type now defaults to udp if invalid. Handle listener type change in config.

git-svn-id: http://voip.null.ro/svn/yate@4531 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
marian 2011-07-29 11:03:19 +00:00
parent beee5d66bc
commit 56c62825b1
2 changed files with 43 additions and 14 deletions

View File

@ -286,9 +286,10 @@
; type: keyword: Listener type
; Allowed values:
; udp: Build an UDP listener. Ignored if multihomed is disabled
; udp: Build an UDP listener
; tcp: Build a TCP listener
; tls: Build a TLS listener (encrypted TCP)
; Defaults to udp if missing or invalid
;type=
; enable: boolean: Enable or disable this listener

View File

@ -456,6 +456,12 @@ public:
{ return protocol() == Tls; }
inline bool listening() const
{ return m_socket != 0; }
inline void setReason(const char* reason) {
if (!reason)
return;
Lock lck(m_mutex);
m_reason = reason;
}
virtual void run();
private:
// Close the socket. Remove from endpoint list
@ -656,7 +662,7 @@ public:
YateSIPUDPTransport* findUdpTransport(const String& addr, int port);
// Build or delete an UDP transport (re-init existing). Start the thread
bool setupUdpTransport(const String& name, bool enabled, const NamedList& params,
const NamedList& defs = NamedList::empty());
const NamedList& defs = NamedList::empty(), const char* reason = 0);
// Delete an UDP transport
bool removeUdpTransport(const String& name, const char* reason);
// Remove a transport from list without deleting it. Notify termination.
@ -671,7 +677,7 @@ public:
// Remove a listener from list without deleting it. Return true if found
bool removeListener(YateSIPTCPListener* listener);
// Remove a listener from list. Remove all if name is empty. Wait for termination
void cancelListener(const String& name = String::empty());
void cancelListener(const String& name = String::empty(), const char* reason = 0);
// This method is called by the driver when start/end initializing
void initializing(bool start);
inline YateSIPEngine* engine() const
@ -3133,7 +3139,12 @@ void YateSIPTCPListener::cleanup(bool final)
else
Debug(&plugin,DebugWarn,"Listener(%s,'%s') abnormally terminated [%p]",protoName(),c_str(),this);
}
stopListening("Terminated",DebugInfo);
m_mutex.lock();
const char* reason = 0;
if (!m_reason)
reason = "Terminated";
m_mutex.unlock();
stopListening(reason,DebugInfo);
}
// Reset socket
@ -3722,7 +3733,7 @@ YateSIPUDPTransport* YateSIPEndPoint::findUdpTransport(const String& addr, int p
// Build an UDP transport (re-init existing). Start the thread
bool YateSIPEndPoint::setupUdpTransport(const String& name, bool enabled,
const NamedList& params, const NamedList& defs)
const NamedList& params, const NamedList& defs, const char* reason)
{
if (!name)
return false;
@ -3734,7 +3745,7 @@ bool YateSIPEndPoint::setupUdpTransport(const String& name, bool enabled,
if (stop)
rd->init(params,defs,false);
else {
removeUdpTransport(name,enabled ? "Address changed" : "Disabled");
removeUdpTransport(name,enabled ? "Address changed" : (reason ? reason : "Disabled"));
rd->deref();
}
TelEngine::destruct(rd);
@ -3780,7 +3791,7 @@ bool YateSIPEndPoint::removeUdpTransport(const String& name, const char* reason)
Thread::idle();
intervals--;
}
if (intervals)
if (!intervals)
Debug(&plugin,DebugNote,
"Removing udp transport '%s' with active transactions using it",
name.c_str());
@ -3874,11 +3885,18 @@ bool YateSIPEndPoint::setupListener(int proto, const String& name, bool enabled,
ObjList* o = m_listeners.find(name);
if (o) {
YateSIPTCPListener* l = static_cast<YateSIPTCPListener*>(o->get());
if (enabled)
l->init(params,false);
if (enabled) {
if (l->protocol() == proto)
l->init(params,false);
else {
lock.drop();
cancelListener(name,"Type changed");
return setupListener(proto,name,enabled,params);
}
}
else {
lock.drop();
cancelListener(name);
cancelListener(name,"Disabled");
}
return true;
}
@ -3909,7 +3927,7 @@ bool YateSIPEndPoint::removeListener(YateSIPTCPListener* listener)
}
// Remove a listener from list. Remove all if name is empty. Wait for termination
void YateSIPEndPoint::cancelListener(const String& name)
void YateSIPEndPoint::cancelListener(const String& name, const char* reason)
{
m_mutex.lock();
bool wait = false;
@ -3918,7 +3936,9 @@ void YateSIPEndPoint::cancelListener(const String& name)
if (name && name != l->toString())
continue;
wait = true;
Debug(&plugin,DebugAll,"Stopping listener (%p,'%s')",l,l->toString().c_str());
Debug(&plugin,DebugAll,"Stopping listener (%p,'%s') reason=%s",
l,l->toString().c_str(),reason);
l->setReason(reason);
l->cancel();
if (name)
break;
@ -3967,7 +3987,7 @@ void YateSIPEndPoint::initializing(bool start)
for (ObjList* o = rmListener.skipNull(); o; o = o->skipNext()) {
String* name = static_cast<String*>(o->get());
Debug(&plugin,DebugNote,"Stopping deleted listener '%s'",name->c_str());
cancelListener(*name);
cancelListener(*name,"Deleted");
}
for (ObjList* o = rmUdpTrans.skipNull(); o; o = o->skipNext())
removeUdpTransport(o->get()->toString(),"Deleted");
@ -7378,14 +7398,22 @@ void SIPDriver::initialize()
if (!name || name == YSTRING("general"))
continue;
const String& type = (*nl)[YSTRING("type")];
int proto = ProtocolHolder::lookupProtoAny(type,false);
int proto = ProtocolHolder::lookupProtoAny(type);
if (proto == ProtocolHolder::Unknown) {
proto = ProtocolHolder::Udp;
Debug(this,DebugNote,"Invalid listener type '%s' in section '%s': defaults to %s",
type.c_str(),nl->c_str(),ProtocolHolder::lookupProtoName(proto,false));
}
bool enabled = nl->getBoolValue(YSTRING("enable"),true);
switch (proto) {
case ProtocolHolder::Udp:
m_endpoint->cancelListener(name,"Type changed");
m_endpoint->setupUdpTransport(name,enabled,*nl,*def);
break;
case ProtocolHolder::Tcp:
case ProtocolHolder::Tls:
m_endpoint->setupUdpTransport(name,false,NamedList::empty(),
NamedList::empty(),"Type changed");
m_endpoint->setupListener(proto,name,enabled,*nl);
break;
default: