1
0
Fork 0

use istream.ignore() for a tighter loop

This commit is contained in:
Kevin Matz 2021-08-19 12:56:12 -04:00
parent 818a0891a3
commit 1371d17af1
1 changed files with 7 additions and 11 deletions

View File

@ -176,23 +176,19 @@ void Pdu::iStream(Stream stream)
uint hd_length = length - (flags_.hasLength ? 3 : 2) - vector_size_;
// abort if the remaining PDU length isn't available
if (!stream->good() || stream->available() < hd_length) {
stream->setstate(std::ios_base::failbit);
return;
}
if (!stream->good() || stream->available() < hd_length)
return stream->setstate(std::ios_base::failbit);
// create a stream buffer for the header and data
stream_ = Stream(new pdu_stream(stream->data(), hd_length));
if (stream_->available() != hd_length) {
stream->setstate(std::ios_base::failbit);
return;
}
if (stream_->available() != hd_length)
return stream->setstate(std::ios_base::failbit);
// fast-forward the input stream
for (uint i = 0; i < hd_length; i++)
stream->get();
stream->ignore(hd_length);
if (!stream->available())
stream->setstate(std::ios_base::eofbit);
return stream->setstate(std::ios_base::eofbit);
}