Skip to content

Commit

Permalink
Merge pull request #935 from Amberg/TrySendFrameLenghtFix
Browse files Browse the repository at this point in the history
Fix TrySendFrame if buffer is bigger than length
  • Loading branch information
somdoron authored Sep 11, 2020
2 parents 671cabc + e11ab8b commit e86706f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/NetMQ.Tests/OutgoingSocketExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Linq;
using System.Text;
using Xunit;

namespace NetMQ.Tests
Expand Down Expand Up @@ -322,5 +324,22 @@ public void TrySignalFailedTest()

Assert.False(socket.TrySignalOK());
}

[Fact]
public void TrySendFrameBiggerBufferThanLength()
{
var buffer = new byte[64];
var data = Encoding.ASCII.GetBytes("Hello there");
data.CopyTo(buffer, 0);
var socket = new MockOutgoingSocket((ref Msg msg, TimeSpan timeout, bool more) =>
{
Assert.Equal(TimeSpan.Zero, timeout);
Assert.True(data.SequenceEqual(msg.ToArray()));
Assert.False(more);
return true;
});

Assert.True(socket.TrySendFrame(TimeSpan.Zero, buffer, data.Length));
}
}
}
2 changes: 1 addition & 1 deletion src/NetMQ/OutgoingSocketExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public static bool TrySendFrame(this IOutgoingSocket socket, TimeSpan timeout, b
{
var msg = new Msg();
msg.InitPool(length);
data.CopyTo(msg);
data.Slice(0, length).CopyTo(msg);
if (!socket.TrySend(ref msg, timeout, more))
{
msg.Close();
Expand Down

0 comments on commit e86706f

Please sign in to comment.