File tree Expand file tree Collapse file tree 2 files changed +14
-14
lines changed Expand file tree Collapse file tree 2 files changed +14
-14
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,8 @@ namespace libp2p::basic {
20
20
*/
21
21
class MessageReadWriter {
22
22
public:
23
- using ReadCallback = outcome::result<std::shared_ptr<std::vector<uint8_t >>>;
23
+ using ResultType = std::shared_ptr<std::vector<uint8_t >>;
24
+ using ReadCallback = outcome::result<ResultType>;
24
25
using ReadCallbackFunc = std::function<void (ReadCallback)>;
25
26
26
27
virtual ~MessageReadWriter () = default ;
Original file line number Diff line number Diff line change @@ -30,24 +30,23 @@ namespace libp2p::basic {
30
30
}
31
31
32
32
auto msg_len = varint_opt->toUInt64 ();
33
- auto buffer = std::make_shared<std::vector<uint8_t >>(msg_len, 0 );
34
- self->conn_ ->read (
35
- *buffer, msg_len,
36
- [self, buffer, cb = std::move (cb)](auto &&res) mutable {
37
- if (!res) {
38
- return cb (res.error ());
39
- }
40
- cb (std::move (buffer));
41
- });
33
+ if (0 != msg_len) {
34
+ auto buffer = std::make_shared<std::vector<uint8_t >>(msg_len, 0 );
35
+ self->conn_ ->read (
36
+ *buffer, msg_len,
37
+ [self, buffer, cb = std::move (cb)](auto &&res) mutable {
38
+ if (!res) {
39
+ return cb (res.error ());
40
+ }
41
+ cb (std::move (buffer));
42
+ });
43
+ } else
44
+ cb (ResultType{});
42
45
});
43
46
}
44
47
45
48
void MessageReadWriterUvarint::write (gsl::span<const uint8_t > buffer,
46
49
Writer::WriteCallbackFunc cb) {
47
- if (buffer.empty ()) {
48
- return cb (MessageReadWriterError::BUFFER_IS_EMPTY);
49
- }
50
-
51
50
auto varint_len = multi::UVarint{static_cast <uint64_t >(buffer.size ())};
52
51
53
52
auto msg_bytes = std::make_shared<std::vector<uint8_t >>();
You can’t perform that action at this time.
0 commit comments