Template Class NetioPublisherTemplate

Nested Relationships

Nested Types

Class Documentation

template<SubscriptionEndpointContainer Container>
class NetioPublisherTemplate

Publisher class. Publishes data to a set of subscribers by tag.

The publisher class is responsible for sending data to a set of subscribers

A publisher opens a listen socket on a dedicated ASYNCMSG TCP backend that is used to receive subscription requests from subscribers and respond with an acknowledgement.

For the main dataflow, a NetioSender is used to send data to the subscribers. The connection type of this connectionis determined by the config passed to the constructor.

Three different modes of sending data are supported:

  • Buffered: Data is accumulated in a buffer and sent when the buffer is full or a timeout is reached (see flush_interval).

  • Send: Data is sent immediately using buffers (meaning the data is copied and the user can discard it immediately).

  • Zero-copy: Data is sent without copying it. The data must be in a registered memory region. It must also remain valid until the data has been sent.

Zero-copy mode requires to pass a key to track when all send operations beloning to the same publish operation have completed. A callback set by set_on_publish_completed will be invoked with the key.

Public Functions

explicit NetioPublisherTemplate(const NetioPublisherConfig &config, std::shared_ptr<BaseEventLoop> eventloop, EndPointAddress local_ep)

Constructor for publisher.

Parameters:
  • config – configuration of the network backend and buffering

  • eventloop – pointer to event loop that runs netio operations

  • local_ep – Endpoint on which we listen for subscription requests

NetioPublisherTemplate(const NetioPublisherTemplate&) = delete
NetioPublisherTemplate(const NetioPublisherTemplate&&) = delete
NetioPublisherTemplate() = delete
NetioPublisherTemplate &operator=(const NetioPublisherTemplate&) = delete
NetioPublisherTemplate &operator=(const NetioPublisherTemplate&&) = delete
~NetioPublisherTemplate() = default
inline NetioPublisherStatus publish(uint64_t tag, std::span<const iovec> data, bool retry, uint8_t user_status = 0)

Publish data to all subscribers of a tag.

If the retry parameter is true only the endpoints that failed on the previous attempt are tried this time.

Parameters:
  • tag – The tag being published

  • data – The data to publish

  • retry – Flag for first try at publish or a retry of failed subscriptions

  • user_status – User supplied status code to be added to header

Return values:
  • NetioPublisherStatus::OK – Publish succeded to all subscibers

  • NetioPublisherStatus::NO_RESOURCES – publish failed to one or more subscribers due to a lack of resources. A retry may succeed

  • NetioPublisherStatus::FAILED – publish to at least one subscriber failed but a retry will not work

  • NetioPublisherStatus::NO_SUBSCRIPTIONS – There are currently no subscribers for this tag

inline NetioPublisherStatus publish(uint64_t tag, std::span<const uint8_t> data, bool retry, uint8_t user_status = 0)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

inline NetioPublisherStatus publish(uint64_t tag, std::span<const iovec> data, bool retry, uint8_t user_status, uint64_t key)

Publish data to all subscribers of a tag in zero-copy mode.

If the retry parameter is true only the endpoints that failed on the previous attempt are tried this time.

Parameters:
  • tag – The tag being published

  • data – The data to publish

  • retry – Flag for first try at publish or a retry of failed subscriptions

  • user_status – User supplied status code to be added to header

  • key – Key for zero copy sending (to be returned once operation compelted)

Return values:
  • NetioPublisherStatus::OK – Publish succeded to all subscibers

  • NetioPublisherStatus::NO_RESOURCES – publish failed to one or more subscribers due to a lack of resources. A retry may succeed

  • NetioPublisherStatus::FAILED – publish to at least one subscriber failed and none succeeded (retry will not work and no completion callback will be triggered)

  • NetioPublisherStatus::PARTIALLY_FAILED – publish to at least one subscriber failed but a at least one send succeeded (retry will not work but a completion callback wll be triggered)

  • NetioPublisherStatus::NO_SUBSCRIPTIONS – There are currently no subscribers for this tag

inline NetioPublisherStatus publish(uint64_t tag, std::span<uint8_t> data, bool retry, uint8_t user_status, uint64_t key)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

NetioPublisherStatus flush_buffer()

Flush current buffer for all subscriber endpoints.

Returns:

NO_RESOURCES if any sender returned it, FAILED if any returned that, OK otherwise

inline EndPointAddress get_endpoint() const

Get the actual endpoint address the publisher is listening on.

This may be different to the endpoint given to the constructor if no port was specified at that time.

Returns:

address of local endpoint

PublisherStats get_stats()

Get the current statistics for the publisher.

Returns:

PublisherStats structure containing the current stats

void set_on_subscription(const CbSubscriptionReceived &cb)

Set a callback function to be called on subscription.

Parameters:

cb – Callback function

void set_on_unsubscription(const CbUnsubscriptionReceived &cb)

Set a callback function to be called on unsubscription.

Parameters:

cb – Callback function

void set_on_resource_available(const CbResourceAvailable &cb)

Set a callback function to be called when an unspecified resource becomes avalable.

Parameters:

cb – Callback function

void set_on_publish_completed(const CbPublishCompleted &cb)

Set a callback function to be called when data has been sent to all subscribers.

Parameters:

cb – Callback function

template<SubscriptionEndpointContainer Container>
void handle_send_completion(std::uint64_t key)