roo_transport
API Documentation for roo_transport
Loading...
Searching...
No Matches
link_output_stream.cpp
Go to the documentation of this file.
2#ifdef ROO_USE_THREADS
3
5
6namespace roo_transport {
7
8LinkOutputStream::LinkOutputStream(LinkOutputStream&& other) {
9 channel_ = other.channel_;
10 my_stream_id_ = other.my_stream_id_;
11 status_ = other.status_;
12 other.channel_ = nullptr;
13 other.my_stream_id_ = 0;
14 other.status_ = roo_io::kClosed;
15}
16
17LinkOutputStream& LinkOutputStream::operator=(LinkOutputStream&& other) {
18 if (this != &other) {
19 channel_ = other.channel_;
20 my_stream_id_ = other.my_stream_id_;
21 status_ = other.status_;
22 other.channel_ = nullptr;
23 other.my_stream_id_ = 0;
24 other.status_ = roo_io::kClosed;
25 }
26 return *this;
27}
28
29size_t LinkOutputStream::write(const roo::byte* buf, size_t count) {
30 if (status_ != roo_io::kOk) return 0;
31 if (count == 0) return 0;
32 return channel_->write(buf, count, my_stream_id_, status_);
33 // while (true) {
34 // for (int i = 0; i < 100; ++i) {
35 // size_t result = processor_.tryWrite(buf, count);
36 // if (result > 0) {
37 // // if (count > result) {
38 // // buf += result;
39 // // count -= result;
40 // // result += processor_.tryWrite(buf, count);
41 // // }
42 // return result;
43 // }
44 // processor_.loop();
45 // }
46 // delay(1);
47 // }
48}
49
50size_t LinkOutputStream::tryWrite(const roo::byte* buf, size_t count) {
51 if (status_ != roo_io::kOk) return 0;
52 return channel_->tryWrite(buf, count, my_stream_id_, status_);
53}
54
55size_t LinkOutputStream::availableForWrite() {
56 if (status_ != roo_io::kOk) return 0;
57 return channel_->availableForWrite(my_stream_id_, status_);
58}
59
60void LinkOutputStream::flush() {
61 if (status_ != roo_io::kOk) return;
62 channel_->flush(my_stream_id_, status_);
63}
64
65void LinkOutputStream::close() {
66 if (status_ != roo_io::kOk) return;
67 channel_->close(my_stream_id_, status_);
68 if (status_ == roo_io::kOk) status_ = roo_io::kClosed;
69}
70
71} // namespace roo_transport
72
73#endif // ROO_USE_THREADS