View Source Barytherium.Network.Receiver (barytherium v0.2.0)
The Receiver
is designed to work with Barytherium.Network
to move frames from
an already opened socket, reporting status back to an instance of Barytherium.Network
,
and frames back to a listener process, including a Barytherium.Network.Sender
pid when
it does so. This is implemented as a loop with no message receiving capabilities, outside
of the reply made to a call to Barytherium.Network
to report the CONNECTED frame, for
which it receives back a tuple which sets out the heartbeats. The loop ends on most error
conditions, including those which can be created elsewhere (e.g. if it gets
{:error, :closed}
when calling recv).
Link to this section Summary
Link to this section Functions
@spec loop(%{ socket: port(), listener_pid: pid(), network_pid: pid(), sender_pid: pid(), parse_state: Barytherium.Frame.parse_state(), hb_recv: integer() | 0 | nil }) :: any()
Pulls data from socket and parses it for STOMP frames until there's an error condition.
Frames are passed via casts to listener_pid
, and include a list of frames, and the
process ID of the corresponding Barytherium.Network.Sender
. A frame list will always
include at least one frame.
spec: {:barytherium, :frames, {list(Barytherium.Frame.t()), pid()}}
Errors are casts to listener_pid
proxied via the corresponding Barytherium.Network
.
If an error is emitted, the socket is closed and the loop ends.
spec: {:barytherium, :disconnect, atom()}
Currently, you can expect :timeout, :closed, and :parse_error in the final position.
Note that :timeout from Receiver
expresses either a heartbeat timeout, or a pre-defined
timeout of 5000ms while waiting for the CONNECTED frame, there is currently no other
mechanism to specify receive timeout.
When the receiver parses the first frame (which must be a CONNECTED frame), it passes
this on in the ordinary way, but also calls the corresponding Barytherium.Network
with
{:connected_frame, frame}
. The reply to this message should be a tuple of two integers
which express the agreed heartbeats for sending and receiving, respectively.
Start the receiver loop as a linked task, see loop/1
.