Skip to content

Commit

Permalink
Support pub-sub messages larger than network buffer (#789)
Browse files Browse the repository at this point in the history
* Support pub-sub messages larger than network buffer

* move EnterAndGetResponseObject inside try

---------

Co-authored-by: Tal Zaccai <[email protected]>
  • Loading branch information
badrishc and TalZaccai authored Nov 12, 2024
1 parent 225a9ea commit 652b49f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions libs/server/Resp/PubSubCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ internal sealed unsafe partial class RespServerSession : ServerSessionBase
/// <inheritdoc />
public override unsafe void Publish(ref byte* keyPtr, int keyLength, ref byte* valPtr, int valLength, ref byte* inputPtr, int sid)
{
networkSender.EnterAndGetResponseObject(out dcurr, out dend);
try
{
networkSender.EnterAndGetResponseObject(out dcurr, out dend);
if (respProtocolVersion == 2)
{
while (!RespWriteUtils.WriteArrayLength(3, ref dcurr, dend))
Expand All @@ -36,10 +36,10 @@ public override unsafe void Publish(ref byte* keyPtr, int keyLength, ref byte* v
}
while (!RespWriteUtils.WriteBulkString("message"u8, ref dcurr, dend))
SendAndReset();
while (!RespWriteUtils.WriteBulkString(new Span<byte>(keyPtr + sizeof(int), keyLength - sizeof(int)), ref dcurr, dend))
SendAndReset();
while (!RespWriteUtils.WriteBulkString(new Span<byte>(valPtr + sizeof(int), valLength - sizeof(int)), ref dcurr, dend))
SendAndReset();

// Write key and value to the network
WriteDirectLargeRespString(new Span<byte>(keyPtr + sizeof(int), keyLength - sizeof(int)));
WriteDirectLargeRespString(new Span<byte>(valPtr + sizeof(int), valLength - sizeof(int)));

if (dcurr > networkSender.GetResponseObjectHead())
Send(networkSender.GetResponseObjectHead());
Expand All @@ -53,9 +53,9 @@ public override unsafe void Publish(ref byte* keyPtr, int keyLength, ref byte* v
/// <inheritdoc />
public override unsafe void PrefixPublish(byte* patternPtr, int patternLength, ref byte* keyPtr, int keyLength, ref byte* valPtr, int valLength, ref byte* inputPtr, int sid)
{
networkSender.EnterAndGetResponseObject(out dcurr, out dend);
try
{
networkSender.EnterAndGetResponseObject(out dcurr, out dend);
if (respProtocolVersion == 2)
{
while (!RespWriteUtils.WriteArrayLength(4, ref dcurr, dend))
Expand Down

0 comments on commit 652b49f

Please sign in to comment.