ravel
Deterministic simulation testing for C++. Seed a bug, replay it exact.
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
ravel::Channel Class Reference

A virtual, one-way, in-process channel between two named endpoints. More...

#include <network.hpp>

Classes

class  ReceiveAwaiter
 What receive() returns. It is only ever co_awaited. More...
 
class  TimedReceiveAwaiter
 Like ReceiveAwaiter, but gives up: yields nothing if no message has arrived once timeout virtual ticks have passed. More...
 

Public Member Functions

 Channel (ChannelId id, std::string from, std::string to, FaultSpec fault, Scheduler &scheduler, VirtualRng &rng, Trace &trace)
 Created by Simulation::add_channel; you do not construct one yourself.
 
 Channel (const Channel &)=delete
 Pending deliveries refer to this object, so it must never move.
 
Channel & operator= (const Channel &)=delete
 
const std::string & from () const noexcept
 The sending endpoint's name.
 
const std::string & to () const noexcept
 The receiving endpoint's name.
 
const FaultSpec & fault () const noexcept
 The fault settings this channel was created with.
 
void send (Message message)
 Applies the fault spec: the message is dropped, or delivered after a random delay.
 
ReceiveAwaiter receive () noexcept
 Waits for the next message: ravel::Message m = co_await channel.receive();
 
TimedReceiveAwaiter receive_within (VirtualClock::Tick timeout) noexcept
 Waits up to timeout ticks for a message: auto m = co_await channel.receive_within(50); The result is empty if none arrived in time.
 
void clear_inbox ()
 Throws away messages that were delivered but not yet received.
 

Detailed Description

A virtual, one-way, in-process channel between two named endpoints.

There are no real sockets: send() schedules delivery on the Scheduler, so a run never depends on actual network conditions.

channel.send("ping"); // never blocks ravel::Message m = co_await channel.receive(); // blocks until one arrives auto maybe = co_await channel.receive_within(50); // or gives up after 50 ticks

At most one task may wait to receive at a time.

Member Function Documentation

◆ clear_inbox()

void ravel::Channel::clear_inbox ( )
inline

Throws away messages that were delivered but not yet received.

Messages still in flight are unaffected. Meant for the receiving task itself, for instance when it restarts after a simulated crash; clearing under a receive that is about to return a message fails that receive.


The documentation for this class was generated from the following file: