Beispiel #1
0
        /// <summary>
        /// An IQ Element is received. Now check if its one we are looking for and
        /// raise the event in this case.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnIq(object sender, Xmpp.protocol.client.IQ iq)
        {
            if (iq == null)
            {
                return;
            }

            // the tracker handles on iq responses, which are either result or error
            if (iq.Type != IqType.error && iq.Type != IqType.result)
            {
                return;
            }

            string id = iq.Id;

            if (id == null)
            {
                return;
            }

            TrackerData td;

            lock (m_grabbing)
            {
                td = (TrackerData)m_grabbing[id];

                if (td == null)
                {
                    return;
                }
                m_grabbing.Remove(id);
            }

            td.cb(this, iq, td.data);
        }
Beispiel #2
0
        /// <summary>
        /// Sends an Iq synchronous and return the response or null on timeout
        /// </summary>
        /// <param name="iq">The IQ to send</param>
        /// <param name="timeout"></param>
        /// <returns>The response IQ or null on timeout</returns>
        public IQ SendIq(Xmpp.protocol.client.IQ iq, int timeout)
        {
            synchronousResponse = null;
            AutoResetEvent are = new AutoResetEvent(false);

            SendIq(iq, new IqCB(SynchronousIqResult), are);

            if (!are.WaitOne(timeout, true))
            {
                // Timed out
                lock (m_grabbing)
                {
                    if (m_grabbing.ContainsKey(iq.Id))
                    {
                        m_grabbing.Remove(iq.Id);
                    }
                }
                return(null);
            }

            return(synchronousResponse);
        }