Skip to content

Commit 3da0ef2

Browse files
committed
Add file_base::sync_all_on_write flag.
Maps to: - O_SYNC on POSIX - FILE_FLAG_WRITE_THROUGH on Windows
1 parent f5ea17d commit 3da0ef2

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

asio/include/asio/detail/impl/win_iocp_file_service.ipp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ asio::error_code win_iocp_file_service::open(
8888
flags |= FILE_FLAG_SEQUENTIAL_SCAN;
8989
else
9090
flags |= FILE_FLAG_RANDOM_ACCESS;
91+
if ((open_flags & file_base::sync_all_on_write) != 0)
92+
flags |= FILE_FLAG_WRITE_THROUGH;
9193

9294
HANDLE handle = ::CreateFileA(path, access, 0, 0, disposition, flags, 0);
9395
if (handle != INVALID_HANDLE_VALUE)

asio/include/asio/file_base.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ class file_base
5858

5959
/// Open the file with any existing contents truncated.
6060
static const flags truncate = implementation_defined;
61+
62+
/// Open the file so that write operations automatically synchronise the file
63+
/// data and metadata to disk.
64+
static const flags sync_all_on_write = implementation_defined;
6165
#else
6266
enum flags
6367
{
@@ -68,15 +72,17 @@ class file_base
6872
append = 8,
6973
create = 16,
7074
exclusive = 32,
71-
truncate = 64
75+
truncate = 64,
76+
sync_all_on_write = 128
7277
#else // defined(ASIO_WINDOWS)
7378
read_only = O_RDONLY,
7479
write_only = O_WRONLY,
7580
read_write = O_RDWR,
7681
append = O_APPEND,
7782
create = O_CREAT,
7883
exclusive = O_EXCL,
79-
truncate = O_TRUNC
84+
truncate = O_TRUNC,
85+
sync_all_on_write = O_SYNC
8086
#endif // defined(ASIO_WINDOWS)
8187
};
8288

0 commit comments

Comments
 (0)