예제 #1
0
        private async Task PublishDataToTrafficReaderAsync(TcpDataReader trafficReader)
        {
            try
            {
#if NETSTANDARD2_1
                var buffer = await trafficReader.AllocateBufferToWriteAsync(_cancellationToken.Token);

                var readSize =
                    await SocketStream.ReadAsync(buffer, _cancellationToken.Token);


                while (readSize > 0)
                {
                    SocketStatistic.WeHaveReceiveEvent(readSize);

                    trafficReader.CommitWrittenData(readSize);

                    buffer = await trafficReader.AllocateBufferToWriteAsync(_cancellationToken.Token);

                    readSize =
                        await SocketStream.ReadAsync(buffer, _cancellationToken.Token);
                }
#else
                var buffer = await trafficReader.AllocateBufferToWriteLegacyAsync(_cancellationToken.Token);

                var readSize =
                    await SocketStream.ReadAsync(buffer.buffer, buffer.start, buffer.len, _cancellationToken.Token);

                while (readSize > 0)
                {
                    SocketStatistic.WeHaveReceiveEvent(readSize);

                    trafficReader.CommitWrittenData(readSize);

                    buffer = await trafficReader.AllocateBufferToWriteLegacyAsync(_cancellationToken.Token);

                    readSize =
                        await SocketStream.ReadAsync(buffer.buffer, buffer.start, buffer.len, _cancellationToken.Token);
                }
#endif
            }
            catch (Exception e)
            {
                Log.InvokeExceptionLog(this, e, true);
            }
            finally
            {
                Log.InvokeInfoLog(this, "Disconnected from Traffic Reader Loop");
                trafficReader.Stop();
            }
        }