roo_transport
API Documentation for roo_transport
Loading...
Searching...
No Matches
link.h
Go to the documentation of this file.
1#pragma once
2
3#include "roo_io.h"
4#include "roo_io/core/output_stream.h"
5#include "roo_transport.h"
10
11namespace roo_transport {
12
13// Represents a reliable bidirectional peer-to-peer link over a packet-based
14// transport.
15class Link {
16 public:
17 // Creates a dummy link in state kIdle.
18 // Use LinkTransport::connect() to create a proper connected link.
19 Link();
20
21 Link(const Link&) = delete;
22 Link& operator=(const Link&) = delete;
23
24 // Support for move.
25 Link(Link&& other);
26
27 // Support for move.
28 Link& operator=(Link&& other);
29
30 // Obtains the input stream that can be used to read from the link.
31 LinkInputStream& in() { return in_; }
32
33 // Obtains the output stream that can be used to write to the link.
34 LinkOutputStream& out() { return out_; }
35
36 // Returns the current status of the link.
37 LinkStatus status() const;
38
39 // If the link is in state kConnecting, blocks until it becomes either
40 // kConnected or kBroken. Otherwise, returns immediately.
41 void awaitConnected();
42
43 // If the link is kIdle, kConnected, or kBroken, does nothing and returns
44 // true immediately. Otherwise (when the link is in state kConnecting), blocks
45 // until it becomes either kConnected or kBroken, or until the specified
46 // timeout elapses, and returns true if the link has changed state, and false
47 // if the timeout has elapsed.
48 bool awaitConnected(roo_time::Duration timeout);
49
50 // Disconnects the link, immediately bringing it to the idle state. If the
51 // link is already idle, does nothing.
52 void disconnect();
53
54 // Returns the ID that identifies this link. The link objects created by
55 // LinkTransport::connect() will have unique stream IDs.
56 uint32_t streamId() const { return my_stream_id_; }
57
58 private:
59 friend class LinkStream;
60 friend class LinkTransport;
61
62 Link(Channel& channel, uint32_t my_stream_id);
63
64 Channel* channel_;
65 uint32_t my_stream_id_;
66 LinkInputStream in_;
67 LinkOutputStream out_;
68};
69
70} // namespace roo_transport