* Clean up exception handling.

This commit is contained in:
Eelco Dolstra 2011-12-16 15:45:42 +00:00
parent 5a1b9ed0aa
commit 78598d06f0
2 changed files with 10 additions and 3 deletions

View File

@ -41,8 +41,15 @@ void BufferedSink::operator () (const unsigned char * data, size_t len)
void BufferedSink::flush() void BufferedSink::flush()
{ {
if (bufPos == 0) return; if (bufPos == 0) return;
write(buffer, bufPos); size_t n = bufPos;
bufPos = 0; bufPos = 0; // don't trigger the assert() in ~BufferedSink()
write(buffer, n);
}
FdSink::~FdSink()
{
try { flush(); } catch (...) { ignoreException(); }
} }

View File

@ -71,7 +71,7 @@ struct FdSink : BufferedSink
FdSink() : fd(-1) { } FdSink() : fd(-1) { }
FdSink(int fd) : fd(fd) { } FdSink(int fd) : fd(fd) { }
~FdSink() { flush(); } ~FdSink();
void write(const unsigned char * data, size_t len); void write(const unsigned char * data, size_t len);
}; };