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++) {
|
for (unsigned int pos = 0; pos < size; pos++) {
|
||||||
fprintf(m_stream, "%2.2x ", value[pos]);
|
fprintf(m_stream, "%2.2x ", value[pos]);
|
||||||
}
|
}
|
||||||
|
m_fileSize += 25+3*size+1;
|
||||||
} else {
|
} else {
|
||||||
fwrite(value, 1, size, m_stream);
|
fwrite(value, 1, size, m_stream);
|
||||||
|
m_fileSize += size+1;
|
||||||
}
|
}
|
||||||
fprintf(m_stream, "\n");
|
fprintf(m_stream, "\n");
|
||||||
m_fileSize += 25+3*size+1;
|
fflush(m_stream);
|
||||||
} else {
|
} else {
|
||||||
fwrite(value, (streamsize)size, 1, m_stream);
|
fwrite(value, (streamsize)size, 1, m_stream);
|
||||||
m_fileSize += size;
|
m_fileSize += size;
|
||||||
}
|
m_flushSize += size;
|
||||||
if ((m_fileSize%1024) == 0) {
|
if (m_flushSize>16) {
|
||||||
fflush(m_stream);
|
fflush(m_stream);
|
||||||
|
m_flushSize = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (m_fileSize >= m_maxSize * 1024LL) {
|
if (m_fileSize >= m_maxSize * 1024LL) {
|
||||||
string oldfile = string(m_fileName)+".old";
|
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.
|
* @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)
|
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.
|
* Destructor.
|
||||||
@@ -92,8 +93,11 @@ class RotateFile {
|
|||||||
/** the @a FILE to writing to. */
|
/** the @a FILE to writing to. */
|
||||||
FILE* m_stream;
|
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;
|
uint64_t m_fileSize;
|
||||||
|
|
||||||
|
/** the number of bytes written to @a m_file since the last flush. */
|
||||||
|
uint64_t m_flushSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ebusd
|
} // namespace ebusd
|
||||||
|
|||||||
Reference in New Issue
Block a user