Last active
March 18, 2017 18:05
-
-
Save Drawaes/d5d01d0ef5be2a7c28973719a7efc7fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private async Task WritingLoop() | |
{ | |
while(true) | |
{ | |
var reader = Task.WhenAny(_handshakePipe.Reader.ReadAsync(), _inputPipe.Reader.ReadAsync()); | |
RecordType recordType; | |
if (reader == handshakeReader) | |
{ | |
recordType = RecordType.Handshake; | |
} | |
else | |
{ | |
recordType = RecordType.Application; | |
} | |
var buffer = reader.Buffer; | |
while(buffer.Length > 0) | |
{ | |
//max record size = 16k - header - some crypto info | |
var messageBuffer = buffer.Slice(0, Min(buffer.Length, maxRecordLength)); | |
buffer = buffer.Slice(messageBuffer.Length); | |
var writer = _connection.Output.Alloc(); | |
writer.WriteBigEndian(recordType); | |
writer.WriteBigEndian(messageBuffer.Length + tagSize); | |
_recordHandler.Encrypt(ref writer, ref messageBuffer); | |
await writer.FlushAsync(); | |
} | |
reader.Advance(buffer.End); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment