Skip to main content
Version: 0.16.0

Streams to clients

A stream's data reaches a client on a path of its own, apart from the requests that started it. Starting a stream makes it flow for everyone; subscribing delivers a copy to one client. Which path carries the copy depends on what the client can open: a socket on the host, frames on its own connection, or a WebSocket in a browser. A stream flows from a Plugin unit to the Core on a transport of its own (streams and transports), and this page is the other half: starting and subscribing, the delivery paths, reading a stream's ring directly, what each preserves, and what ends a delivery.

Two acts, and they are not the same one​

ActMeansWho else it affects
stream.startmake the stream flow at all — the Core activates it on the unit's Session and the unit begins emittingeveryone: a stream is a property of the unit, not of the client that asked
stream.subscribedeliver a copy of what is flowing to this clientnobody else
  • Subscribing to a stream that is not flowing is legal, and carries nothing until it flows. The answer says whether the stream is flowing, so subscribing first and starting second — the order that misses nothing — is not a race.
  • Starting a stream is withdrawn from a suspended channel; subscribing is not (arbitration).

The delivery paths​

What carries a stream to a client is decided by what the client can open, never by what the data means.

The channelThe deliveryThe client
local, bound as a local socketa per-subscriber socket at plugins/<unit>/subscribers/<stream>/<n>.sock, created when the subscription is granted; the Core listens and the client connects. A stream socket, each frame after its length, where the client's library offered it; otherwise a packet socketis on the host, and can open it
local, bound as a local socket, for a stream on the shared ring, where the client's library offered to read itthe ring itself; the per-subscriber socket carries no frame and is the delivery's lifelineis on the host, and can map its memory
local, bound on a loopback or routable addressstream-delivery frames on the channel's own connection, apart from the control shapecannot reach a path in the instance's tree
http+wsone binary WebSocket for this stream, at the path the answer namesspeaks nothing else
  • The answer to stream.subscribe says where the data will arrive — a path, or the identity of the delivery on the connection the client holds. A client never derives it.
  • The subscriber's identity is a counter, not a name the client chooses: decimal, zero-padded to 8 digits, unique within that unit and stream for the life of the instance, never reused.
  • stream.subscribe names what the client's library can read: the stream socket with a length, the shared ring, both or neither. The Core answers with one of them, and a library that names neither is given the packet socket.
  • On a stream socket each frame is preceded by its length, a u32, little-endian (streams and transports).

Reading the ring directly​

A client on the host may read a stream carried on the shared ring from the ring itself, so that a frame is written once by the unit and copied by nobody on its way.

who maya client attached to a local socket, whose library offered the ring at stream.subscribe, on a stream the unit publishes on the ring
what the answer saysthat the delivery is the shared object, and the per-subscriber socket to connect to
at each activationone byte on that socket, carrying a descriptor of that activation's ring opened for reading alone
at each stopa message of length zero; the library reads that ring no more
the socket closingthe delivery's end
  • The Core still grants, creates, hands over and ends. The subscription is checked against the same scope, the ring is the Core's object, and a stop on any route reaches the reader on the lifeline.
  • A reader slower than the unit meets gaps in the sequence, which the stream declared it tolerates. It is never released for falling behind.
  • A remote client and a browser are relayed as before, and so is a client whose library offers nothing.
  • The ring's layout is the one the unit writes (streams and transports).

What every path preserves​

Preserved
the stream identityone delivery carries one stream
the sequence, unchangeda gap means loss, a decrease means reorder
the sender's clock at emissiona consumer plotting against time uses the instrument's moment
the payload, opaquethe Core transports it and does not interpret it

A stream that tolerates nothing arrives complete and in order; one that tolerates loss may arrive with gaps, and the sequence is how the client knows which. A delivery never adds a guarantee the producing side did not give, and never removes one it did.

What ends a delivery​

CauseThe deliveryThe client learns
stream.unsubscribereleased, and what carried it removedfrom the answer
the channel detachesreleased with everything the connection heldnothing — it is gone
the unit's Session endsreleased: the Session takes every stream with itunit.state.changed, and unit.stream.stopped
the instance stopschannels drain, and everything is releasedinstance.stopping
the stream is stopped — by this client, another, or an administrative callerkept, carrying nothingunit.stream.stopped, with the reason
the channel is suspended darkkept, delivering nothing until channel.resumedchannel.suspended
the client falls behind — more than 1024 frames held for itreleased; no frame is ever dropped from itits socket closes, or the delivery completes, ended by the Core
a client reading the ring directly falls behindkept: it meets gaps in the sequencefrom the sequence
the Core cannot write to itreleased, and channel.delivery.failed published with the reasonits socket closes
  • A delivery kept across a stop means a client does not have to subscribe again when the stream resumes.
  • A client that falls behind reads everything that reached it and then the end, and subscribes again from what flows next. The figure is not declarable.
  • Cleanup is the Core's on every route, so a client that crashes mid-stream strands nothing.

Nothing streams from a client into a unit​

There is no client-produced stream. Continuous input from an interface reaches a unit as commands — one instruction per value, in the control shape, each acknowledged.