Skip to content

Commit

Permalink
Added a ReadBufferMaxSize property
Browse files Browse the repository at this point in the history
  • Loading branch information
mgnsm committed Mar 6, 2024
1 parent a3393e8 commit 94f6522
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Source/Millistream.Streaming/IMarketDataFeed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ public interface IMarketDataFeed<TCallbackUserData, TStatusCallbackUserData>
/// </summary>
public ulong MessageClass { get; }

/// <summary>
/// Gets or sets the current size of the internal read buffer.
/// </summary>
public uint ReadBufferMaxSize { get; set; }

/// <summary>
/// Consumes data sent from the server. If there currently is no data the function waits for <paramref name="timeout"/> number of seconds, if <paramref name="timeout"/> is zero (0) the function will return immediately. If <paramref name="timeout"/> is negative then the wait period is treated as number of microseconds instead of number of seconds (i.e. -1000 will wait a maximum of 1000µs).
/// </summary>
Expand Down
4 changes: 3 additions & 1 deletion Source/Millistream.Streaming/MDF_OPTION.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ internal enum MDF_OPTION
MDF_OPT_CRYPT_DIGEST,
MDF_OPT_CRYPT_CIPHER,
MDF_OPT_TIMEOUT,
MDF_OPT_HANDLE_DELAY
MDF_OPT_HANDLE_DELAY,
MDF_OPT_RBUF_SIZE,
MDF_OPT_RBUF_MAXSIZE
};
}
10 changes: 10 additions & 0 deletions Source/Millistream.Streaming/MarketDataFeed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,16 @@ public bool HandleDelay
/// </summary>
/// <remarks>The corresponding native function is mdf_get_mclass.</remarks>
public ulong MessageClass => _nativeImplementation.mdf_get_mclass != default ? _nativeImplementation.mdf_get_mclass(_feedHandle) : default;

/// <summary>
/// Gets or sets the current size of the internal read buffer.
/// </summary>
/// <exception cref="InvalidOperationException">The native value of the <see cref="MDF_OPTION.MDF_OPT_RBUF_MAXSIZE"/> option cannot be fetched or modified.</exception>
public uint ReadBufferMaxSize
{
get => (uint)GetUInt64Property(MDF_OPTION.MDF_OPT_RBUF_MAXSIZE);
set => SetProperty(MDF_OPTION.MDF_OPT_RBUF_MAXSIZE, value);
}
#endregion

#region Methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public void GetAndSetPropertiesTest()

Assert.AreEqual(0UL, mdf.ReceivedBytes);
Assert.AreEqual(0UL, mdf.SentBytes);
Assert.AreEqual(2048UL, mdf.ReadBufferMaxSize);

//HandleDelay
Assert.IsFalse(mdf.HandleDelay);
Expand Down Expand Up @@ -124,6 +125,10 @@ public void GetAndSetPropertiesTest()

_ = mdf.TimeDifferenceNs;

//ReadBufferMaxSize
mdf.ReadBufferMaxSize = uint.MaxValue;
Assert.AreEqual(uint.MaxValue, mdf.ReadBufferMaxSize);

//Allocations
long allocatedBytes = GetTotalAllocatedBytes();
_ = mdf.FileDescriptor;
Expand Down
21 changes: 19 additions & 2 deletions Tests/Millistream.Streaming.UnitTests/MarketDataFeedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void GetErrorCodeTest()
}

[TestMethod]
public void GetAndSetReceivedBytesTest() =>
public void GetReceivedBytesTest() =>
GetUInt64Property(MDF_OPTION.MDF_OPT_RCV_BYTES, mdf => mdf.ReceivedBytes);

[TestMethod]
Expand All @@ -97,7 +97,7 @@ public void SetReceivedBytesTest()
}

[TestMethod]
public void GetAndSetSentBytesTest() => GetUInt64Property(MDF_OPTION.MDF_OPT_SENT_BYTES, mdf => mdf.SentBytes);
public void GetSentBytesTest() => GetUInt64Property(MDF_OPTION.MDF_OPT_SENT_BYTES, mdf => mdf.SentBytes);

[TestMethod]
public void SetSentBytesTest()
Expand Down Expand Up @@ -448,6 +448,23 @@ public void GetMessageClassTest()
Assert.AreEqual(MessageClass, mdf.MessageClass);
}

[TestMethod]
public void GetReadBufferMaxSizeTest() => GetUInt64Property(MDF_OPTION.MDF_OPT_RBUF_MAXSIZE, mdf => mdf.ReadBufferMaxSize);

[TestMethod]
public void SetReadBufferMaxSizeTest()
{
const uint ReadBufferMaxSize = 5000;
Mock<INativeImplementation> nativeImplementation = new();
Setup(nativeImplementation, MDF_OPTION.MDF_OPT_RBUF_MAXSIZE, ReadBufferMaxSize);

using MarketDataFeed mdf = new()
{
ReadBufferMaxSize = ReadBufferMaxSize
};
nativeImplementation.Verify();
}

[TestMethod]
public void GetAndSetDataCallbackTest()
{
Expand Down

0 comments on commit 94f6522

Please sign in to comment.