Ejemplo n.º 1
0
        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);

            InitWriteBuffer();

            await _transport.FlushAsync(cancellationToken);
        }
Ejemplo n.º 2
0
        private async Task RunTestAsync(Func <bool, Task <TProtocol> > factory)
        {
            var stop = new Stopwatch();

            var proto = await factory(true);

            stop.Start();
            await Testdata.WriteAsync(proto, Cancel.Token);

            await Transport.FlushAsync(Cancel.Token);

            stop.Stop();
            Console.WriteLine("RunTestAsync({0}): write = {1} msec",
                              GetProtocolTransportName(proto),
                              stop.ElapsedMilliseconds);

            var restored = new CrazyNesting();

            proto = await factory(false);

            stop.Start();
            await restored.ReadAsync(proto, Cancel.Token);

            stop.Stop();
            Console.WriteLine("RunTestAsync({0}): read = {1} msec",
                              GetProtocolTransportName(proto),
                              stop.ElapsedMilliseconds);
        }
Ejemplo n.º 3
0
        public override async Task FlushAsync(CancellationToken cancellationToken)
        {
            CheckNotDisposed();

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

            if (_outputBuffer.Length > 0)
            {
                var data = _outputBuffer.ToArray();

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

                _outputBuffer.SetLength(0);
            }

            await _transport.FlushAsync(cancellationToken);
        }