26
26
27
27
#include " async_simple/coro/SyncAwait.h"
28
28
#include " io_context_pool.hpp"
29
- #if defined(ENABLE_FILE_IO_URING) || defined(ASIO_WINDOWS )
29
+ #if defined(ASIO_HAS_FILE )
30
30
#include < asio/random_access_file.hpp>
31
31
#include < asio/stream_file.hpp>
32
32
#endif
@@ -121,7 +121,7 @@ constexpr inline flags to_flags(std::ios::ios_base::openmode mode) {
121
121
return access;
122
122
}
123
123
124
- #if defined(ENABLE_FILE_IO_URING) || defined(ASIO_WINDOWS )
124
+ #if defined(ASIO_HAS_FILE )
125
125
template <bool seq, typename File, typename Executor>
126
126
inline bool open_native_async_file (File &file, Executor &executor,
127
127
std::string_view filepath,
@@ -184,7 +184,7 @@ class basic_seq_coro_file {
184
184
return open_stream_file_in_pool (filepath, open_flags);
185
185
}
186
186
else {
187
- #if defined(ENABLE_FILE_IO_URING) || defined(ASIO_WINDOWS )
187
+ #if defined(ASIO_HAS_FILE )
188
188
return open_native_async_file<true >(async_seq_file_, executor_wrapper_,
189
189
filepath, to_flags (open_flags));
190
190
#else
@@ -199,7 +199,7 @@ class basic_seq_coro_file {
199
199
co_return co_await async_read_write ({buf, size});
200
200
}
201
201
else {
202
- #if defined(ENABLE_FILE_IO_URING) || defined(ASIO_WINDOWS )
202
+ #if defined(ASIO_HAS_FILE )
203
203
if (async_seq_file_ == nullptr ) {
204
204
co_return std::make_pair (
205
205
std::make_error_code (std::errc::invalid_argument), 0 );
@@ -253,7 +253,7 @@ class basic_seq_coro_file {
253
253
std::span (const_cast <char *>(buf.data ()), buf.size ()));
254
254
}
255
255
else {
256
- #if defined(ENABLE_FILE_IO_URING) || defined(ASIO_WINDOWS )
256
+ #if defined(ASIO_HAS_FILE )
257
257
if (async_seq_file_ == nullptr ) {
258
258
co_return std::make_pair (
259
259
std::make_error_code (std::errc::invalid_argument), 0 );
@@ -268,7 +268,7 @@ class basic_seq_coro_file {
268
268
}
269
269
}
270
270
271
- #if defined(ENABLE_FILE_IO_URING) || defined(ASIO_WINDOWS )
271
+ #if defined(ASIO_HAS_FILE )
272
272
std::shared_ptr<asio::stream_file> get_async_stream_file () {
273
273
return async_seq_file_;
274
274
}
@@ -277,7 +277,7 @@ class basic_seq_coro_file {
277
277
std::fstream &get_stream_file () { return frw_seq_file_; }
278
278
279
279
bool is_open () {
280
- #if defined(ENABLE_FILE_IO_URING) || defined(ASIO_WINDOWS )
280
+ #if defined(ASIO_HAS_FILE )
281
281
if (async_seq_file_ && async_seq_file_->is_open ()) {
282
282
return true ;
283
283
}
@@ -288,7 +288,7 @@ class basic_seq_coro_file {
288
288
bool eof () { return eof_; }
289
289
290
290
void close () {
291
- #if defined(ENABLE_FILE_IO_URING) || defined(ASIO_WINDOWS )
291
+ #if defined(ASIO_HAS_FILE )
292
292
if (async_seq_file_ && async_seq_file_->is_open ()) {
293
293
std::error_code ec;
294
294
async_seq_file_->close (ec);
@@ -300,7 +300,7 @@ class basic_seq_coro_file {
300
300
}
301
301
302
302
bool seek (size_t offset, std::ios_base::seekdir dir) {
303
- #if defined(ENABLE_FILE_IO_URING) || defined(ASIO_WINDOWS )
303
+ #if defined(ASIO_HAS_FILE )
304
304
if (async_seq_file_ && async_seq_file_->is_open ()) {
305
305
int whence = SEEK_SET;
306
306
if (dir == std::ios_base::cur)
@@ -327,7 +327,7 @@ class basic_seq_coro_file {
327
327
}
328
328
329
329
execution_type get_execution_type () {
330
- #if defined(ENABLE_FILE_IO_URING) || defined(ASIO_WINDOWS )
330
+ #if defined(ASIO_HAS_FILE )
331
331
if (async_seq_file_ && async_seq_file_->is_open ()) {
332
332
return execution_type::native_async;
333
333
}
@@ -370,7 +370,7 @@ class basic_seq_coro_file {
370
370
}
371
371
372
372
coro_io::ExecutorWrapper<> executor_wrapper_;
373
- #if defined(ENABLE_FILE_IO_URING) || defined(ASIO_WINDOWS )
373
+ #if defined(ASIO_HAS_FILE )
374
374
std::shared_ptr<asio::stream_file> async_seq_file_; // seq
375
375
#endif
376
376
std::fstream frw_seq_file_; // fread/fwrite seq file
@@ -411,7 +411,7 @@ class basic_random_coro_file {
411
411
return open_fd (filepath, to_flags (open_flags));
412
412
}
413
413
else {
414
- #if defined(ENABLE_FILE_IO_URING) || defined(ASIO_WINDOWS )
414
+ #if defined(ASIO_HAS_FILE )
415
415
return open_native_async_file<false >(async_random_file_,
416
416
executor_wrapper_, filepath,
417
417
to_flags (open_flags));
@@ -427,7 +427,7 @@ class basic_random_coro_file {
427
427
co_return co_await async_pread (offset, buf, size);
428
428
}
429
429
else {
430
- #if defined(ENABLE_FILE_IO_URING) || defined(ASIO_WINDOWS )
430
+ #if defined(ASIO_HAS_FILE )
431
431
if (async_random_file_ == nullptr ) {
432
432
co_return std::make_pair (
433
433
std::make_error_code (std::errc::invalid_argument), 0 );
@@ -453,7 +453,7 @@ class basic_random_coro_file {
453
453
co_return co_await async_pwrite (offset, buf.data (), buf.size ());
454
454
}
455
455
else {
456
- #if defined(ENABLE_FILE_IO_URING) || defined(ASIO_WINDOWS )
456
+ #if defined(ASIO_HAS_FILE )
457
457
if (async_random_file_ == nullptr ) {
458
458
co_return std::make_pair (
459
459
std::make_error_code (std::errc::invalid_argument), 0 );
@@ -468,7 +468,7 @@ class basic_random_coro_file {
468
468
}
469
469
}
470
470
471
- #if defined(ENABLE_FILE_IO_URING) || defined(ASIO_WINDOWS )
471
+ #if defined(ASIO_HAS_FILE )
472
472
std::shared_ptr<asio::random_access_file> get_async_stream_file () {
473
473
return async_random_file_;
474
474
}
@@ -477,7 +477,7 @@ class basic_random_coro_file {
477
477
std::shared_ptr<int > get_pread_file () { return prw_random_file_; }
478
478
479
479
bool is_open () {
480
- #if defined(ENABLE_FILE_IO_URING) || defined(ASIO_WINDOWS )
480
+ #if defined(ASIO_HAS_FILE )
481
481
if (async_random_file_ && async_random_file_->is_open ()) {
482
482
return true ;
483
483
}
@@ -488,7 +488,7 @@ class basic_random_coro_file {
488
488
bool eof () { return eof_; }
489
489
490
490
execution_type get_execution_type () {
491
- #if defined(ENABLE_FILE_IO_URING) || defined(ASIO_WINDOWS )
491
+ #if defined(ASIO_HAS_FILE )
492
492
if (async_random_file_ && async_random_file_->is_open ()) {
493
493
return execution_type::native_async;
494
494
}
@@ -501,7 +501,7 @@ class basic_random_coro_file {
501
501
}
502
502
503
503
void close () {
504
- #if defined(ENABLE_FILE_IO_URING) || defined(ASIO_WINDOWS )
504
+ #if defined(ASIO_HAS_FILE )
505
505
std::error_code ec;
506
506
if (async_random_file_) {
507
507
async_random_file_->close (ec);
@@ -653,7 +653,7 @@ class basic_random_coro_file {
653
653
#endif
654
654
655
655
coro_io::ExecutorWrapper<> executor_wrapper_;
656
- #if defined(ENABLE_FILE_IO_URING) || defined(ASIO_WINDOWS )
656
+ #if defined(ASIO_HAS_FILE )
657
657
std::shared_ptr<asio::random_access_file> async_random_file_; // random file
658
658
#endif
659
659
std::shared_ptr<int > prw_random_file_ = nullptr ; // pread/pwrite random file
0 commit comments