Skip to main content

Module request

Module request 

Source
Expand description

Requests in: the multibulk decoder and the inline decoder.

This is the read half of the hot path and it does not allocate once a connection is warm. An argument is a range in the connection’s own read buffer, so the command layer works on the bytes the kernel delivered and nothing is copied on the way. The one exception is an inline request with escapes in it, which has to be unescaped somewhere, and that goes into a scratch buffer on the same Argv.

§The contract

A connection owns one Argv and one read buffer, and drives them like this:

  1. Read bytes and append them to the buffer. Never insert, never reorder.
  2. Call Argv::decode. On Step::Incomplete, go back to 1.
  3. On Step::Command, read the arguments, then drop consumed bytes from the front of the buffer, then go back to 2 in case the read carried more than one command.

The arguments are only valid between step 3 and the moment the buffer is drained, because they are ranges into it. That is the price of not copying and it is the reason the buffer is passed to Argv::arg rather than held.

Between calls the decoder remembers how far it got, so a 512 MiB value that arrives in ten thousand pieces is scanned once rather than ten thousand times. That is the difference between linear and quadratic on a slow link and it is why the resume state exists at all.

Structs§

Argv
A command’s arguments, and the decoder that fills them.

Enums§

Step
What a decode attempt produced.