Generic, framing-agnostic connection serve loop.
Each protocol handler is a module implementing the FakeRiak.Protocol
behaviour. serve/2 owns the socket, buffers incoming bytes, and repeatedly
asks the handler to parse the next complete request out of the buffer.
The handler stays purely functional over the accumulated buffer: it never
touches the socket directly and never blocks waiting for more bytes. When the
buffer does not yet hold a full request it returns {:need_more, state} and
this loop takes care of reading more data.
A connection whose buffer grows past 16 MiB without ever containing a complete request is dropped, so a runaway client cannot balloon memory.
A handler on a plain-TCP connection can also request an in-band TLS upgrade
({:upgrade_tls, ...}, used for Riak's RpbStartTls): the loop sends the
acknowledgement in plaintext, terminates TLS on the same socket, and carries
the handler state over to the encrypted stream.
Summary
Functions
The per-connection buffer cap; handlers can size their own frame limits off it.
Types
Functions
The per-connection buffer cap; handlers can size their own frame limits off it.
@spec serve(:gen_tcp.socket() | :ssl.sslsocket(), module(), transport(), binary()) :: :ok