private bool HandleReadBytes(int bytesRead) { try { if (bytesRead == 0) { HandleDisconnect(null); Dispose(); return(false); } _readBuffer.Count += bytesRead; var lastOffset = -1; while (_readBuffer.RemainingLength != 0 && lastOffset != _readBuffer.Position) { lastOffset = _readBuffer.Position; var msg = new Received(_socket.RemoteEndPoint, _stream, _readBuffer); SendUpstream(msg); } _logger.Debug(string.Format("Compacting since we got {1} bytes left from pos {0}.", _readBuffer.Position, _readBuffer.RemainingLength)); _readBuffer.Compact(); return(true); } catch (Exception err) { Logger.Warning("A pipeline handler threw an exception.", err); Pipeline.SendUpstream(new PipelineFailure(err)); Dispose(); return(false); } }
public void TestCompact() { var buffer = Encoding.ASCII.GetBytes("0123456789"); var slice = new BufferSlice(buffer, 0, buffer.Length, buffer.Length); slice.Position = 5; slice.Compact(); var str = Encoding.ASCII.GetString(slice.Buffer, 0, 5); Assert.Equal("56789", str); }