Skip to content

Commit

Permalink
simple_writer: add Windows support for fsync
Browse files Browse the repository at this point in the history
  • Loading branch information
bkueng committed Aug 5, 2024
1 parent cf24ec6 commit 4d468f9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Streamed C++ [ULog](https://docs.px4.io/main/en/dev_log/ulog_file_format.html) r

## Properties
- Options for keeping log data in memory or processing immediately.
- Pure C++17 without additional dependencies (`SimpleWriter` requires POSIX for file IO).
- Pure C++17 without additional dependencies (`SimpleWriter` requires platform-specific `fsync`/`FlushFileBuffers`).
- The reader is ~10 times as fast compared to the [python implementation](https://github.com/PX4/pyulog).
However, the API is more low-level, and if you're just looking for an easy-to-use parsing library, use pyulog.
- Unsupported ULog features:
Expand Down
8 changes: 8 additions & 0 deletions ulog_cpp/simple_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

#include "simple_writer.hpp"

#ifdef WINDOWS
#include <fileapi.h>
#else
#include <unistd.h>
#endif

namespace ulog_cpp {

Expand Down Expand Up @@ -108,7 +112,11 @@ void SimpleWriter::fsync()
{
if (_file) {
fflush(_file);
#ifdef WINDOWS
FlushFileBuffers(static_cast<HANDLE>(_fileno(_file)));
#else
::fsync(fileno(_file));
#endif
}
}
uint16_t SimpleWriter::writeAddLoggedMessage(const std::string& message_format_name,
Expand Down

0 comments on commit 4d468f9

Please sign in to comment.