Esempio n. 1
0
        public TcpSocketListener(ILogger logger, int clientCapacity, int maxPacketSize, int packetQueueCapacity)
        {
            this._logger = logger ?? throw new ArgumentNullException(nameof(logger));

            this.Clients      = new TcpClients(logger, clientCapacity);
            this._tcpReceiver = new TcpStreamMessageReader(logger, maxPacketSize, packetQueueCapacity);

            this.MaxPacketSize       = maxPacketSize;
            this.PacketQueueCapacity = packetQueueCapacity;
        }
Esempio n. 2
0
        public TcpSocketClient(ILogger logger, int maxPacketSize, int packetQueueCapacity)
        {
            this._client = new TcpClient(AddressFamily.InterNetworkV6);

            this._receiveBuffer = new TcpReceiveBuffer(maxPacketSize, packetQueueCapacity);
            this._tcpReceiver   = new TcpStreamMessageReader(logger, maxPacketSize, packetQueueCapacity);

            this._requestAsyncStates           = new RequestAsyncState[packetQueueCapacity];
            this._freeRequestAsyncStateIndices = new int[packetQueueCapacity];
            this._idToRequestAsyncStateIndex   = new Dictionary <int, int>(packetQueueCapacity);

            this._requestAsyncStateCount     = 0;
            this._freeRequestAsyncStateCount = 0;

            this._receiveBuffer.OnWriteComplete = this.OnWriteComplete;
            this.OnCancelResponseTcs            = OnSendAsyncCancellation;

            this._stateLock       = new object();
            this._streamWriteLock = new object();
        }