/// <summary> /// Returns existing flow if exists, otherwise new created flow. /// </summary> /// <param name="isServer">Specifies if created flow is server or client flow. This has effect only if flow is created.</param> /// <param name="localEP">Local end point.</param> /// <param name="remoteEP">Remote end point.</param> /// <param name="transport">SIP transport.</param> /// <returns>Returns existing flow if exists, otherwise new created flow.</returns> /// <exception cref="ArgumentNullException">Is raised when <b>localEP</b>,<b>remoteEP</b> or <b>transport</b> is null reference.</exception> /// <exception cref="ArgumentException">Is raised when any of the arguments has invalid value.</exception> internal SIP_Flow GetOrCreateFlow(bool isServer,IPEndPoint localEP,IPEndPoint remoteEP,string transport) { if(localEP == null){ throw new ArgumentNullException("localEP"); } if(remoteEP == null){ throw new ArgumentNullException("remoteEP"); } if(transport == null){ throw new ArgumentNullException("transport"); } string flowID = localEP.ToString() + "-" + remoteEP.ToString() + "-" + transport.ToString(); lock(m_pLock){ SIP_Flow flow = null; if(m_pFlows.TryGetValue(flowID,out flow)){ return flow; } else{ flow = new SIP_Flow(m_pOwner.Stack,isServer,localEP,remoteEP,transport); m_pFlows.Add(flow.ID,flow); flow.IsDisposing += new EventHandler(delegate(object s,EventArgs e){ lock(m_pLock){ m_pFlows.Remove(flowID); } }); flow.Start(); return flow; } } }
/// <summary> /// Creates new flow from TCP server session. /// </summary> /// <param name="session">TCP server session.</param> /// <returns>Returns created flow.</returns> /// <exception cref="ArgumentNullException">Is raised when <b>session</b> is null reference.</exception> internal SIP_Flow CreateFromSession(TCP_ServerSession session) { if(session == null){ throw new ArgumentNullException("session"); } string flowID = session.LocalEndPoint.ToString() + "-" + session.RemoteEndPoint.ToString() + "-" + (session.IsSecureConnection ? SIP_Transport.TLS : SIP_Transport.TCP); lock(m_pLock){ SIP_Flow flow = new SIP_Flow(m_pOwner.Stack,session); m_pFlows.Add(flowID,flow); flow.IsDisposing += new EventHandler(delegate(object s,EventArgs e){ lock(m_pLock){ m_pFlows.Remove(flowID); } }); flow.Start(); return flow; } }