Skip to content

Commit

Permalink
Write logs in the buffer first to ensure the order of log entries (#508)
Browse files Browse the repository at this point in the history
  • Loading branch information
xuezhulian authored Jun 21, 2024
1 parent 63bab23 commit 901cfdc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,6 @@
<Test
Identifier = "KSDebug_Tests">
</Test>
<Test
Identifier = "KSFileUtils_Tests/testWriteBuffered_FlushAndLargeWriteOrder">
</Test>
<Test
Identifier = "KSFileUtils_Tests/testWriteBuffered_OrderWithLargeData">
</Test>
<Test
Identifier = "KSObjC_Tests/testDateDescription">
</Test>
Expand Down
9 changes: 4 additions & 5 deletions Sources/KSCrashRecordingCore/KSFileUtils.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,18 +480,17 @@ void ksfu_closeBufferedWriter(KSBufferedWriter* writer)

bool ksfu_writeBufferedWriter(KSBufferedWriter* writer, const char* restrict const data, const int length)
{
if(length > writer->bufferLength)
{
return ksfu_writeBytesToFD(writer->fd, data, length);
}
if(length > writer->bufferLength - writer->position)
{
if (!ksfu_flushBufferedWriter(writer))
{
return false;
}
}

if(length > writer->bufferLength)
{
return ksfu_writeBytesToFD(writer->fd, data, length);
}
memcpy(writer->buffer + writer->position, data, length);
writer->position += length;
return true;
Expand Down

0 comments on commit 901cfdc

Please sign in to comment.