Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data serialization fix #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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