Exemplo n.º 1
0
        private async void HandshakeWriting()
        {
            var writer = _handshakeOutpipe.Alloc();

            _state.StartHandshake(ref writer);
            if (writer.BytesWritten > 0)
            {
                await writer.FlushAsync();
            }
            else
            {
                writer.Commit();
            }
            while (true)
            {
                while (true)
                {
                    var result = await _handshakeOutpipe.ReadAsync();

                    var buffer = result.Buffer;
                    if (result.IsCompleted && result.Buffer.IsEmpty)
                    {
                        break;
                    }
                    try
                    {
                        while (buffer.Length > 0)
                        {
                            ReadableBuffer messageBuffer;
                            if (buffer.Length <= RecordProcessor.PlainTextMaxSize)
                            {
                                messageBuffer = buffer;
                                buffer        = buffer.Slice(buffer.End);
                            }
                            else
                            {
                                messageBuffer = buffer.Slice(0, RecordProcessor.PlainTextMaxSize);
                                buffer        = buffer.Slice(RecordProcessor.PlainTextMaxSize);
                            }
                            writer = _lowerConnection.Output.Alloc();
                            RecordProcessor.WriteRecord(ref writer, RecordType.Handshake, messageBuffer, _state);
                            await writer.FlushAsync();
                        }
                        _state.DataForCurrentScheduleSent.Set();
                    }
                    finally
                    {
                        _handshakeOutpipe.AdvanceReader(buffer.Start, buffer.End);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private async void ApplicationWriting()
        {
            try
            {
                while (true)
                {
                    var result = await _inputPipe.ReadAsync();

                    var buffer = result.Buffer;
                    try
                    {
                        while (buffer.Length > 0)
                        {
                            ReadableBuffer messageBuffer;
                            if (buffer.Length <= RecordProcessor.PlainTextMaxSize)
                            {
                                messageBuffer = buffer;
                                buffer        = buffer.Slice(buffer.End);
                            }
                            else
                            {
                                messageBuffer = buffer.Slice(0, RecordProcessor.PlainTextMaxSize);
                                buffer        = buffer.Slice(RecordProcessor.PlainTextMaxSize);
                            }
                            var writer = _lowerConnection.Output.Alloc();
                            RecordProcessor.WriteRecord(ref writer, RecordType.Application, messageBuffer, _state);
                            await writer.FlushAsync();
                        }
                        _state.DataForCurrentScheduleSent.Set();
                        if (result.IsCompleted && buffer.IsEmpty)
                        {
                            var output = _lowerConnection.Output.Alloc();
                            Alerts.AlertException.WriteAlert(ref output, Alerts.AlertLevel.Warning, Alerts.AlertDescription.close_notify, _state);
                            await output.FlushAsync();

                            break;
                        }
                    }
                    finally
                    {
                        _inputPipe.AdvanceReader(buffer.Start, buffer.End);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Exception was thrown {ex}");
                //Nom Nom
            }
            _lowerConnection.Output.Complete();
        }
Exemplo n.º 3
0
        private async Task HandshakeReading()
        {
            var result = await _handshakePipe.ReadAsync();

            var buffer = result.Buffer;

            try
            {
                ReadableBuffer          messageBuffer;
                Handshake.HandshakeType handshakeType;
                while (Handshake.HandshakeProcessor.TryGetFrame(ref buffer, out messageBuffer, out handshakeType))
                {
                    await _state.HandleHandshakeMessage(handshakeType, messageBuffer, _handshakeOutpipe);
                }
            }
            finally
            {
                _handshakePipe.AdvanceReader(buffer.Start, buffer.End);
            }
        }
Exemplo n.º 4
0
 public void Advance(ReadCursor consumed, ReadCursor examined)
 {
     _pipe.AdvanceReader(consumed, examined);
 }