Commit b3c880b3 authored by Marc Gravell's avatar Marc Gravell

fix length vs position error in ReadLineTerminatedString

parent b0637c6f
......@@ -1140,15 +1140,13 @@ private RawResult ReadBulkString(in ReadOnlySequence<byte> buffer, ref BufferRea
private RawResult ReadLineTerminatedString(ResultType type, in ReadOnlySequence<byte> buffer, ref BufferReader reader)
{
int crlf = BufferReader.FindNextCrLf(reader);
int crlfOffsetFromCurrent = BufferReader.FindNextCrLf(reader);
if (crlfOffsetFromCurrent < 0) return RawResult.Nil;
if (crlf < 0) return RawResult.Nil;
var payload = buffer.Slice(reader.TotalConsumed, crlfOffsetFromCurrent);
reader.Consume(crlfOffsetFromCurrent + 2);
var inner = buffer.Slice(reader.TotalConsumed, crlf);
reader.Consume(crlf + 2);
return new RawResult(type, inner, false);
return new RawResult(type, payload, false);
}
void ISocketCallback.StartReading() => ReadFromPipe();
......@@ -1185,7 +1183,9 @@ public enum ConsumeResult
private ReadOnlySequence<byte>.Enumerator _iterator;
private ReadOnlySpan<byte> _current;
public ReadOnlySpan<byte> Span => _current;
public ReadOnlySpan<byte> OversizedSpan => _current;
public ReadOnlySpan<byte> SlicedSpan => _current.Slice(OffsetThisSpan, RemainingThisSpan);
public int OffsetThisSpan { get; private set; }
public int TotalConsumed { get; private set; }
public int RemainingThisSpan { get; private set; }
......@@ -1280,23 +1280,20 @@ public void Consume(int count)
bool haveTrailingCR = false;
do
{
var span = reader.Span;
if (reader.OffsetThisSpan != 0) span = span.Slice(reader.OffsetThisSpan);
if (span.IsEmpty)
if (reader.RemainingThisSpan == 0) continue;
var span = reader.SlicedSpan;
if (haveTrailingCR)
{
if(span[0] == '\n') return totalSkipped - 1;
haveTrailingCR = false;
}
else
{
if (haveTrailingCR && span[0] == '\n') return totalSkipped - 1;
int found = span.IndexOf(CRLF);
if (found >= 0) return totalSkipped + found;
int found = span.IndexOf(CRLF);
if (found >= 0) return totalSkipped + found;
haveTrailingCR = span[span.Length - 1] == '\r';
totalSkipped += span.Length;
}
haveTrailingCR = span[span.Length - 1] == '\r';
totalSkipped += span.Length;
}
while (reader.FetchNextSegment());
return -1;
......
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Pipelines;
using System.Linq;
using StackExchange.Redis;
class Program
{
static int Main()
{
var options = PipeOptions.Default;
Console.WriteLine(options.PauseWriterThreshold);
Console.WriteLine(options.ResumeWriterThreshold);
var s = new StringWriter();
try
{
#if DEBUG
Pipelines.Sockets.Unofficial.DebugCounters.SetLog(Console.Out);
// Pipelines.Sockets.Unofficial.DebugCounters.SetLog(Console.Out);
#endif
// it is sometimes hard to get the debugger to play nicely with benchmarkdotnet/xunit attached,
// so this is just a *trivial* exe
var config = new ConfigurationOptions
{
EndPoints = { "127.0.0.1" },
//TieBreaker = "",
//CommandMap = CommandMap.Create(new Dictionary<string, string>
//{
// ["SUBSCRIBE"] = null,
// ["PSUBSCRIBE"] = null,
//})
};
using (var conn = ConnectionMultiplexer.Connect(config, log: s))
{
Console.WriteLine("Connected");
var db = conn.GetDatabase();
db.StringSet("abc", "def");
var x = db.StringGet("abc");
Console.WriteLine(x);
//for (int i = 0; i < 10; i++)
//{
// Console.WriteLine($"Ping {i}");
// db.Ping();
//}
Execute(conn);
}
Console.WriteLine("Clean exit");
return 0;
......@@ -49,8 +38,23 @@ static int Main()
}
finally
{
Console.WriteLine();
Console.WriteLine(s);
// Console.WriteLine();
// Console.WriteLine(s);
}
}
private static void Execute(ConnectionMultiplexer conn)
{
int pageSize = 100;
RedisKey key = nameof(Execute);
var db = conn.GetDatabase();
db.KeyDelete(key);
for (int i = 0; i < 2000; i++)
db.SetAdd(key, "s" + i, flags: CommandFlags.FireAndForget);
int count = db.SetScan(key, pageSize: pageSize).Count();
Console.WriteLine(count == 2000 ? "Pass" : "Fail");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment