summaryrefslogtreecommitdiff
path: root/src/mongo/util
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2017-04-06 16:20:05 -0400
committerMathias Stearn <mathias@10gen.com>2017-04-12 08:57:13 -0400
commitc68c898e1e5ed1260e067a57ae90049d8d0916b6 (patch)
tree7740e123797fa249150d427ceb5eb3913322cbc2 /src/mongo/util
parent999ec2fca89384f57b3fe0468ee7b57c40dabf14 (diff)
downloadmongo-c68c898e1e5ed1260e067a57ae90049d8d0916b6.tar.gz
SERVER-28508 Make BufReader propagate the actual errors
Diffstat (limited to 'src/mongo/util')
-rw-r--r--src/mongo/util/bufreader.h30
1 files changed, 6 insertions, 24 deletions
diff --git a/src/mongo/util/bufreader.h b/src/mongo/util/bufreader.h
index ae7f2a469e3..b73ca28459d 100644
--- a/src/mongo/util/bufreader.h
+++ b/src/mongo/util/bufreader.h
@@ -30,6 +30,8 @@
#pragma once
+#include <utility>
+
#include "mongo/base/data_range.h"
#include "mongo/base/data_range_cursor.h"
#include "mongo/base/data_type_terminated.h"
@@ -48,14 +50,6 @@ class BufReader {
MONGO_DISALLOW_COPYING(BufReader);
public:
- class eof : public std::exception {
- public:
- eof() {}
- virtual const char* what() const throw() {
- return "BufReader eof";
- }
- };
-
BufReader(const void* p, unsigned len)
: _start(reinterpret_cast<const char*>(p)), _pos(_start), _end(_start + len) {}
@@ -67,10 +61,7 @@ public:
template <typename T>
void read(T& t) {
ConstDataRangeCursor cdrc(_pos, _end);
- if (!cdrc.readAndAdvance(&t).isOK()) {
- throw eof();
- }
-
+ uassertStatusOK(cdrc.readAndAdvance(&t));
_pos = cdrc.data();
}
@@ -85,10 +76,7 @@ public:
/** read in the object specified, but do not advance buffer pointer */
template <typename T>
void peek(T& t) const {
- ConstDataRange cdr(_pos, _end);
- if (!cdr.read(&t).isOK()) {
- throw eof();
- }
+ uassertStatusOK(ConstDataRange(_pos, _end).read(&t));
}
/** read in and return an object of the specified type, but do not advance buffer pointer */
@@ -118,14 +106,8 @@ public:
/** return current position pointer, and advance by len */
const void* skip(unsigned len) {
ConstDataRangeCursor cdrc(_pos, _end);
-
- if (!cdrc.advance(len).isOK()) {
- throw eof();
- }
-
- const void* p = _pos;
- _pos = cdrc.data();
- return p;
+ uassertStatusOK(cdrc.advance(len));
+ return std::exchange(_pos, cdrc.data());
}
/// reads a NUL terminated string