/// <summary> /// Starts operation processing. /// </summary> /// <param name="owner">Owner TCP session.</param> /// <returns>Returns true if asynchronous operation in progress or false if operation completed synchronously.</returns> /// <exception cref="ArgumentNullException">Is raised when <b>owner</b> is null reference.</exception> internal bool Start(TCP_ServerSession owner) { if (owner == null) { throw new ArgumentNullException("owner"); } m_pTcpSession = owner; SetState(AsyncOP_State.Active); try { m_pSslStream = new SslStream(m_pTcpSession.TcpStream.SourceStream, true); m_pSslStream.BeginAuthenticateAsServer(m_pTcpSession.m_pCertificate, this.BeginAuthenticateAsServerCompleted, null); } catch (Exception x) { m_pException = x; SetState(AsyncOP_State.Completed); } // Set flag rise CompletedAsync event flag. The event is raised when async op completes. // If already completed sync, that flag has no effect. lock (m_pLock) { m_RiseCompleted = true; return(m_State == AsyncOP_State.Active); } }
/// <summary> /// Starts operation processing. /// </summary> /// <param name="owner">Owner TCP session.</param> /// <returns>Returns true if asynchronous operation in progress or false if operation completed synchronously.</returns> /// <exception cref="ArgumentNullException">Is raised when <b>owner</b> is null reference.</exception> internal bool Start(TCP_ServerSession owner) { if (owner == null) { throw new ArgumentNullException("owner"); } m_pTcpSession = owner; SetState(AsyncOP_State.Active); try{ m_pSslStream = new SslStream(m_pTcpSession.TcpStream.SourceStream, true); #if NETSTANDARD // NOTE synchronously async, yuck var authTask = System.Threading.Tasks.Task.Run(() => m_pSslStream.AuthenticateAsServerAsync(m_pTcpSession.m_pCertificate)); authTask.GetAwaiter().GetResult(); this.BeginAuthenticateAsServerCompleted(); #else m_pSslStream.BeginAuthenticateAsServer(m_pTcpSession.m_pCertificate, this.BeginAuthenticateAsServerCompleted, null); #endif } catch (Exception x) { m_pException = x; SetState(AsyncOP_State.Completed); } // Set flag rise CompletedAsync event flag. The event is raised when async op completes. // If already completed sync, that flag has no effect. lock (m_pLock){ m_RiseCompleted = true; return(m_State == AsyncOP_State.Active); } }
/// <summary> /// Cleans up any resource being used. /// </summary> public void Dispose() { if (m_State == AsyncOP_State.Disposed) { return; } SetState(AsyncOP_State.Disposed); m_pException = null; m_pTcpSession = null; m_pSslStream = null; this.CompletedAsync = null; }
/// <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; } }
/// <summary> /// Starts operation processing. /// </summary> /// <param name="owner">Owner TCP session.</param> /// <returns>Returns true if asynchronous operation in progress or false if operation completed synchronously.</returns> /// <exception cref="ArgumentNullException">Is raised when <b>owner</b> is null reference.</exception> internal bool Start(TCP_ServerSession owner) { if(owner == null){ throw new ArgumentNullException("owner"); } m_pTcpSession = owner; SetState(AsyncOP_State.Active); try{ m_pSslStream = new SslStream(m_pTcpSession.TcpStream.SourceStream,true); m_pSslStream.BeginAuthenticateAsServer(m_pTcpSession.m_pCertificate,this.BeginAuthenticateAsServerCompleted,null); } catch(Exception x){ m_pException = x; SetState(AsyncOP_State.Completed); } // Set flag rise CompletedAsync event flag. The event is raised when async op completes. // If already completed sync, that flag has no effect. lock(m_pLock){ m_RiseCompleted = true; return m_State == AsyncOP_State.Active; } }
/// <summary> /// Cleans up any resource being used. /// </summary> public void Dispose() { if(m_State == AsyncOP_State.Disposed){ return; } SetState(AsyncOP_State.Disposed); m_pException = null; m_pTcpSession = null; m_pSslStream = null; this.CompletedAsync = null; }