roo_transport
API Documentation for roo_transport
Loading...
Searching...
No Matches
link_input_stream.cpp
Go to the documentation of this file.
2#ifdef ROO_USE_THREADS
3
5
6namespace roo_transport {
7
8LinkInputStream::LinkInputStream(LinkInputStream&& 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
17LinkInputStream& LinkInputStream::operator=(LinkInputStream&& 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
29void LinkInputStream::close() {
30 if (status_ != roo_io::kOk && status_ != roo_io::kEndOfStream) return;
31 channel_->closeInput(my_stream_id_, status_);
32 if (status_ != roo_io::kOk && status_ != roo_io::kEndOfStream) return;
33 status_ = roo_io::kClosed;
34}
35
36size_t LinkInputStream::read(roo::byte* buf, size_t count) {
37 if (count == 0 || status_ != roo_io::kOk) return 0;
38 return channel_->read(buf, count, my_stream_id_, status_);
39 // // processor_.loop();
40 // while (true) {
41 // for (int i = 0; i < 100; ++i) {
42 // size_t result = processor_.tryRead(buf, count);
43 // if (result > 0) {
44 // // if (count > result) {
45 // // buf += result;
46 // // count -= result;
47 // // result += processor_.tryRead(buf, count);
48 // // }
49 // return result;
50 // }
51 // processor_.loop();
52 // }
53 // delay(1);
54 // }
55}
56
57size_t LinkInputStream::tryRead(roo::byte* buf, size_t count) {
58 if (count == 0 || status_ != roo_io::kOk) return 0;
59 return channel_->tryRead(buf, count, my_stream_id_, status_);
60}
61
62size_t LinkInputStream::available() {
63 if (status_ != roo_io::kOk) return 0;
64 return channel_->availableForRead(my_stream_id_, status_);
65}
66
67int LinkInputStream::read() {
68 if (status_ != roo_io::kOk) return 0;
69 roo::byte result;
70 size_t count = channel_->tryRead(&result, 1, my_stream_id_, status_);
71 if (count > 0) return (int)result;
72 return -1;
73}
74
75int LinkInputStream::peek() {
76 if (status_ != roo_io::kOk) return -1;
77 int result = channel_->peek(my_stream_id_, status_);
78 if (result >= 0) return result;
79 return -1;
80}
81
82} // namespace roo_transport
83
84#endif // ROO_USE_THREADS