roo_transport
API Documentation for roo_transport
Loading...
Searching...
No Matches
link_transport.h
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4
5#include "roo_io/core/output_stream.h"
9
10namespace roo_transport {
11
13 public:
14 class StatsMonitor;
15
18
19 LinkTransport(PacketSender& sender, roo::string_view name,
22
23 // Starts the send thread.
24 void begin() { channel_.begin(); }
25
26 void end() { channel_.end(); }
27
28 // Supply an incoming packet received from the underlying transport.
29 void processIncomingPacket(const roo::byte* buf, size_t len);
30
31 // Establishes a new connection and returns the Link object representing it.
32 // The optional function parameter will be called when the link gets
33 // disconnected.
34 Link connect(std::function<void()> disconnect_fn = nullptr);
35
36 // Establishes a new connection asynchronously and returns the Link object
37 // representing it. Until the connection is established, the link will be in
38 // the "connecting" state.
39 // The optional function parameter will be called when the link gets
40 // disconnected.
41 Link connectAsync(std::function<void()> disconnect_fn = nullptr);
42
43 // Establishes a new connection and returns the Link object representing it.
44 // If the peer attempts reconnection (e.g. after a reset), the program
45 // will terminate (usually to reconnect after reboot).
47 return connect(
48 []() { LOG(FATAL) << "LinkTransport: peer reset; rebooting"; });
49 }
50
51 private:
52 friend class StatsMonitor;
53
54 PacketSender& sender_;
55 Channel channel_;
56};
57
59 public:
60 StatsMonitor(LinkTransport& transport) : channel_(transport.channel_) {}
61
62 // Returns the count of packets sent over the link transport since start
63 // (including retransmissions). The counter does not reset on new connections.
64 uint32_t packets_sent() const { return channel_.packets_sent(); }
65
66 // Returns the count of packets confirmed as delivered by the peer since
67 // start. The counter does not reset on new connections.
68 uint32_t packets_delivered() const { return channel_.packets_delivered(); }
69
70 // Returns the count of packets received from the peer since start. The
71 // counter does not reset on new connections.
72 uint32_t packets_received() const { return channel_.packets_received(); }
73
74 private:
75 Channel& channel_;
76};
77
78} // namespace roo_transport
Link connectAsync(std::function< void()> disconnect_fn=nullptr)
Link connect(std::function< void()> disconnect_fn=nullptr)
void processIncomingPacket(const roo::byte *buf, size_t len)
Abstraction for sending packets over an underlying medium.