COROIO: NNet::NActors::TThreadedInbound< TPoller, TDelivery, TEnvelopeReader > Class Template Reference
COROIO
Loading...
Searching...
No Matches
NNet::NActors::TThreadedInbound< TPoller, TDelivery, TEnvelopeReader > Class Template Reference

Accepts and reads the inbound connections of an actor system on an I/O thread. More...

#include <threaded_inbound.hpp>

Public Types

using TSocket = typename TPoller::TSocket

Public Member Functions

 TThreadedInbound (TPoller &poller, TSocket listener, TNodeId nodeId, TDelivery &delivery, std::function< void(const std::string &)> logger={})
 TThreadedInbound (TPoller &poller, TSocket listener, TNodeId nodeId, TDelivery &delivery, const TMessagesFactory &factory, std::function< void(const std::string &)> logger={})
 ~TThreadedInbound ()
 Destroys the coroutines first: they wait on the sockets.
 TThreadedInbound (const TThreadedInbound &)=delete
TThreadedInbound & operator= (const TThreadedInbound &)=delete
size_t Connections () const
 Connections accepted and not forgotten yet. On the I/O thread, or while its loop does not run.

Detailed Description

template<typename TPoller, typename TDelivery, typename TEnvelopeReader = TZeroCopyEnvelopeReader>
class NNet::NActors::TThreadedInbound< TPoller, TDelivery, TEnvelopeReader >

Accepts and reads the inbound connections of an actor system on an I/O thread.

The accept loop and one coroutine per connection run on poller, which belongs to another thread (see TLoopThread). A connection reads its socket into its own TEnvelopeReader, as a connection of TActorSystem::Serve(TSocket) does, and hands the envelopes of every read to delivery in one TEnvelopeBatch. Envelopes for another node are dropped and logged, as there.

With a factory, the payloads of the types registered with TMessagesFactory::RegisterDeserializer are deserialized here, on the I/O thread: the actors get Near blobs of them, all other envelopes go on unchanged. An envelope whose deserializer throws is dropped and logged. The bytes counted against the limit of the delivery are those read.

TDelivery is the way to the actors; TQueuedDelivery is the one for an actor system on another thread. Both calls are made on the I/O thread:

  • bool Full() const — while it is true, the connections do not read: the bytes stay in the sockets, and TCP slows the senders down. A connection asks before each read, so each one hands over at most one read beyond the limit of the delivery.
  • void Deliver(std::unique_ptr<TEnvelopeBatch> batch).

A finished connection closes its socket; the inbound forgets it at the next accept.

TLoop<TDefaultPoller> loop; // the loop of the actor system
TLoopThread<TDefaultPoller> io; // before sys: it outlives the nodes on io
TActorSystem sys(&loop.Poller(), 1);
sys.AddNode(2, ...); // a TNode on loop or a TThreadedNode on io
TQueuedDelivery delivery(sys);
TAddress address{"::", 9001};
TDefaultPoller::TSocket listener(io.Poller(), address.Domain());
listener.Bind(address);
listener.Listen();
io.Poller(), std::move(listener), 1, delivery);
sys.ServeOutbound();
io.Start();
...
io.Stop();
io.Join();
// inbound, delivery and sys with its nodes are destroyed here, then io and loop
Single-threaded actor runtime.
Definition actorsystem.hpp:61
Delivery of TThreadedInbound to an actor system on another thread.
Definition threaded_inbound.hpp:52
Accepts and reads the inbound connections of an actor system on an I/O thread.
Definition threaded_inbound.hpp:191
A class representing an IPv4 or IPv6 address (with port).
Definition address.hpp:38
int Domain() const
Gets the domain (address family) of the stored address.
Definition address.cpp:45
A thread that runs its own event loop.
Definition loop_thread.hpp:61
void Join()
Waits for the loop thread to exit. Owner thread only; does nothing if it is not running.
Definition loop_thread.hpp:131
TPoller & Poller()
The poller of the loop. See the class description for which thread may use it.
Definition loop_thread.hpp:86
void Start(TFailureHook onFailure={})
Starts the loop thread. Call once, from the owner thread.
Definition loop_thread.hpp:99
Event loop that drives a poller backend.
Definition loop.hpp:35
TPoller & Poller()
Provides access to the underlying poller instance.
Definition loop.hpp:62
NNet::TSocket TSocket
Alias for the socket type.
Definition poll.hpp:42
Template Parameters
TPollerPoller type of the I/O thread; determines the socket type.
TDeliveryReceives the batches, see above.
TEnvelopeReaderTZeroCopyEnvelopeReader, which copies every payload into an allocation of its own, or TZeroCopyEnvelopeReaderV2, whose payloads point into its chunks and may be released on any thread.
Note
Construct it before the loop of poller starts and destroy it after that loop has stopped: both touch the poller. listener is a listening socket on poller.
The logger is called on the I/O thread.
Not available on Windows: I/O threads need TNotifier.

Constructor & Destructor Documentation

◆ TThreadedInbound() [1/2]

template<typename TPoller, typename TDelivery, typename TEnvelopeReader = TZeroCopyEnvelopeReader>
NNet::NActors::TThreadedInbound< TPoller, TDelivery, TEnvelopeReader >::TThreadedInbound ( TPoller & poller,
TSocket listener,
TNodeId nodeId,
TDelivery & delivery,
std::function< void(const std::string &)> logger = {} )
inline
Parameters
pollerPoller of the I/O thread.
listenerBound, listening socket on poller.
nodeIdNode of the actor system: envelopes for other nodes are dropped.
deliveryReceives the envelopes; outlives the inbound.
loggerOptional; called on the I/O thread.

◆ TThreadedInbound() [2/2]

template<typename TPoller, typename TDelivery, typename TEnvelopeReader = TZeroCopyEnvelopeReader>
NNet::NActors::TThreadedInbound< TPoller, TDelivery, TEnvelopeReader >::TThreadedInbound ( TPoller & poller,
TSocket listener,
TNodeId nodeId,
TDelivery & delivery,
const TMessagesFactory & factory,
std::function< void(const std::string &)> logger = {} )
inline

The same, and the payloads of the types factory can deserialize are deserialized on the I/O thread. factory outlives the inbound.


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