/// <summary>
        /// Starts flow processing.
        /// </summary>
        internal void Start()
        {
            // Move processing to thread pool.
            AutoResetEvent startLock = new AutoResetEvent(false);

            ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object state){
                lock (m_pLock){
                    startLock.Set();

                    // TCP / TLS client, connect to remote end point.
                    if (!m_IsServer && m_Transport != SIP_Transport.UDP)
                    {
                        try{
                            TCP_Client client = new TCP_Client();
                            client.Connect(m_pLocalEP, m_pRemoteEP, m_Transport == SIP_Transport.TLS);

                            m_pTcpSession = client;

                            BeginReadHeader();
                        }
                        catch {
                            Dispose();
                        }
                    }
                }
            }));
            startLock.WaitOne();
            startLock.Close();
        }
        /// <summary>
        /// Server TCP,TLS constructor.
        /// </summary>
        /// <param name="stack">Owner stack.</param>
        /// <param name="session">TCP session.</param>
        /// <exception cref="ArgumentNullException">Is raised when <b>stack</b> or <b>session</b> is null reference.</exception>
        internal SIP_Flow(SIP_Stack stack, TCP_ServerSession session)
        {
            if (stack == null)
            {
                throw new ArgumentNullException("stack");
            }
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }

            m_pStack      = stack;
            m_pTcpSession = session;

            m_IsServer     = true;
            m_pLocalEP     = session.LocalEndPoint;
            m_pRemoteEP    = session.RemoteEndPoint;
            m_Transport    = session.IsSecureConnection ? SIP_Transport.TLS : SIP_Transport.TCP;
            m_CreateTime   = DateTime.Now;
            m_LastActivity = DateTime.Now;
            m_ID           = m_pLocalEP.ToString() + "-" + m_pRemoteEP.ToString() + "-" + m_Transport;
            m_pMessage     = new MemoryStream();

            // Dispose flow when TCP server session closed.
            session.Disposed += new EventHandler(delegate(object s, EventArgs e){
                Dispose();
            });

            BeginReadHeader();
        }
예제 #3
0
        /// <summary>
        /// Server TCP,TLS constructor.
        /// </summary>
        /// <param name="stack">Owner stack.</param>
        /// <param name="session">TCP session.</param>
        /// <exception cref="ArgumentNullException">Is raised when <b>stack</b> or <b>session</b> is null reference.</exception>
        internal SIP_Flow(SIP_Stack stack, TCP_Session session)
        {
            if (stack == null)
            {
                throw new ArgumentNullException("stack");
            }
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }

            m_pStack      = stack;
            m_pTcpSession = session;

            m_IsServer     = true;
            m_pLocalEP     = session.LocalEndPoint;
            m_pRemoteEP    = session.RemoteEndPoint;
            m_Transport    = session.IsSecureConnection ? SIP_Transport.TLS : SIP_Transport.TCP;
            m_CreateTime   = DateTime.Now;
            m_LastActivity = DateTime.Now;
            m_ID           = m_pLocalEP + "-" + m_pRemoteEP + "-" + m_Transport;
            m_pMessage     = new MemoryStream();

            BeginReadHeader();
        }
        /// <summary>
        /// Cleans up any resources being used.
        /// </summary>
        public void Dispose()
        {
            lock (m_pLock){
                if (m_IsDisposed)
                {
                    return;
                }
                OnDisposing();
                m_IsDisposed = true;

                if (m_pTcpSession != null)
                {
                    m_pTcpSession.Dispose();
                    m_pTcpSession = null;
                }
                m_pMessage = null;
                if (m_pKeepAliveTimer != null)
                {
                    m_pKeepAliveTimer.Dispose();
                    m_pKeepAliveTimer = null;
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Starts flow processing.
        /// </summary>
        internal void Start()
        {
            // Move processing to thread pool.
            AutoResetEvent startLock = new AutoResetEvent(false);
            ThreadPool.QueueUserWorkItem(delegate
                                             {
                                                 lock (m_pLock)
                                                 {
                                                     startLock.Set();

                                                     // TCP / TLS client, connect to remote end point.
                                                     if (!m_IsServer && m_Transport != SIP_Transport.UDP)
                                                     {
                                                         try
                                                         {
                                                             TCP_Client client = new TCP_Client();
                                                             client.Connect(m_pLocalEP,
                                                                            m_pRemoteEP,
                                                                            m_Transport == SIP_Transport.TLS);

                                                             m_pTcpSession = client;

                                                             BeginReadHeader();
                                                         }
                                                         catch
                                                         {
                                                             Dispose();
                                                         }
                                                     }
                                                 }
                                             });
            startLock.WaitOne();
        }
예제 #6
0
        /// <summary>
        /// Cleans up any resources being used.
        /// </summary>
        public void Dispose()
        {
            lock (m_pLock)
            {
                if (m_IsDisposed)
                {
                    return;
                }
                OnDisposing();
                m_IsDisposed = true;

                if (m_pTcpSession != null)
                {
                    m_pTcpSession.Dispose();
                    m_pTcpSession = null;
                }
                m_pMessage = null;
                if (m_pKeepAliveTimer != null)
                {
                    m_pKeepAliveTimer.Dispose();
                    m_pKeepAliveTimer = null;
                }
            }
        }
예제 #7
0
        /// <summary>
        /// Server TCP,TLS constructor.
        /// </summary>
        /// <param name="stack">Owner stack.</param>
        /// <param name="session">TCP session.</param>
        /// <exception cref="ArgumentNullException">Is raised when <b>stack</b> or <b>session</b> is null reference.</exception>
        internal SIP_Flow(SIP_Stack stack, TCP_Session session)
        {
            if (stack == null)
            {
                throw new ArgumentNullException("stack");
            }
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }

            m_pStack = stack;
            m_pTcpSession = session;

            m_IsServer = true;
            m_pLocalEP = session.LocalEndPoint;
            m_pRemoteEP = session.RemoteEndPoint;
            m_Transport = session.IsSecureConnection ? SIP_Transport.TLS : SIP_Transport.TCP;
            m_CreateTime = DateTime.Now;
            m_LastActivity = DateTime.Now;
            m_ID = m_pLocalEP + "-" + m_pRemoteEP + "-" + m_Transport;
            m_pMessage = new MemoryStream();

            BeginReadHeader();
        }