public override async Task FlushAsync(CancellationToken cancellationToken)
        {
            CheckNotDisposed();

            if (!IsOpen)
            {
                throw new TTransportException(TTransportException.ExceptionType.NotOpen);
            }

            //ArraySegment<byte> bufSegment;
            //_writeBuffer.TryGetBuffer(out bufSegment);
            //var buf = bufSegment.Array;
            var buf = _writeBuffer.ToArray();

            //var len = (int)_writeBuffer.Length;
            var dataLen = (int)_writeBuffer.Length - HeaderSize;

            if (dataLen < 0)
            {
                throw new InvalidOperationException(); // logic error actually
            }

            // Inject message header into the reserved buffer space
            EncodeFrameSize(dataLen, buf);

            // Send the entire message at once
            await _transport.WriteAsync(buf, cancellationToken).ConfigureAwait(false);

            InitWriteBuffer();

            await _transport.FlushAsync(cancellationToken).ConfigureAwait(false);
        }
        public override async Task FlushAsync(CancellationToken cancellationToken)
        {
            CheckNotDisposed();

            if (!IsOpen)
            {
                throw new TTransportException(TTransportException.ExceptionType.NotOpen);
            }

            if (_outputBuffer.Length > 0)
            {
                //ArraySegment<byte> bufSegment;
                var data = _outputBuffer.ToArray(); // TryGetBuffer(out bufSegment);

                await _transport.WriteAsync(data /*bufSegment.Array*/, cancellationToken).ConfigureAwait(false);

                _outputBuffer.SetLength(0);
            }

            await _transport.FlushAsync(cancellationToken).ConfigureAwait(false);
        }