Beispiel #1
0
        private void TryParsingReceivedData(ConcurrentQueue <ReceivedData> receiveQueue)
        {
            if (!EnterParsing())
            {
                return;
            }

            try
            {
                var dataList    = new List <ReceivedData>(receiveQueue.Count);
                var segmentList = new List <ArraySegment <byte> >();

                ReceivedData data;
                while (receiveQueue.TryDequeue(out data))
                {
                    dataList.Add(data);
                    segmentList.Add(new ArraySegment <byte>(data.Buf.Array, data.Buf.Offset, data.DataLen));
                }

                _framer.UnFrameData(segmentList);

                for (int i = 0, n = dataList.Count; i < n; ++i)
                {
                    _receiveDataBufferPool.Return(dataList[i].Buf.Array);
                }
            }
            finally
            {
                ExitParsing();
            }
        }
Beispiel #2
0
        private void TryParsingReceivedData()
        {
            if (!EnterParsing())
            {
                return;
            }

            try
            {
                var dataList    = new List <ReceivedData>(_receiveQueue.Count);
                var segmentList = new List <ArraySegment <byte> >();

                ReceivedData data;
                while (_receiveQueue.TryDequeue(out data))
                {
                    dataList.Add(data);
                    segmentList.Add(new ArraySegment <byte>(data.Buf.Array, data.Buf.Offset, data.DataLen));
                }

                _framer.UnFrameData(segmentList);

                for (int i = 0, n = dataList.Count; i < n; ++i)
                {
                    _receiveDataBufferPool.Return(dataList[i].Buf.Array);
                }
            }
            catch (Exception ex)
            {
                _logger.Error("Parsing received data error.", ex);
            }
            finally
            {
                ExitParsing();
            }
        }
        public void Send(Message msg)
        {
            _sentMessagesMeter.Mark();
            var buffer = _bufferPool.Take(_config.MaxMessageSizeBts);

            try
            {
                using (var stream = new MemoryStream(buffer))
                {
                    MessageSerializer.Serialize(msg, stream);
                    TransportChannel.Send(msg.Priority, msg.Reliability, new ArraySegment <byte>(buffer, 0, (int)stream.Position));
                }

                Logger.NetChannelSentMessage(Node, this, msg);
            }
            finally
            {
                _bufferPool.Return(buffer);
            }
        }
Beispiel #4
0
 /// <summary>
 /// Returns <paramref name="buffer"/> to the <see cref="IBufferPool"/>.
 /// </summary>
 /// <param name="buffer">The byte array to be returned to the pool.</param>
 public static void Return(byte[] buffer)
 {
     s_bufferPool.Return(buffer);
 }
Beispiel #5
0
 private static void FreeBuffer(byte[] buffer) => BufferPool?.Return(buffer);
Beispiel #6
0
 public void Return()
 {
     pool.Return(this);
 }