public void SendMessage(CancellationToken cancellationToken) { communicationProtocol.LogInformation($"Start sending message {Id.ToByteString()}."); Data.Seek(0, SeekOrigin.Begin); SendMessageInChunks(cancellationToken); }
private void StartReading() { try { while (!cancellationToken.IsCancellationRequested) { communicationProtocol.LogInformation("Start message reader"); byte[] header = new byte[HeaderSize]; int headerResult = readStream.Read(header, 0, header.Length); try { if (headerResult == 0) { throw new ClientDisconnectedException(); } int messageLength = ParseHeader(header); if (messageLength > 0) { ReadMessage(messageLength); } } catch (ClientDisconnectedException) { communicationProtocol.Disconnect(); } } communicationProtocol.LogInformation("Shutdown reader thread."); } catch (Exception) { //Do not log anything as any log will lead to another exception } }