public void Test_Full_Response() { SocketWatcher watcher = new SocketWatcher(); Address a = new Address("127.0.0.1", 7002); a.Resolve(); ServerListener server = new ServerListener(); AsyncSocket server_sock = watcher.CreateListenSocket(server, a); server_sock.RequestAccept(); ResponseListener resp = new ResponseListener(); HttpSocket sock = new HttpSocket(resp); Uri u = new Uri("http://localhost:7002/"); byte[] buf = ENC.GetBytes("11111"); HttpSocket s = (HttpSocket)sock; s.Execute("GET", u, buf, 0, buf.Length, "text/plain"); resp.Event.WaitOne(); Assert.AreEqual("1234567890", resp.Last); resp.Last = null; buf = ENC.GetBytes("22222"); s.Execute("GET", u, buf, 0, buf.Length, "text/plain"); resp.Event.WaitOne(); Assert.AreEqual("1234567890", resp.Last); resp.Last = null; buf = ENC.GetBytes("33333"); s.Execute("GET", u, buf, 0, buf.Length, "text/plain"); resp.Event.WaitOne(); Assert.AreEqual("12345678901234567890", resp.Last); }
void ISocketEventListener.OnConnect(BaseSocket sock) { lock (m_lock) { if (!m_running && (m_sockA != null) && m_sockA.Connected && (m_sockB != null) && m_sockB.Connected) { m_running = true; m_lastSock = m_sockB; m_listener.OnConnect(this); } } }
private HttpSocket GetSocket() { lock (m_lock) { if (m_lastSock == m_sockA) { m_lastSock = m_sockB; } else { m_lastSock = m_sockA; } return(m_lastSock); } }
// 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); }
/// <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.ProxyURI = m_sockB.ProxyURI = m_proxyURI; m_sockA.ProxyCredentials = m_sockB.ProxyCredentials = m_proxyCredentials; m_sockA.Connect(m_uri); m_sockB.Connect(m_uri); }
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); m_thread.IsBackground = true; m_thread.Name = "XEP 124 processing thread"; m_thread.Start(); m_listener.OnConnect(this); } } }
/// <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); }
/// <summary> /// Stop polling. /// </summary> public override void Close() { Body body = CreateOpenBodyTag(); body.Type = BodyType.terminate; byte[] buf = ENC.GetBytes(body.OuterXml); //m_listener.OnWrite(this, buf, 0, buf.Length); GetSocket().Execute(METHOD, m_uri, buf, 0, buf.Length, CONTENT_TYPE); m_sockA.EnqueueClose(); m_sockB.EnqueueClose(); lock (m_lock) { m_running = false; m_sockA = m_sockB = m_lastSock = null; } m_listener.OnClose(this); }
// 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; }
/// <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); }
/// <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); }
/// <summary> /// Stop polling. /// </summary> public override void Close() { if (m_running) { Body body = CreateOpenBodyTag(); body.Type = BodyType.terminate; Enqueue(body); } else { // Make sure that the queue has a chance to process/free lock (m_queue) { Monitor.Pulse(m_queue); } } 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); }
private HttpSocket GetSocket() { lock (m_lock) { if (m_lastSock == m_sockA) { m_lastSock = m_sockB; } else { m_lastSock = m_sockA; } return m_lastSock; } }