private void OnWait(object _, TimeoutEventArgs a) { try { lock (locker) { if (currentRequest != null) { log.DebugFormat("Close request {0}", Id); currentRequest.Close(false); currentRequest = null; } } } finally { if (lastRequestTime + waitTimeout + inactivityTimeout < DateTime.Now) { Close(); } else { IdleWatcher.StartWatch(Id, waitTimeout, OnWait); } } }
public void ProcessBody(Body body, HttpListenerContext ctx) { log.DebugFormat("Start process body connection {0}", Id); lock (locker) { CloseRequest(false); lastRequestTime = DateTime.Now; currentRequest = new BoshXmppRequest(Id, body, ctx); } if (body.HasChildElements) { if (body.FirstChild.GetAttribute("type") == "notification") { //сonfiguring store and write to data base DbPushStore dbPushStore = new DbPushStore(); var properties = new Dictionary <string, string>(1); properties.Add("connectionStringName", "default"); dbPushStore.Configure(properties); dbPushStore.SaveUserEndpoint( body.FirstChild.GetAttribute("username"), body.FirstChild.GetAttribute("endpoint"), body.FirstChild.GetAttribute("browser")); } } if (body.Type == BoshType.terminate) { Close(); return; } if (Volatile.Read(ref closed) == 1) { CloseRequest(true); return; } IdleWatcher.UpdateTimeout(Id, waitTimeout); if (string.IsNullOrEmpty(body.Sid) || body.XmppRestart) { var stream = new Stream { Prefix = Uri.PREFIX, Namespace = Uri.STREAM, Version = body.Version, Language = body.GetAttribute("lang"), To = body.To, }; XmppStreamStart(this, new XmppStreamStartEventArgs(Id, stream, Uri.CLIENT)); } foreach (var element in body.ChildNodes.OfType <Element>()) { XmppStreamElement(this, new XmppStreamEventArgs(Id, element)); } Send((Node)null, null); // try to send a non-empty buffer }
private void CloseRequest(bool terminate) { lock (locker) { if (currentRequest != null) { currentRequest.Close(terminate); currentRequest = null; } } log.DebugFormat("Close request {0}{1}", Id, terminate ? " with termination" : ""); }
public void ProcessBody(Body body, HttpListenerContext ctx) { log.DebugFormat("Start process body connection {0}", Id); lock (locker) { CloseRequest(false); lastRequestTime = DateTime.Now; currentRequest = new BoshXmppRequest(Id, body, ctx); } if (body.Type == BoshType.terminate) { Close(); return; } if (Volatile.Read(ref closed) == 1) { CloseRequest(true); return; } IdleWatcher.UpdateTimeout(Id, waitTimeout); if (string.IsNullOrEmpty(body.Sid) || body.XmppRestart) { var stream = new Stream { Prefix = Uri.PREFIX, Namespace = Uri.STREAM, Version = body.Version, Language = body.GetAttribute("lang"), To = body.To, }; XmppStreamStart(this, new XmppStreamStartEventArgs(Id, stream, Uri.CLIENT)); } foreach (var element in body.ChildNodes.OfType <Element>()) { XmppStreamElement(this, new XmppStreamEventArgs(Id, element)); } Send((Node)null, null); // try to send a non-empty buffer }
public void Send(Node node, Encoding encoding) { lock (locker) { if (node != null) { sendBuffer.Add(node); } if (currentRequest != null && sendBuffer.Any()) { try { var terminate = Volatile.Read(ref closed) == 1; currentRequest.SendAndClose(sendBuffer, terminate); sendBuffer.Clear(); } catch (Exception e) { log.ErrorFormat("Connection {0} Error send buffer: {1}", Id, e); } currentRequest = null; } } }