fixed weird flushing (#95)
This commit is contained in:
@@ -71,17 +71,21 @@ void RotateFile::write(const unsigned char* value, const size_t size, const bool
|
||||
for (unsigned int pos = 0; pos < size; pos++) {
|
||||
fprintf(m_stream, "%2.2x ", value[pos]);
|
||||
}
|
||||
m_fileSize += 25+3*size+1;
|
||||
} else {
|
||||
fwrite(value, 1, size, m_stream);
|
||||
m_fileSize += size+1;
|
||||
}
|
||||
fprintf(m_stream, "\n");
|
||||
m_fileSize += 25+3*size+1;
|
||||
fflush(m_stream);
|
||||
} else {
|
||||
fwrite(value, (streamsize)size, 1, m_stream);
|
||||
m_fileSize += size;
|
||||
}
|
||||
if ((m_fileSize%1024) == 0) {
|
||||
fflush(m_stream);
|
||||
m_flushSize += size;
|
||||
if (m_flushSize>16) {
|
||||
fflush(m_stream);
|
||||
m_flushSize = 0;
|
||||
}
|
||||
}
|
||||
if (m_fileSize >= m_maxSize * 1024LL) {
|
||||
string oldfile = string(m_fileName)+".old";
|
||||
|
||||
@@ -45,7 +45,8 @@ class RotateFile {
|
||||
* @param textMode whether to write each byte with prefixed timestamp and direction as text.
|
||||
*/
|
||||
RotateFile(const string fileName, const unsigned int maxSize, const bool textMode = false)
|
||||
: m_enabled(false), m_fileName(fileName), m_maxSize(maxSize), m_textMode(textMode), m_stream(), m_fileSize(0) {}
|
||||
: m_enabled(false), m_fileName(fileName), m_maxSize(maxSize), m_textMode(textMode), m_stream(), m_fileSize(0),
|
||||
m_flushSize(0) {}
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
@@ -92,8 +93,11 @@ class RotateFile {
|
||||
/** the @a FILE to writing to. */
|
||||
FILE* m_stream;
|
||||
|
||||
/** the number of bytes already written to the @a m_file. */
|
||||
/** the number of bytes written to @a m_file. */
|
||||
uint64_t m_fileSize;
|
||||
|
||||
/** the number of bytes written to @a m_file since the last flush. */
|
||||
uint64_t m_flushSize;
|
||||
};
|
||||
|
||||
} // namespace ebusd
|
||||
|
||||
Reference in New Issue
Block a user