FakeRiak.Connection (fake_riak v0.1.0)

Copy Markdown View Source

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.

Summary

Functions

serve(socket, handler)

@spec serve(:gen_tcp.socket(), module()) :: :ok