private void EnsureCapacity(int size)
        {
            // return the old segment and get a new, bigger one
            var newSegment = BufferManager.GetSegment(size);

            _segment.CopyTo(newSegment, _length);
            m_Position = m_Position - _segment.Offset + newSegment.Offset;

            _segment.DecrementUsage();
            _segment = newSegment;
        }
        private void ProcessRecieve(SocketAsyncEventArgs args)
        {
            try
            {
                var bytesReceived = args.BytesTransferred;

                if (args.BytesTransferred == 0)
                {
                    OnSocketClosed();
                }
                else
                {
                    unchecked
                    {
                        _bytesReceived += (uint)bytesReceived;
                    }

                    Interlocked.Add(ref _totalBytesReceived, bytesReceived);

                    if (this.DataArrivals(_bufferSegment))
                    {
                        _offset = 0;
                        _bufferSegment.DecrementUsage();
                        _bufferSegment = Buffers.CheckOut();
                    }
                    else
                    {
                        EnsureBuffer();
                    }

                    this.Receive();
                }
            }
            catch (ObjectDisposedException)
            {
                OnSocketClosed();
            }
            catch (Exception)
            {
                OnSocketClosed();
            }
            finally
            {
                args.Completed -= ReceiveAsyncComplete;
                SocketHelpers.ReleaseSocketArg(args);
            }
        }