Пример #1
0
        // Must hold lock first.
        private HttpSocket GetSocket()
        {
            // Debug.Assert(!BothPending);

            // Switch to the other socket than the last one, assuming the other socket isn't pending.
            // If the other socket is pending, use the last one.
            HttpSocket other = (m_lastSock == m_sockA) ? m_sockB : m_sockA;
            if (!other.IsPending)
                m_lastSock = other;

            Debug.WriteLine("Socket: " + m_lastSock.Name);
            return m_lastSock;
        }
Пример #2
0
        /// <summary>
        /// Start polling
        /// </summary>
        /// <param name="addr">Ignored in this case.  Set URL.</param>
        public override void Connect(Address addr)
        {
            Debug.Assert(m_uri != null);

            m_rid = -1L;
            m_lastSock = null;
            m_running = false;

            // Create new ones each time, in case the URL has changed or something.
            m_sockA = new HttpSocket(this);
            m_sockB = new HttpSocket(this);

            m_sockA.Name = "A";
            m_sockB.Name = "B";

            m_sockA.ProxyURI = m_sockB.ProxyURI = m_proxyURI;
            m_sockA.ProxyCredentials = m_sockB.ProxyCredentials = m_proxyCredentials;

            m_sockA.Connect(m_uri);
            m_sockB.Connect(m_uri);
        }
Пример #3
0
        void ISocketEventListener.OnConnect(BaseSocket sock)
        {
            lock (m_queue)
            {
                if (!m_running &&
                    (m_sockA != null) && m_sockA.Connected &&
                    (m_sockB != null) && m_sockB.Connected)
                {
                    m_running = true;
                    m_lastSock = m_sockB;

                    m_thread = new Thread(ProcessThread) {IsBackground = true, Name = "XEP 124 processing thread"};
                    m_thread.Start();

                    m_listener.OnConnect(this);
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Stop polling.
        /// </summary>
        public override void Close()
        {
            Body body = CreateOpenBodyTag();
            body.Type = BodyType.terminate;

            Enqueue(body);

            if (m_thread != null)
                m_thread.Join();

            lock (m_queue)
            {
                m_running = false;
                m_thread = null;
                m_sockA = m_sockB = m_lastSock = null;
            }
            m_listener.OnClose(this);
        }