Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions IpcStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class IpcStream : IDisposable

private bool _disposed = false;
protected bool encrypted = false;
private object _lockObject = new object();

/// <summary>
/// Constructor
Expand Down Expand Up @@ -119,16 +120,19 @@ protected async Task<byte[]> ReadBytesAsync()
/// <param name="buffer">byte buffer</param>
protected void WriteBytes(byte[] buffer)
{
int length = buffer.Length;
if (length > UInt16.MaxValue)
throw new InvalidOperationException("Message is too long");
lock (_lockObject)
{
int length = buffer.Length;
if (length > UInt16.MaxValue)
throw new InvalidOperationException("Message is too long");

// write message length
BaseStream.Write(new byte[] { (byte)(length / 256), (byte)(length & 255) }, 0, 2);
// write message length
BaseStream.Write(new byte[] {(byte) (length / 256), (byte) (length % 256)}, 0, 2);

// write message
BaseStream.Write(buffer, 0, length);
BaseStream.Flush();
// write message
BaseStream.Write(buffer, 0, length);
BaseStream.Flush();
}
}

/// <summary>
Expand Down