public void BeginReceive(XmppHandlerManager handlerManager) { RequiresNotClosed(); Args.NotNull(handlerManager, "handlerManager"); Log.Information(GetType().Name + " begin receive"); this.handlerManager = handlerManager; reader = new XmppStreamReader(context.Request.InputStream); reader.ReadElementComleted += (s, e) => { if (e.State == XmppStreamState.Success) { Log.Information(GetType().Name + " {0} recv <<:\r\n{1:I}\r\n", SessionId, e.Element); handlerManager.ProcessElement(this, e.Element); } else if (e.State == XmppStreamState.Error) { if (!IgnoreError(e.Error)) { Log.Error(e.Error); } Close(); } }; reader.ReadElementAsync(); }
public void Reset() { Log.Information(GetType().Name + " {0} reset", SessionId); if (reader != null) { reader.ReadElementCancel(); } reader = new XmppStreamReader(stream); reader.ReadElementComleted += (s, e) => { if (e.State == XmppStreamState.Success) { Log.Information(GetType().Name + " {0} recv <<:\r\n{1:I}\r\n", SessionId, e.Element); handlerManager.ProcessElement(this, e.Element); } else if (e.State == XmppStreamState.Error) { if (!IgnoreError(e.Error)) { Log.Error(e.Error); } Close(); } else if (e.State == XmppStreamState.Closed) { Close(); } }; reader.ReadElementAsync(); if (writer != null) { writer.WriteElementCancel(); } writer = new XmppStreamWriter(stream); writer.WriteElementComleted += (s, e) => { if (e.State == XmppStreamState.Error) { if (!IgnoreError(e.Error)) { Log.Error(e.Error); } Close(); } }; }