@@ -46,7 +46,7 @@ namespace libp2p::connection {
4646 }
4747
4848 bool MplexStream::readTry () {
49- auto size{std::min (read_buffer_.size (), reading_->bytes )};
49+ auto size{std::min (read_buffer_.size (), reading_->out . size () )};
5050 if (size == 0 ) {
5151 return false ;
5252 }
@@ -65,20 +65,21 @@ namespace libp2p::connection {
6565 }
6666
6767 void MplexStream::readSome (BytesOut out, size_t bytes, ReadCallbackFunc cb) {
68+ ambigousSize (out, bytes);
6869 if (is_reset_) {
6970 return cb (Error::STREAM_RESET_BY_PEER);
7071 }
7172 if (!is_readable_) {
7273 return cb (Error::STREAM_NOT_READABLE);
7374 }
74- if (bytes == 0 || out.empty () || static_cast < size_t >(out. size ()) < bytes ) {
75+ if (out.empty ()) {
7576 return cb (Error::STREAM_INVALID_ARGUMENT);
7677 }
7778 if (reading_.has_value ()) {
7879 return cb (Error::STREAM_IS_READING);
7980 }
8081
81- reading_.emplace (Reading{out, bytes, std::move (cb)});
82+ reading_.emplace (Reading{out, std::move (cb)});
8283 if (readTry ()) {
8384 return ;
8485 }
@@ -98,13 +99,13 @@ namespace libp2p::connection {
9899 if (!is_writable_) {
99100 return cb (Error::STREAM_NOT_WRITABLE);
100101 }
101- if (bytes == 0 || in.empty () || static_cast < size_t >(in. size ()) < bytes ) {
102+ if (in.empty ()) {
102103 return cb (Error::STREAM_INVALID_ARGUMENT);
103104 }
104105 if (is_writing_) {
105106 std::vector<uint8_t > in_vector (in.begin (), in.end ());
106107 std::lock_guard<std::mutex> lock (write_queue_mutex_);
107- write_queue_.emplace_back (in_vector, bytes, cb);
108+ write_queue_.emplace_back (in_vector, cb);
108109 return ;
109110 }
110111 if (connection_.expired ()) {
@@ -129,7 +130,7 @@ namespace libp2p::connection {
129130 // check if new write messages were received while stream was writing
130131 // and propagate these messages
131132 if (not self->write_queue_ .empty ()) {
132- auto [in, bytes, cb] = self->write_queue_ .front ();
133+ auto [in, cb] = self->write_queue_ .front ();
133134 self->write_queue_ .pop_front ();
134135 writeReturnSize (self, in, cb);
135136 }
0 commit comments