<commit_before>﻿//  ------------------------------------------------------------------------------------
//  Copyright (c) Microsoft Corporation
//  All rights reserved. 
//  
//  Licensed under the Apache License, Version 2.0 (the ""License""); you may not use this 
//  file except in compliance with the License. You may obtain a copy of the License at 
//  http://www.apache.org/licenses/LICENSE-2.0  
//  
//  THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
//  EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR 
//  CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR 
//  NON-INFRINGEMENT. 
// 
//  See the Apache Version 2.0 License for specific language governing permissions and 
//  limitations under the License.
//  ------------------------------------------------------------------------------------

namespace Amqp
{
    using System;
    using Amqp.Framing;
    using Amqp.Types;

    /// <summary>
    /// The Session class represents an AMQP session.
    /// </summary>
    public partial class Session : AmqpObject
    {
        enum State
        {
            Start,
            BeginSent,
            BeginReceived,
            Opened,
            EndReceived,
            EndSent,
            EndPipe,
            End
        }

        internal const uint defaultWindowSize = 2048;
        readonly Connection connection;
        readonly OnBegin onBegin;
        readonly ushort channel;
        uint handleMax;
        Link[] localLinks;
        Link[] remoteLinks;
        State state;

        // incoming flow control
        SequenceNumber incomingDeliveryId;
        LinkedList incomingList;
        SequenceNumber nextIncomingId;
        uint incomingWindow;

        // outgoing delivery tracking & flow control
        SequenceNumber outgoingDeliveryId;
        LinkedList outgoingList;
        SequenceNumber nextOutgoingId;
        uint outgoingWindow;

        /// <summary>
        /// Initializes a session object.
        /// </summary>
        /// <param name="connection">The connection within which to create the session.</param>
        public Session(Connection connection)
            : this(connection, Default(connection), null)
        {
        }

        /// <summary>
        /// Initializes a session object with a custom Begin performative.
        /// </summary>
        /// <param name="connection">The connection in which the session will be created.</param>
        /// <param name="begin">The Begin performative to be sent to the remote peer.</param>
        /// <param name="onBegin">The callback to invoke when a begin is received from peer.</param>
        public Session(Connection connection, Begin begin, OnBegin onBegin)
        {
            this.connection = connection;
            this.onBegin = onBegin;
            this.handleMax = begin.HandleMax;
            this.nextOutgoingId = begin.NextOutgoingId;
            this.incomingWindow = defaultWindowSize;
            this.outgoingWindow = begin.IncomingWindow;
            this.incomingDeliveryId = uint.MaxValue;
            this.localLinks = new Link[1];
            this.remoteLinks = new Link[1];
            this.incomingList = new LinkedList();
            this.outgoingList = new LinkedList();
            this.channel = connection.AddSession(this);

            this.state = State.BeginSent;
            this.SendBegin(begin);
        }

        /// <summary>
        /// Gets the connection where the session was created.
        /// </summary>
        public Connection Connection
        {
            get { return this.connection; }
        }

        object ThisLock
        {
            get { return this; }
        }

        internal ushort Channel
        {
            get { return this.channel; }
        }

        internal void Abort(Error error)<commit_msg>[#305] Session (2nd) constructor does not use all of the Begin properties.<commit_after>﻿//  ------------------------------------------------------------------------------------
//  Copyright (c) Microsoft Corporation
//  All rights reserved. 
//  
//  Licensed under the Apache License, Version 2.0 (the ""License""); you may not use this 
//  file except in compliance with the License. You may obtain a copy of the License at 
//  http://www.apache.org/licenses/LICENSE-2.0  
//  
//  THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
//  EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR 
//  CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR 
//  NON-INFRINGEMENT. 
// 
//  See the Apache Version 2.0 License for specific language governing permissions and 
//  limitations under the License.
//  ------------------------------------------------------------------------------------

namespace Amqp
{
    using System;
    using Amqp.Framing;
    using Amqp.Types;

    /// <summary>
    /// The Session class represents an AMQP session.
    /// </summary>
    public partial class Session : AmqpObject
    {
        enum State
        {
            Start,
            BeginSent,
            BeginReceived,
            Opened,
            EndReceived,
            EndSent,
            EndPipe,
            End
        }

        internal const uint defaultWindowSize = 2048;
        readonly Connection connection;
        readonly OnBegin onBegin;
        readonly ushort channel;
        uint handleMax;
        Link[] localLinks;
        Link[] remoteLinks;
        State state;

        // incoming flow control
        SequenceNumber incomingDeliveryId;
        LinkedList incomingList;
        SequenceNumber nextIncomingId;
        uint incomingWindow;

        // outgoing delivery tracking & flow control
        SequenceNumber outgoingDeliveryId;
        LinkedList outgoingList;
        SequenceNumber nextOutgoingId;
        uint outgoingWindow;

        /// <summary>
        /// Initializes a session object.
        /// </summary>
        /// <param name="connection">The connection within which to create the session.</param>
        public Session(Connection connection)
            : this(connection, Default(connection), null)
        {
        }

        /// <summary>
        /// Initializes a session object with a custom Begin performative.
        /// </summary>
        /// <param name="connection">The connection in which the session will be created.</param>
        /// <param name="begin">The Begin performative to be sent to the remote peer.</param>
        /// <param name="onBegin">The callback to invoke when a begin is received from peer.</param>
        public Session(Connection connection, Begin begin, OnBegin onBegin)
        {
            this.connection = connection;
            this.onBegin = onBegin;
            this.handleMax = begin.HandleMax;
            this.nextOutgoingId = begin.NextOutgoingId;
            this.incomingWindow = begin.IncomingWindow;
            this.outgoingWindow = begin.OutgoingWindow;
            this.incomingDeliveryId = uint.MaxValue;
            this.localLinks = new Link[1];
            this.remoteLinks = new Link[1];
            this.incomingList = new LinkedList();
            this.outgoingList = new LinkedList();
            this.channel = connection.AddSession(this);

            this.state = State.BeginSent;
            this.SendBegin(begin);
        }

        /// <summary>
        /// Gets the connection where the session was created.
        /// </summary>
        public Connection Connection
        {
            get { return this.connection; }
        }

        object ThisLock
        {
            get { return this; }
        }

        internal ushort Channel
        {
            get { return this.channel; }
        }

        internal void Abort(Error error)
{'fraction_non_alphanumeric': 0.1239174732552216, 'fraction_numerical': 0.003565970453387672, 'mean_word_length': 1.6674592391304348, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6386526', 'n_tokens_mistral': 1892, 'n_tokens_neox': 1841, 'n_words': 616}