FdSource: track number of bytes read
This commit is contained in:
parent
bcc9943cee
commit
581e1bc5b4
2 changed files with 8 additions and 5 deletions
|
@ -64,9 +64,9 @@ static void warnLargeDump()
|
||||||
|
|
||||||
void FdSink::write(const unsigned char * data, size_t len)
|
void FdSink::write(const unsigned char * data, size_t len)
|
||||||
{
|
{
|
||||||
|
written += len;
|
||||||
static bool warned = false;
|
static bool warned = false;
|
||||||
if (warn && !warned) {
|
if (warn && !warned) {
|
||||||
written += len;
|
|
||||||
if (written > threshold) {
|
if (written > threshold) {
|
||||||
warnLargeDump();
|
warnLargeDump();
|
||||||
warned = true;
|
warned = true;
|
||||||
|
@ -131,6 +131,7 @@ size_t FdSource::readUnbuffered(unsigned char * data, size_t len)
|
||||||
} while (n == -1 && errno == EINTR);
|
} while (n == -1 && errno == EINTR);
|
||||||
if (n == -1) { _good = false; throw SysError("reading from file"); }
|
if (n == -1) { _good = false; throw SysError("reading from file"); }
|
||||||
if (n == 0) { _good = false; throw EndOfFile("unexpected end-of-file"); }
|
if (n == 0) { _good = false; throw EndOfFile("unexpected end-of-file"); }
|
||||||
|
read += n;
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,11 +76,11 @@ struct BufferedSource : Source
|
||||||
struct FdSink : BufferedSink
|
struct FdSink : BufferedSink
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
bool warn;
|
bool warn = false;
|
||||||
size_t written;
|
size_t written = 0;
|
||||||
|
|
||||||
FdSink() : fd(-1), warn(false), written(0) { }
|
FdSink() : fd(-1) { }
|
||||||
FdSink(int fd) : fd(fd), warn(false), written(0) { }
|
FdSink(int fd) : fd(fd) { }
|
||||||
~FdSink();
|
~FdSink();
|
||||||
|
|
||||||
void write(const unsigned char * data, size_t len) override;
|
void write(const unsigned char * data, size_t len) override;
|
||||||
|
@ -96,6 +96,8 @@ private:
|
||||||
struct FdSource : BufferedSource
|
struct FdSource : BufferedSource
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
size_t read = 0;
|
||||||
|
|
||||||
FdSource() : fd(-1) { }
|
FdSource() : fd(-1) { }
|
||||||
FdSource(int fd) : fd(fd) { }
|
FdSource(int fd) : fd(fd) { }
|
||||||
size_t readUnbuffered(unsigned char * data, size_t len) override;
|
size_t readUnbuffered(unsigned char * data, size_t len) override;
|
||||||
|
|
Loading…
Reference in a new issue