Example #1
0
        private Task CloseHandler(object Sender, IqEventArgs e)
        {
            string         StreamId = XML.Attribute(e.Query, "sid");
            string         Key      = e.From + " " + StreamId;
            IncomingStream Input;
            OutgoingStream Output;

            lock (this.synchObject)
            {
                if (this.cache is null)
                {
                    Input = null;
                }
                else if (this.cache.TryGetValue(Key, out Input))
                {
                    this.cache.Remove(Key);
                }
                else
                {
                    Input = null;
                }
            }

            if (Input is null)
            {
                lock (this.output)
                {
                    if (!this.output.TryGetValue(StreamId, out Output))
                    {
                        throw new ItemNotFoundException("Stream not recognized.", e.Query);
                    }

                    this.output.Remove(StreamId);
                }

                Output.Abort();
                Output.Dispose();
            }
            else
            {
                if (Input.BlocksMissing)
                {
                    Input.Closed(CloseReason.Aborted);
                }
                else
                {
                    Input.Closed(CloseReason.Done);
                }

                Input.Dispose();
            }

            e.IqResult(string.Empty);

            return(Task.CompletedTask);
        }
        /// <summary>
        /// Immediately kill the connection and poison the request body stream with an error.
        /// </summary>
        public void Abort(ConnectionAbortedException abortReason)
        {
            if (Interlocked.Exchange(ref _requestAborted, 1) != 0)
            {
                return;
            }

            // Abort output prior to calling OnIOCompleted() to give the transport the chance to complete the input
            // with the correct error and message.
            Output.Abort(abortReason);

            OnInputOrOutputCompleted();

            PoisonRequestBodyStream(abortReason);
        }