Skip to content

Commit

Permalink
Add locking to send
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Rogers committed Nov 25, 2013
1 parent ea52a9b commit be3abff
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions projects/CommSample/source/CommSample.Core/MemoryChannel.cs
Expand Up @@ -68,18 +68,21 @@ public Task<int> ReceiveAsync(byte[] buffer)

public void Send(byte[] buffer)
{
this.ThrowIfDisposed();
int bytesReceived;
if (this.pendingReceive != null)
{
bytesReceived = this.pendingReceive.AddData(buffer);
}
else
lock (this.excessBuffers)
{
bytesReceived = 0;
}
this.ThrowIfDisposed();
if (this.pendingReceive != null)
{
bytesReceived = this.pendingReceive.AddData(buffer);
}
else
{
bytesReceived = 0;
}

this.AddExcess(buffer, bytesReceived, false);
this.AddExcess(buffer, bytesReceived, false);
}

if (bytesReceived > 0)
{
Expand Down

0 comments on commit be3abff

Please sign in to comment.