예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ConcurrentRequestExecutor"/> class with the specified
        /// connection and memory pool.
        /// </summary>
        /// <param name="connection">The <see cref="S7Connection"/> that is used for this executor.</param>
        /// <param name="memoryPool">
        /// The <see cref="MemoryPool{T}" /> that is used for request and response memory allocations.
        /// </param>
        public ConcurrentRequestExecutor(S7Connection connection, MemoryPool <byte>?memoryPool = default)
        {
            if (connection.Parameters == null)
            {
                Sally7CommunicationSetupException.ThrowConnectionParametersNotSet();
            }

            Connection      = connection;
            socket          = connection.TcpClient.Client;
            bufferSize      = connection.Parameters.GetRequiredBufferSize();
            maxRequests     = connection.Parameters.MaximumNumberOfConcurrentRequests;
            this.memoryPool = memoryPool ?? MemoryPool <byte> .Shared;

            jobPool       = new JobPool(connection.Parameters.MaximumNumberOfConcurrentRequests);
            sendSignal    = new Signal();
            receiveSignal = new Signal();

            if (!sendSignal.TryInit())
            {
                Sally7Exception.ThrowFailedToInitSendingSignal();
            }
            if (!receiveSignal.TryInit())
            {
                Sally7Exception.ThrowFailedToInitReceivingSignal();
            }

            reader = new SocketTpktReader(socket);

#if !NETSTANDARD2_1_OR_GREATER && !NET5_0_OR_GREATER
            sendAwaitable = new SocketAwaitable(new SocketAsyncEventArgs());
#endif
        }