2 #ifndef UVCC_REQUEST_FS__HPP 3 #define UVCC_REQUEST_FS__HPP 5 #include "uvcc/utility.hpp" 6 #include "uvcc/request-base.hpp" 7 #include "uvcc/handle-fs.hpp" 8 #include "uvcc/handle-io.hpp" 9 #include "uvcc/buffer.hpp" 10 #include "uvcc/loop.hpp" 21 #include <type_traits> 43 friend class request::instance< fs >;
47 using uv_t = ::uv_fs_t;
76 struct properties :
request::properties
78 uv_t *uv_req =
nullptr;
79 ~properties() {
if (uv_req) ::uv_fs_req_cleanup(uv_req); }
89 fs()
noexcept =
default;
91 explicit fs(uv_t *_uv_req) :
request(
reinterpret_cast<
request::uv_t* >(_uv_req)) {}
97 fs(
const fs&) =
default;
98 fs& operator =(
const fs&) =
default;
100 fs(
fs&&)
noexcept =
default;
101 fs& operator =(
fs&&)
noexcept =
default;
105 template< ::uv_fs_type _UV_FS_TYPE_ >
void init()
107 static_cast< uv_t* >(uv_req)->type = UV_FS;
108 static_cast< uv_t* >(uv_req)->fs_type = _UV_FS_TYPE_;
109 instance::from(uv_req)->properties().uv_req =
static_cast< uv_t* >(uv_req);
116 ::uv_fs_type
fs_type()
const noexcept {
return static_cast< uv_t* >(uv_req)->fs_type; }
119 uv::
loop loop()
const noexcept {
return uv::
loop(
static_cast< uv_t* >(uv_req)->loop); }
122 explicit operator
const uv_t*()
const noexcept {
return static_cast<
const uv_t* >(uv_req); }
123 explicit operator uv_t*()
noexcept {
return static_cast< uv_t* >(uv_req); }
132 friend class request::instance< close >;
136 using on_request_t = std::function<
void(
close _request) >;
143 struct properties :
fs::properties
145 file::uv_t *uv_handle =
nullptr;
155 explicit close(uv_t *_uv_req) :
fs(_uv_req) {}
162 uv_req = instance::create();
163 init< UV_FS_CLOSE >();
166 close(
const close&) =
default;
169 close(
close&&)
noexcept =
default;
170 close& operator =(
close&&)
noexcept =
default;
173 template<
typename =
void >
static void close_cb(::uv_fs_t*);
176 on_request_t& on_request()
const noexcept {
return instance::from(uv_req)->request_cb_storage.value(); }
180 file handle()
const noexcept {
return file(instance::from(uv_req)->properties().uv_handle); }
190 ::uv_fs_req_cleanup(
static_cast< uv_t* >(uv_req));
192 file::instance::from(_file.uv_handle)->properties().is_closing = 1;
194 auto instance_ptr = instance::from(uv_req);
196 if (!instance_ptr->request_cb_storage.value())
198 instance_ptr->properties().uv_handle =
static_cast< file::uv_t* >(_file);
202 return uv_status(::uv_fs_close(
203 static_cast< file::uv_t* >(_file)->loop,
static_cast< uv_t* >(uv_req),
210 file::instance::from(_file.uv_handle)->ref();
215 auto &properties = instance_ptr->properties();
216 properties.uv_handle =
static_cast< file::uv_t* >(_file);
222 auto uv_ret = ::uv_fs_close(
223 static_cast< file::uv_t* >(_file)->loop,
static_cast< uv_t* >(uv_req),
230 file::instance::from(_file.uv_handle)->unref();
231 instance_ptr->unref();
239 explicit operator
const uv_t*()
const noexcept {
return static_cast<
const uv_t* >(uv_req); }
240 explicit operator uv_t*()
noexcept {
return static_cast< uv_t* >(uv_req); }
244 void fs::
close::close_cb(::uv_fs_t *_uv_req)
246 auto instance_ptr = instance::from(_uv_req);
247 instance_ptr->uv_error = _uv_req->result;
249 auto &properties = instance_ptr->properties();
251 ref_guard<
file::instance > unref_file(*file::instance::from(properties.uv_handle), adopt_ref);
252 ref_guard< instance > unref_req(*instance_ptr, adopt_ref);
254 auto &close_cb = instance_ptr->request_cb_storage.value();
255 if (close_cb) close_cb(close(_uv_req));
264 friend class request::instance< read >;
268 using on_request_t = std::function<
void(
read _request,
buffer _buffer) >;
275 struct properties :
fs::properties
277 file::uv_t *uv_handle =
nullptr;
278 buffer::uv_t *uv_buf =
nullptr;
289 explicit read(uv_t *_uv_req) :
fs(_uv_req) {}
296 uv_req = instance::create();
297 init< UV_FS_READ >();
300 read(
const read&) =
default;
301 read& operator =(
const read&) =
default;
303 read(
read&&)
noexcept =
default;
304 read& operator =(
read&&)
noexcept =
default;
307 template<
typename =
void >
static void read_cb(::uv_fs_t*);
310 on_request_t& on_request()
const noexcept {
return instance::from(uv_req)->request_cb_storage.value(); }
314 file handle()
const noexcept {
return file(instance::from(uv_req)->properties().uv_handle); }
317 int64_t
offset()
const noexcept {
return instance::from(uv_req)->properties().offset; }
328 ::uv_fs_req_cleanup(
static_cast< uv_t* >(uv_req));
334 _offset = _telli64(_file.fd());
336 _offset = lseek64(_file.fd(), 0, SEEK_CUR);
340 auto instance_ptr = instance::from(uv_req);
342 if (!instance_ptr->request_cb_storage.value())
344 auto &properties = instance_ptr->properties();
345 properties.uv_handle =
static_cast< file::uv_t* >(_file);
346 properties.offset = _offset;
348 return uv_status(::uv_fs_read(
349 static_cast< file::uv_t* >(_file)->loop,
static_cast< uv_t* >(uv_req),
351 static_cast<
const buffer::uv_t* >(_buf), _buf.count(),
358 file::instance::from(_file.uv_handle)->ref();
359 buffer::instance::from(_buf.uv_buf)->ref();
364 auto &properties = instance_ptr->properties();
365 properties.uv_handle =
static_cast< file::uv_t* >(_file);
366 properties.uv_buf = _buf.uv_buf;
367 properties.offset = _offset;
371 auto uv_ret = ::uv_fs_read(
372 static_cast< file::uv_t* >(_file)->loop,
static_cast< uv_t* >(uv_req),
374 static_cast<
const buffer::uv_t* >(_buf), _buf.count(),
381 file::instance::from(_file.uv_handle)->unref();
382 buffer::instance::from(_buf.uv_buf)->unref();
383 instance_ptr->unref();
391 explicit operator
const uv_t*()
const noexcept {
return static_cast<
const uv_t* >(uv_req); }
392 explicit operator uv_t*()
noexcept {
return static_cast< uv_t* >(uv_req); }
396 void fs::
read::read_cb(::uv_fs_t *_uv_req)
398 auto instance_ptr = instance::from(_uv_req);
399 instance_ptr->uv_error = _uv_req->result;
401 auto &properties = instance_ptr->properties();
403 ref_guard<
file::instance > unref_file(*file::instance::from(properties.uv_handle), adopt_ref);
404 ref_guard< instance > unref_req(*instance_ptr, adopt_ref);
406 auto &read_cb = instance_ptr->request_cb_storage.value();
408 read_cb(read(_uv_req), buffer(properties.uv_buf, adopt_ref));
410 buffer::instance::from(properties.uv_buf)->unref();
419 friend class request::instance< write >;
424 using on_request_t = std::function<
void(
write _request,
buffer _buffer) >;
431 struct properties :
fs::properties
433 file::uv_t *uv_handle =
nullptr;
434 buffer::uv_t *uv_buf =
nullptr;
436 std::size_t pending_size = 0;
446 explicit write(uv_t *_uv_req) :
fs(_uv_req) {}
453 uv_req = instance::create();
454 init< UV_FS_WRITE >();
457 write(
const write&) =
default;
460 write(
write&&)
noexcept =
default;
461 write& operator =(
write&&)
noexcept =
default;
464 template<
typename =
void >
static void write_cb(::uv_fs_t*);
467 on_request_t& on_request()
const noexcept {
return instance::from(uv_req)->request_cb_storage.value(); }
471 file handle()
const noexcept {
return file(instance::from(uv_req)->properties().uv_handle); }
474 int64_t
offset()
const noexcept {
return instance::from(uv_req)->properties().offset; }
485 ::uv_fs_req_cleanup(
static_cast< uv_t* >(uv_req));
491 _offset = _telli64(_file.fd());
493 _offset = lseek64(_file.fd(), 0, SEEK_CUR);
497 auto instance_ptr = instance::from(uv_req);
499 if (!instance_ptr->request_cb_storage.value())
501 auto &properties = instance_ptr->properties();
502 properties.uv_handle =
static_cast< file::uv_t* >(_file);
503 properties.offset = _offset;
505 return uv_status(::uv_fs_write(
506 static_cast< file::uv_t* >(_file)->loop,
static_cast< uv_t* >(uv_req),
508 static_cast<
const buffer::uv_t* >(_buf), _buf.count(),
515 file::instance::from(_file.uv_handle)->ref();
516 buffer::instance::from(_buf.uv_buf)->ref();
519 std::size_t wr_size = 0;
520 for (std::size_t i = 0, buf_count = _buf.count(); i < buf_count; ++i) wr_size += _buf.len(i);
524 auto &properties = instance_ptr->properties();
525 properties.uv_handle =
static_cast< file::uv_t* >(_file);
526 properties.uv_buf = _buf.uv_buf;
527 properties.offset = _offset;
528 properties.pending_size = wr_size;
531 file::instance::from(_file.uv_handle)->properties().write_queue_size += wr_size;
534 auto uv_ret = ::uv_fs_write(
535 static_cast< file::uv_t* >(_file)->loop,
static_cast< uv_t* >(uv_req),
537 static_cast<
const buffer::uv_t* >(_buf), _buf.count(),
545 file::instance::from(_file.uv_handle)->properties().write_queue_size -= wr_size;
547 file::instance::from(_file.uv_handle)->unref();
548 buffer::instance::from(_buf.uv_buf)->unref();
549 instance_ptr->unref();
563 ::uv_fs_req_cleanup(
static_cast< uv_t* >(uv_req));
571 _offset = _telli64(_file.fd());
573 _offset = lseek64(_file.fd(), 0, SEEK_CUR);
577 auto &properties = instance::from(uv_req)->properties();
578 properties.uv_handle =
static_cast< file::uv_t* >(_file);
579 properties.offset = _offset;
581 auto uv_ret = uv_status(::uv_fs_write(
582 static_cast< file::uv_t* >(_file)->loop,
static_cast< uv_t* >(uv_req),
584 static_cast<
const buffer::uv_t* >(_buf), _buf.count(),
593 explicit operator
const uv_t*()
const noexcept {
return static_cast<
const uv_t* >(uv_req); }
594 explicit operator uv_t*()
noexcept {
return static_cast< uv_t* >(uv_req); }
598 void fs::
write::write_cb(::uv_fs_t *_uv_req)
600 auto instance_ptr = instance::from(_uv_req);
601 instance_ptr->uv_error = _uv_req->result;
603 auto &properties = instance_ptr->properties();
604 auto file_instance_ptr = file::instance::from(properties.uv_handle);
606 ref_guard<
file::instance > unref_file(*file_instance_ptr, adopt_ref);
607 ref_guard< instance > unref_req(*instance_ptr, adopt_ref);
610 file_instance_ptr->properties().write_queue_size -= properties.pending_size;
612 auto &write_cb = instance_ptr->request_cb_storage.value();
614 write_cb(write(_uv_req), buffer(properties.uv_buf, adopt_ref));
616 buffer::instance::from(properties.uv_buf)->unref();
625 friend class request::instance< sync >;
629 using on_request_t = std::function<
void(
sync _request) >;
636 struct properties :
fs::properties
638 file::uv_t *uv_handle =
nullptr;
648 explicit sync(uv_t *_uv_req) :
fs(_uv_req) {}
655 uv_req = instance::create();
656 init< UV_FS_FSYNC >();
659 sync(
const sync&) =
default;
660 sync& operator =(
const sync&) =
default;
662 sync(
sync&&)
noexcept =
default;
663 sync& operator =(
sync&&)
noexcept =
default;
666 template<
typename =
void >
static void sync_cb(::uv_fs_t*);
669 on_request_t& on_request()
const noexcept {
return instance::from(uv_req)->request_cb_storage.value(); }
673 file handle()
const noexcept {
return file(instance::from(uv_req)->properties().uv_handle); }
683 int run(
file &_file,
bool _flush_all_metadata =
false)
685 ::uv_fs_req_cleanup(
static_cast< uv_t* >(uv_req));
687 auto uv_fs_sync_func_ptr = _flush_all_metadata ? ::uv_fs_fsync : ::uv_fs_fdatasync;
688 auto instance_ptr = instance::from(uv_req);
690 if (!instance_ptr->request_cb_storage.value())
692 instance_ptr->properties().uv_handle =
static_cast< file::uv_t* >(_file);
694 return uv_status(uv_fs_sync_func_ptr(
695 static_cast< file::uv_t* >(_file)->loop,
static_cast< uv_t* >(uv_req),
702 file::instance::from(_file.uv_handle)->ref();
707 auto &properties = instance_ptr->properties();
708 properties.uv_handle =
static_cast< file::uv_t* >(_file);
712 auto uv_ret = uv_fs_sync_func_ptr(
713 static_cast< file::uv_t* >(_file)->loop,
static_cast< uv_t* >(uv_req),
720 file::instance::from(_file.uv_handle)->unref();
721 instance_ptr->unref();
729 explicit operator
const uv_t*()
const noexcept {
return static_cast<
const uv_t* >(uv_req); }
730 explicit operator uv_t*()
noexcept {
return static_cast< uv_t* >(uv_req); }
734 void fs::
sync::sync_cb(::uv_fs_t *_uv_req)
736 auto instance_ptr = instance::from(_uv_req);
737 instance_ptr->uv_error = _uv_req->result;
739 auto &properties = instance_ptr->properties();
741 ref_guard<
file::instance > unref_file(*file::instance::from(properties.uv_handle), adopt_ref);
742 ref_guard< instance > unref_req(*instance_ptr, adopt_ref);
744 auto &sync_cb = instance_ptr->request_cb_storage.value();
745 if (sync_cb) sync_cb(sync(_uv_req));
754 friend class request::instance< truncate >;
758 using on_request_t = std::function<
void(
truncate _request) >;
765 struct properties :
fs::properties
767 file::uv_t *uv_handle =
nullptr;
778 explicit truncate(uv_t *_uv_req) :
fs(_uv_req) {}
782 ~truncate() =
default;
785 uv_req = instance::create();
786 init< UV_FS_FTRUNCATE >();
789 truncate(
const truncate&) =
default;
792 truncate(
truncate&&)
noexcept =
default;
796 template<
typename =
void >
static void truncate_cb(::uv_fs_t*);
799 on_request_t& on_request()
const noexcept {
return instance::from(uv_req)->request_cb_storage.value(); }
803 file handle()
const noexcept {
return file(instance::from(uv_req)->properties().uv_handle); }
806 int64_t
offset()
const noexcept {
return instance::from(uv_req)->properties().offset; }
816 ::uv_fs_req_cleanup(
static_cast< uv_t* >(uv_req));
822 _offset = _telli64(_file.fd());
824 _offset = lseek64(_file.fd(), 0, SEEK_CUR);
828 auto instance_ptr = instance::from(uv_req);
830 if (!instance_ptr->request_cb_storage.value())
832 auto &properties = instance_ptr->properties();
833 properties.uv_handle =
static_cast< file::uv_t* >(_file);
834 properties.offset = _offset;
836 return uv_status(::uv_fs_ftruncate(
837 static_cast< file::uv_t* >(_file)->loop,
static_cast< uv_t* >(uv_req),
845 file::instance::from(_file.uv_handle)->ref();
850 auto &properties = instance_ptr->properties();
851 properties.uv_handle =
static_cast< file::uv_t* >(_file);
852 properties.offset = _offset;
856 auto uv_ret = ::uv_fs_ftruncate(
857 static_cast< file::uv_t* >(_file)->loop,
static_cast< uv_t* >(uv_req),
865 file::instance::from(_file.uv_handle)->unref();
866 instance_ptr->unref();
874 explicit operator
const uv_t*()
const noexcept {
return static_cast<
const uv_t* >(uv_req); }
875 explicit operator uv_t*()
noexcept {
return static_cast< uv_t* >(uv_req); }
879 void fs::
truncate::truncate_cb(::uv_fs_t *_uv_req)
881 auto instance_ptr = instance::from(_uv_req);
882 instance_ptr->uv_error = _uv_req->result;
884 auto &properties = instance_ptr->properties();
886 ref_guard<
file::instance > unref_file(*file::instance::from(properties.uv_handle), adopt_ref);
887 ref_guard< instance > unref_req(*instance_ptr, adopt_ref);
889 auto &truncate_cb = instance_ptr->request_cb_storage.value();
890 if (truncate_cb) truncate_cb(truncate(_uv_req));
899 friend class request::instance< sendfile >;
904 using on_request_t = std::function<
void(
sendfile _request) >;
911 struct properties :
fs::properties
913 io::uv_t *uv_handle_out =
nullptr;
914 file::uv_t *uv_handle_in =
nullptr;
916 std::size_t pending_size = 0;
926 static constexpr const bool is_convertible_v = std::is_convertible< ::uv_os_fd_t, ::uv_file >::value;
928 template<
bool _is_convertible_ = is_convertible_v >
929 static std::enable_if_t< !_is_convertible_, ::uv_file > try_convert(::uv_os_fd_t) {
return -1; }
930 template<
bool _is_convertible_ = is_convertible_v >
931 static std::enable_if_t< _is_convertible_, ::uv_file > try_convert(::uv_os_fd_t _os_fd) {
return _os_fd; }
936 explicit sendfile(uv_t *_uv_req) :
fs(_uv_req) {}
940 ~sendfile() =
default;
943 uv_req = instance::create();
944 init< UV_FS_SENDFILE >();
947 sendfile(
const sendfile&) =
default;
950 sendfile(
sendfile&&)
noexcept =
default;
954 template<
typename =
void >
static void sendfile_cb(::uv_fs_t*);
957 on_request_t& on_request()
const noexcept {
return instance::from(uv_req)->request_cb_storage.value(); }
961 io handle_out()
const noexcept {
return io(instance::from(uv_req)->properties().uv_handle_out); }
964 file handle_in()
const noexcept {
return file(instance::from(uv_req)->properties().uv_handle_in); }
967 int64_t
offset()
const noexcept {
return instance::from(uv_req)->properties().offset; }
977 int run(
io &_out,
file &_in, int64_t _offset, std::size_t _length)
979 ::uv_fs_req_cleanup(
static_cast< uv_t* >(uv_req));
981 ::uv_file out = _out.type() == UV_FILE ?
static_cast< file& >(_out).fd() : fd::try_convert(_out.fileno());
982 if (out == -1)
return UV_EBADF;
988 _offset = _telli64(_in.fd());
990 _offset = lseek64(_in.fd(), 0, SEEK_CUR);
994 auto instance_ptr = instance::from(uv_req);
996 if (!instance_ptr->request_cb_storage.value())
998 auto &properties = instance_ptr->properties();
999 properties.uv_handle_out =
static_cast< io::uv_t* >(_out);
1000 properties.uv_handle_in =
static_cast< file::uv_t* >(_in);
1001 properties.offset = _offset;
1003 return uv_status(::uv_fs_sendfile(
1004 static_cast< file::uv_t* >(_in)->loop,
static_cast< uv_t* >(uv_req),
1012 io::instance::from(_out.uv_handle)->ref();
1013 file::instance::from(_in.uv_handle)->ref();
1014 instance_ptr->ref();
1018 auto &properties = instance_ptr->properties();
1019 properties.uv_handle_out =
static_cast< io::uv_t* >(_out);
1020 properties.uv_handle_in =
static_cast< file::uv_t* >(_in);
1021 properties.offset = _offset;
1022 properties.pending_size = _length;
1025 if (_out.type() == UV_FILE) file::instance::from(_out.uv_handle)->properties().write_queue_size += _length;
1028 int uv_ret = ::uv_fs_sendfile(
1029 static_cast< file::uv_t* >(_in)->loop,
static_cast< uv_t* >(uv_req),
1038 if (_out.type() == UV_FILE) file::instance::from(_out.uv_handle)->properties().write_queue_size -= _length;
1040 io::instance::from(_out.uv_handle)->unref();
1041 file::instance::from(_in.uv_handle)->unref();
1042 instance_ptr->unref();
1050 explicit operator
const uv_t*()
const noexcept {
return static_cast<
const uv_t* >(uv_req); }
1051 explicit operator uv_t*()
noexcept {
return static_cast< uv_t* >(uv_req); }
1054 template<
typename >
1055 void fs::
sendfile::sendfile_cb(::uv_fs_t *_uv_req)
1057 auto instance_ptr = instance::from(_uv_req);
1058 instance_ptr->uv_error = _uv_req->result;
1060 auto &properties = instance_ptr->properties();
1061 auto handle_out_instance_ptr = io::instance::from(properties.uv_handle_out);
1062 auto handle_in_instance_ptr = file::instance::from(properties.uv_handle_in);
1064 ref_guard<
io::instance > unref_out(*handle_out_instance_ptr, adopt_ref);
1065 ref_guard<
file::instance > unref_in(*handle_in_instance_ptr, adopt_ref);
1066 ref_guard< instance > unref_req(*instance_ptr, adopt_ref);
1068 if (handle_out_instance_ptr->uv_interface()->type(properties.uv_handle_out) == UV_FILE)
1069 reinterpret_cast< file::instance* >(handle_out_instance_ptr)->properties().write_queue_size -= properties.pending_size;
1071 auto &sendfile_cb = instance_ptr->request_cb_storage.value();
1072 if (sendfile_cb) sendfile_cb(sendfile(_uv_req));
1081 friend class request::instance< stat >;
1085 using on_request_t = std::function<
void(
stat _request) >;
1092 struct properties :
fs::properties
1094 file::uv_t *uv_handle =
nullptr;
1104 explicit stat(uv_t *_uv_req) :
fs(_uv_req) {}
1111 uv_req = instance::create();
1112 init< UV_FS_STAT >();
1115 stat(
const stat&) =
default;
1116 stat& operator =(
const stat&) =
default;
1118 stat(
stat&&)
noexcept =
default;
1119 stat& operator =(
stat&&)
noexcept =
default;
1122 template<
typename =
void >
static void stat_cb(::uv_fs_t*);
1125 on_request_t& on_request()
const noexcept {
return instance::from(uv_req)->request_cb_storage.value(); }
1132 auto uv_handle = instance::from(uv_req)->properties().uv_handle;
1133 return uv_handle ? file(uv_handle) : file(
static_cast< uv_t* >(uv_req)->loop, -1,
static_cast< uv_t* >(uv_req)->path);
1140 auto uv_handle = instance::from(uv_req)->properties().uv_handle;
1141 return uv_handle ? uv_handle->path :
static_cast< uv_t* >(uv_req)->path;
1151 const ::uv_stat_t&
result()
const noexcept {
return static_cast< uv_t* >(uv_req)->statbuf; }
1159 int run(
uv::
loop &_loop,
const char* _path,
bool _follow_symlinks =
false)
1161 ::uv_fs_req_cleanup(
static_cast< uv_t* >(uv_req));
1163 auto uv_fs_stat_func_ptr = _follow_symlinks ? ::uv_fs_stat : ::uv_fs_lstat;
1164 auto instance_ptr = instance::from(uv_req);
1166 if (!instance_ptr->request_cb_storage.value())
1168 instance_ptr->properties().uv_handle =
nullptr;
1170 return uv_status(uv_fs_stat_func_ptr(
1171 static_cast<
uv::
loop::uv_t* >(_loop),
static_cast< uv_t* >(uv_req),
1178 instance_ptr->ref();
1182 auto &properties = instance_ptr->properties();
1183 properties.uv_handle =
nullptr;
1187 auto uv_ret = uv_fs_stat_func_ptr(
1188 static_cast< uv::loop::uv_t* >(_loop),
static_cast< uv_t* >(uv_req),
1195 instance_ptr->unref();
1208 ::uv_fs_req_cleanup(
static_cast< uv_t* >(uv_req));
1210 auto instance_ptr = instance::from(uv_req);
1212 if (!instance_ptr->request_cb_storage.value())
1214 instance_ptr->properties().uv_handle =
static_cast< file::uv_t* >(_file);
1216 return uv_status(::uv_fs_fstat(
1217 static_cast< file::uv_t* >(_file)->loop,
static_cast< uv_t* >(uv_req),
1224 file::instance::from(_file.uv_handle)->ref();
1225 instance_ptr->ref();
1229 auto &properties = instance_ptr->properties();
1230 properties.uv_handle =
static_cast< file::uv_t* >(_file);
1234 auto uv_ret = ::uv_fs_fstat(
1235 static_cast< file::uv_t* >(_file)->loop,
static_cast< uv_t* >(uv_req),
1242 file::instance::from(_file.uv_handle)->unref();
1243 instance_ptr->unref();
1251 explicit operator
const uv_t*()
const noexcept {
return static_cast<
const uv_t* >(uv_req); }
1252 explicit operator uv_t*()
noexcept {
return static_cast< uv_t* >(uv_req); }
1255 template<
typename >
1256 void fs::
stat::stat_cb(::uv_fs_t *_uv_req)
1258 auto instance_ptr = instance::from(_uv_req);
1259 instance_ptr->uv_error = _uv_req->result;
1261 auto &properties = instance_ptr->properties();
1263 if (properties.uv_handle)
1265 ref_guard<
file::instance > unref_file(*file::instance::from(properties.uv_handle), adopt_ref);
1266 ref_guard< instance > unref_req(*instance_ptr, adopt_ref);
1268 auto &stat_cb = instance_ptr->request_cb_storage.value();
1269 if (stat_cb) stat_cb(stat(_uv_req));
1273 ref_guard< instance > unref_req(*instance_ptr, adopt_ref);
1275 auto &stat_cb = instance_ptr->request_cb_storage.value();
1276 if (stat_cb) stat_cb(stat(_uv_req));
1286 friend class request::instance< chmod >;
1290 using on_request_t = std::function<
void(
chmod _request) >;
1297 struct properties :
fs::properties
1299 file::uv_t *uv_handle =
nullptr;
1309 explicit chmod(uv_t *_uv_req) :
fs(_uv_req) {}
1316 uv_req = instance::create();
1317 init< UV_FS_CHMOD >();
1320 chmod(
const chmod&) =
default;
1323 chmod(
chmod&&)
noexcept =
default;
1324 chmod& operator =(
chmod&&)
noexcept =
default;
1327 template<
typename =
void >
static void chmod_cb(::uv_fs_t*);
1330 on_request_t& on_request()
const noexcept {
return instance::from(uv_req)->request_cb_storage.value(); }
1337 auto uv_handle = instance::from(uv_req)->properties().uv_handle;
1338 return uv_handle ? file(uv_handle) : file(
static_cast< uv_t* >(uv_req)->loop, -1,
static_cast< uv_t* >(uv_req)->path);
1345 auto uv_handle = instance::from(uv_req)->properties().uv_handle;
1346 return uv_handle ? uv_handle->path :
static_cast< uv_t* >(uv_req)->path;
1356 ::uv_fs_req_cleanup(
static_cast< uv_t* >(uv_req));
1358 auto instance_ptr = instance::from(uv_req);
1360 if (!instance_ptr->request_cb_storage.value())
1362 instance_ptr->properties().uv_handle =
nullptr;
1364 return uv_status(::uv_fs_chmod(
1365 static_cast<
uv::
loop::uv_t* >(_loop),
static_cast< uv_t* >(uv_req),
1372 instance_ptr->ref();
1376 auto &properties = instance_ptr->properties();
1377 properties.uv_handle =
nullptr;
1381 auto uv_ret = ::uv_fs_chmod(
1382 static_cast< uv::loop::uv_t* >(_loop),
static_cast< uv_t* >(uv_req),
1389 instance_ptr->unref();
1402 ::uv_fs_req_cleanup(
static_cast< uv_t* >(uv_req));
1404 auto instance_ptr = instance::from(uv_req);
1406 if (!instance_ptr->request_cb_storage.value())
1408 instance_ptr->properties().uv_handle =
static_cast< file::uv_t* >(_file);
1410 return uv_status(::uv_fs_fchmod(
1411 static_cast< file::uv_t* >(_file)->loop,
static_cast< uv_t* >(uv_req),
1418 file::instance::from(_file.uv_handle)->ref();
1419 instance_ptr->ref();
1423 auto &properties = instance_ptr->properties();
1424 properties.uv_handle =
static_cast< file::uv_t* >(_file);
1428 auto uv_ret = ::uv_fs_fchmod(
1429 static_cast< file::uv_t* >(_file)->loop,
static_cast< uv_t* >(uv_req),
1436 file::instance::from(_file.uv_handle)->unref();
1437 instance_ptr->unref();
1445 explicit operator
const uv_t*()
const noexcept {
return static_cast<
const uv_t* >(uv_req); }
1446 explicit operator uv_t*()
noexcept {
return static_cast< uv_t* >(uv_req); }
1449 template<
typename >
1450 void fs::
chmod::chmod_cb(::uv_fs_t *_uv_req)
1452 auto instance_ptr = instance::from(_uv_req);
1453 instance_ptr->uv_error = _uv_req->result;
1455 auto &properties = instance_ptr->properties();
1457 if (properties.uv_handle)
1459 ref_guard<
file::instance > unref_file(*file::instance::from(properties.uv_handle), adopt_ref);
1460 ref_guard< instance > unref_req(*instance_ptr, adopt_ref);
1462 auto &chmod_cb = instance_ptr->request_cb_storage.value();
1463 if (chmod_cb) chmod_cb(chmod(_uv_req));
1467 ref_guard< instance > unref_req(*instance_ptr, adopt_ref);
1469 auto &chmod_cb = instance_ptr->request_cb_storage.value();
1470 if (chmod_cb) chmod_cb(chmod(_uv_req));
1480 friend class request::instance< chown >;
1484 using on_request_t = std::function<
void(
chown _request) >;
1491 struct properties :
fs::properties
1493 file::uv_t *uv_handle =
nullptr;
1503 explicit chown(uv_t *_uv_req) :
fs(_uv_req) {}
1510 uv_req = instance::create();
1511 init< UV_FS_CHOWN >();
1514 chown(
const chown&) =
default;
1517 chown(
chown&&)
noexcept =
default;
1518 chown& operator =(
chown&&)
noexcept =
default;
1521 template<
typename =
void >
static void chown_cb(::uv_fs_t*);
1524 on_request_t& on_request()
const noexcept {
return instance::from(uv_req)->request_cb_storage.value(); }
1531 auto uv_handle = instance::from(uv_req)->properties().uv_handle;
1532 return uv_handle ? file(uv_handle) : file(
static_cast< uv_t* >(uv_req)->loop, -1,
static_cast< uv_t* >(uv_req)->path);
1539 auto uv_handle = instance::from(uv_req)->properties().uv_handle;
1540 return uv_handle ? uv_handle->path :
static_cast< uv_t* >(uv_req)->path;
1547 int run(
uv::
loop &_loop,
const char* _path, ::uv_uid_t _uid, ::uv_gid_t _gid)
1549 ::uv_fs_req_cleanup(
static_cast< uv_t* >(uv_req));
1551 auto instance_ptr = instance::from(uv_req);
1553 if (!instance_ptr->request_cb_storage.value())
1555 instance_ptr->properties().uv_handle =
nullptr;
1557 return uv_status(::uv_fs_chown(
1558 static_cast< uv::loop::uv_t* >(_loop),
static_cast< uv_t* >(uv_req),
1565 instance_ptr->ref();
1569 auto &properties = instance_ptr->properties();
1570 properties.uv_handle =
nullptr;
1574 auto uv_ret = ::uv_fs_chown(
1575 static_cast< uv::loop::uv_t* >(_loop),
static_cast< uv_t* >(uv_req),
1582 instance_ptr->unref();
1593 int run(
file &_file, ::uv_uid_t _uid, ::uv_gid_t _gid)
1595 ::uv_fs_req_cleanup(
static_cast< uv_t* >(uv_req));
1597 auto instance_ptr = instance::from(uv_req);
1599 if (!instance_ptr->request_cb_storage.value())
1601 instance_ptr->properties().uv_handle =
static_cast< file::uv_t* >(_file);
1603 return uv_status(::uv_fs_fchown(
1604 static_cast< file::uv_t* >(_file)->loop,
static_cast< uv_t* >(uv_req),
1605 _file.fd(), _uid, _gid,
1611 file::instance::from(_file.uv_handle)->ref();
1612 instance_ptr->ref();
1616 auto &properties = instance_ptr->properties();
1617 properties.uv_handle =
static_cast< file::uv_t* >(_file);
1621 auto uv_ret = ::uv_fs_fchown(
1622 static_cast< file::uv_t* >(_file)->loop,
static_cast< uv_t* >(uv_req),
1623 _file.fd(), _uid, _gid,
1629 file::instance::from(_file.uv_handle)->unref();
1630 instance_ptr->unref();
1638 explicit operator
const uv_t*()
const noexcept {
return static_cast<
const uv_t* >(uv_req); }
1639 explicit operator uv_t*()
noexcept {
return static_cast< uv_t* >(uv_req); }
1642 template<
typename >
1643 void fs::
chown::chown_cb(::uv_fs_t *_uv_req)
1645 auto instance_ptr = instance::from(_uv_req);
1646 instance_ptr->uv_error = _uv_req->result;
1648 auto &properties = instance_ptr->properties();
1650 if (properties.uv_handle)
1652 ref_guard<
file::instance > unref_file(*file::instance::from(properties.uv_handle), adopt_ref);
1653 ref_guard< instance > unref_req(*instance_ptr, adopt_ref);
1655 auto &chown_cb = instance_ptr->request_cb_storage.value();
1656 if (chown_cb) chown_cb(chown(_uv_req));
1660 ref_guard< instance > unref_req(*instance_ptr, adopt_ref);
1662 auto &chown_cb = instance_ptr->request_cb_storage.value();
1663 if (chown_cb) chown_cb(chown(_uv_req));
1673 friend class request::instance< utime >;
1677 using on_request_t = std::function<
void(
utime _request) >;
1684 struct properties :
fs::properties
1686 file::uv_t *uv_handle =
nullptr;
1696 explicit utime(uv_t *_uv_req) :
fs(_uv_req) {}
1703 uv_req = instance::create();
1704 init< UV_FS_UTIME >();
1707 utime(
const utime&) =
default;
1710 utime(
utime&&)
noexcept =
default;
1711 utime& operator =(
utime&&)
noexcept =
default;
1714 template<
typename =
void >
static void utime_cb(::uv_fs_t*);
1717 on_request_t& on_request()
const noexcept {
return instance::from(uv_req)->request_cb_storage.value(); }
1724 auto uv_handle = instance::from(uv_req)->properties().uv_handle;
1725 return uv_handle ? file(uv_handle) : file(
static_cast< uv_t* >(uv_req)->loop, -1,
static_cast< uv_t* >(uv_req)->path);
1732 auto uv_handle = instance::from(uv_req)->properties().uv_handle;
1733 return uv_handle ? uv_handle->path :
static_cast< uv_t* >(uv_req)->path;
1741 int run(
uv::
loop &_loop,
const char* _path,
double _atime,
double _mtime)
1743 ::uv_fs_req_cleanup(
static_cast< uv_t* >(uv_req));
1745 auto instance_ptr = instance::from(uv_req);
1747 if (!instance_ptr->request_cb_storage.value())
1749 instance_ptr->properties().uv_handle =
nullptr;
1751 return uv_status(::uv_fs_utime(
1752 static_cast<
uv::
loop::uv_t* >(_loop),
static_cast< uv_t* >(uv_req),
1753 _path, _atime, _mtime,
1759 instance_ptr->ref();
1763 auto &properties = instance_ptr->properties();
1764 properties.uv_handle =
nullptr;
1768 auto uv_ret = ::uv_fs_utime(
1769 static_cast< uv::loop::uv_t* >(_loop),
static_cast< uv_t* >(uv_req),
1770 _path, _atime, _mtime,
1776 instance_ptr->unref();
1787 int run(
file &_file,
double _atime,
double _mtime)
1789 ::uv_fs_req_cleanup(
static_cast< uv_t* >(uv_req));
1791 auto instance_ptr = instance::from(uv_req);
1793 if (!instance_ptr->request_cb_storage.value())
1795 instance_ptr->properties().uv_handle =
static_cast< file::uv_t* >(_file);
1797 return uv_status(::uv_fs_futime(
1798 static_cast< file::uv_t* >(_file)->loop,
static_cast< uv_t* >(uv_req),
1799 _file.fd(), _atime, _mtime,
1805 file::instance::from(_file.uv_handle)->ref();
1806 instance_ptr->ref();
1810 auto &properties = instance_ptr->properties();
1811 properties.uv_handle =
static_cast< file::uv_t* >(_file);
1815 auto uv_ret = ::uv_fs_futime(
1816 static_cast< file::uv_t* >(_file)->loop,
static_cast< uv_t* >(uv_req),
1817 _file.fd(), _atime, _mtime,
1823 file::instance::from(_file.uv_handle)->unref();
1824 instance_ptr->unref();
1832 explicit operator
const uv_t*()
const noexcept {
return static_cast<
const uv_t* >(uv_req); }
1833 explicit operator uv_t*()
noexcept {
return static_cast< uv_t* >(uv_req); }
1836 template<
typename >
1837 void fs::
utime::utime_cb(::uv_fs_t *_uv_req)
1839 auto instance_ptr = instance::from(_uv_req);
1840 instance_ptr->uv_error = _uv_req->result;
1842 auto &properties = instance_ptr->properties();
1844 if (properties.uv_handle)
1846 ref_guard<
file::instance > unref_file(*file::instance::from(properties.uv_handle), adopt_ref);
1847 ref_guard< instance > unref_req(*instance_ptr, adopt_ref);
1849 auto &utime_cb = instance_ptr->request_cb_storage.value();
1850 if (utime_cb) utime_cb(utime(_uv_req));
1854 ref_guard< instance > unref_req(*instance_ptr, adopt_ref);
1856 auto &utime_cb = instance_ptr->request_cb_storage.value();
1857 if (utime_cb) utime_cb(utime(_uv_req));
1867 friend class request::instance< unlink >;
1871 using on_request_t = std::function<
void(
unlink _request) >;
1879 explicit unlink(uv_t *_uv_req) :
fs(_uv_req) {}
1883 ~unlink() =
default;
1886 uv_req = instance::create();
1887 init< UV_FS_UNLINK >();
1890 unlink(
const unlink&) =
default;
1893 unlink(
unlink&&)
noexcept =
default;
1897 template<
typename =
void >
static void unlink_cb(::uv_fs_t*);
1900 on_request_t& on_request()
const noexcept {
return instance::from(uv_req)->request_cb_storage.value(); }
1904 const char*
path()
const noexcept {
return static_cast< uv_t* >(uv_req)->path; }
1912 ::uv_fs_req_cleanup(
static_cast< uv_t* >(uv_req));
1914 auto instance_ptr = instance::from(uv_req);
1916 if (!instance_ptr->request_cb_storage.value())
1918 return uv_status(::uv_fs_unlink(
1919 static_cast<
uv::
loop::uv_t* >(_loop),
static_cast< uv_t* >(uv_req),
1926 instance_ptr->ref();
1929 auto uv_ret = ::uv_fs_unlink(
1930 static_cast< uv::loop::uv_t* >(_loop),
static_cast< uv_t* >(uv_req),
1937 instance_ptr->unref();
1945 explicit operator
const uv_t*()
const noexcept {
return static_cast<
const uv_t* >(uv_req); }
1946 explicit operator uv_t*()
noexcept {
return static_cast< uv_t* >(uv_req); }
1949 template<
typename >
1950 void fs::
unlink::unlink_cb(::uv_fs_t *_uv_req)
1952 auto instance_ptr = instance::from(_uv_req);
1953 instance_ptr->uv_error = _uv_req->result;
1955 ref_guard< instance > unref_req(*instance_ptr, adopt_ref);
1957 auto &unlink_cb = instance_ptr->request_cb_storage.value();
1958 if (unlink_cb) unlink_cb(unlink(_uv_req));
1967 friend class request::instance< mkdir >;
1971 using on_request_t = std::function<
void(
mkdir _request) >;
1979 explicit mkdir(uv_t *_uv_req) :
fs(_uv_req) {}
1986 uv_req = instance::create();
1987 init< UV_FS_MKDIR >();
1990 mkdir(
const mkdir&) =
default;
1993 mkdir(
mkdir&&)
noexcept =
default;
1994 mkdir& operator =(
mkdir&&)
noexcept =
default;
1997 template<
typename =
void >
static void mkdir_cb(::uv_fs_t*);
2000 on_request_t& on_request()
const noexcept {
return instance::from(uv_req)->request_cb_storage.value(); }
2004 const char*
path()
const noexcept {
return static_cast< uv_t* >(uv_req)->path; }
2012 ::uv_fs_req_cleanup(
static_cast< uv_t* >(uv_req));
2014 auto instance_ptr = instance::from(uv_req);
2016 if (!instance_ptr->request_cb_storage.value())
2018 return uv_status(::uv_fs_mkdir(
2019 static_cast<
uv::
loop::uv_t* >(_loop),
static_cast< uv_t* >(uv_req),
2026 instance_ptr->ref();
2029 auto uv_ret = ::uv_fs_mkdir(
2030 static_cast< uv::loop::uv_t* >(_loop),
static_cast< uv_t* >(uv_req),
2037 instance_ptr->unref();
2045 explicit operator
const uv_t*()
const noexcept {
return static_cast<
const uv_t* >(uv_req); }
2046 explicit operator uv_t*()
noexcept {
return static_cast< uv_t* >(uv_req); }
2049 template<
typename >
2050 void fs::
mkdir::mkdir_cb(::uv_fs_t *_uv_req)
2052 auto instance_ptr = instance::from(_uv_req);
2053 instance_ptr->uv_error = _uv_req->result;
2055 ref_guard< instance > unref_req(*instance_ptr, adopt_ref);
2057 auto &mkdir_cb = instance_ptr->request_cb_storage.value();
2058 if (mkdir_cb) mkdir_cb(mkdir(_uv_req));
2067 friend class request::instance< mkdtemp >;
2071 using on_request_t = std::function<
void(
mkdtemp _request) >;
2079 explicit mkdtemp(uv_t *_uv_req) :
fs(_uv_req) {}
2083 ~mkdtemp() =
default;
2086 uv_req = instance::create();
2087 init< UV_FS_MKDTEMP >();
2090 mkdtemp(
const mkdtemp&) =
default;
2093 mkdtemp(
mkdtemp&&)
noexcept =
default;
2097 template<
typename =
void >
static void mkdtemp_cb(::uv_fs_t*);
2100 on_request_t& on_request()
const noexcept {
return instance::from(uv_req)->request_cb_storage.value(); }
2104 const char*
path()
const noexcept {
return static_cast< uv_t* >(uv_req)->path; }
2112 ::uv_fs_req_cleanup(
static_cast< uv_t* >(uv_req));
2114 auto instance_ptr = instance::from(uv_req);
2116 if (!instance_ptr->request_cb_storage.value())
2118 return uv_status(::uv_fs_mkdtemp(
2119 static_cast<
uv::
loop::uv_t* >(_loop),
static_cast< uv_t* >(uv_req),
2126 instance_ptr->ref();
2129 auto uv_ret = ::uv_fs_mkdtemp(
2130 static_cast< uv::loop::uv_t* >(_loop),
static_cast< uv_t* >(uv_req),
2137 instance_ptr->unref();
2145 explicit operator
const uv_t*()
const noexcept {
return static_cast<
const uv_t* >(uv_req); }
2146 explicit operator uv_t*()
noexcept {
return static_cast< uv_t* >(uv_req); }
2149 template<
typename >
2150 void fs::
mkdtemp::mkdtemp_cb(::uv_fs_t *_uv_req)
2152 auto instance_ptr = instance::from(_uv_req);
2153 instance_ptr->uv_error = _uv_req->result;
2155 ref_guard< instance > unref_req(*instance_ptr, adopt_ref);
2157 auto &mkdtemp_cb = instance_ptr->request_cb_storage.value();
2158 if (mkdtemp_cb) mkdtemp_cb(mkdtemp(_uv_req));
2167 friend class request::instance< rmdir >;
2171 using on_request_t = std::function<
void(
rmdir _request) >;
2179 explicit rmdir(uv_t *_uv_req) :
fs(_uv_req) {}
2186 uv_req = instance::create();
2187 init< UV_FS_RMDIR >();
2190 rmdir(
const rmdir&) =
default;
2193 rmdir(
rmdir&&)
noexcept =
default;
2194 rmdir& operator =(
rmdir&&)
noexcept =
default;
2197 template<
typename =
void >
static void rmdir_cb(::uv_fs_t*);
2200 on_request_t& on_request()
const noexcept {
return instance::from(uv_req)->request_cb_storage.value(); }
2204 const char*
path()
const noexcept {
return static_cast< uv_t* >(uv_req)->path; }
2212 ::uv_fs_req_cleanup(
static_cast< uv_t* >(uv_req));
2214 auto instance_ptr = instance::from(uv_req);
2216 if (!instance_ptr->request_cb_storage.value())
2218 return uv_status(::uv_fs_rmdir(
2219 static_cast<
uv::
loop::uv_t* >(_loop),
static_cast< uv_t* >(uv_req),
2226 instance_ptr->ref();
2229 auto uv_ret = ::uv_fs_rmdir(
2230 static_cast< uv::loop::uv_t* >(_loop),
static_cast< uv_t* >(uv_req),
2237 instance_ptr->unref();
2245 explicit operator
const uv_t*()
const noexcept {
return static_cast<
const uv_t* >(uv_req); }
2246 explicit operator uv_t*()
noexcept {
return static_cast< uv_t* >(uv_req); }
2249 template<
typename >
2250 void fs::
rmdir::rmdir_cb(::uv_fs_t *_uv_req)
2252 auto instance_ptr = instance::from(_uv_req);
2253 instance_ptr->uv_error = _uv_req->result;
2255 ref_guard< instance > unref_req(*instance_ptr, adopt_ref);
2257 auto &rmdir_cb = instance_ptr->request_cb_storage.value();
2258 if (rmdir_cb) rmdir_cb(rmdir(_uv_req));
2267 friend class request::instance< scandir >;
2271 using on_request_t = std::function<
void(
scandir _request) >;
2279 explicit scandir(uv_t *_uv_req) :
fs(_uv_req) {}
2283 ~scandir() =
default;
2286 uv_req = instance::create();
2287 init< UV_FS_SCANDIR >();
2290 scandir(
const scandir&) =
default;
2293 scandir(
scandir&&)
noexcept =
default;
2297 template<
typename =
void >
static void scandir_cb(::uv_fs_t*);
2300 on_request_t& on_request()
const noexcept {
return instance::from(uv_req)->request_cb_storage.value(); }
2304 const char*
path()
const noexcept {
return static_cast< uv_t* >(uv_req)->path; }
2312 {
return uv_status(uv_fs_scandir_next(
static_cast< uv_t* >(uv_req), &_entry)); }
2322 ::uv_fs_req_cleanup(
static_cast< uv_t* >(uv_req));
2324 auto instance_ptr = instance::from(uv_req);
2326 if (!instance_ptr->request_cb_storage.value())
2328 return uv_status(::uv_fs_scandir(
2329 static_cast<
uv::
loop::uv_t* >(_loop),
static_cast< uv_t* >(uv_req),
2336 instance_ptr->ref();
2339 auto uv_ret = ::uv_fs_scandir(
2340 static_cast< uv::loop::uv_t* >(_loop),
static_cast< uv_t* >(uv_req),
2347 instance_ptr->unref();
2355 explicit operator
const uv_t*()
const noexcept {
return static_cast<
const uv_t* >(uv_req); }
2356 explicit operator uv_t*()
noexcept {
return static_cast< uv_t* >(uv_req); }
2359 template<
typename >
2360 void fs::
scandir::scandir_cb(::uv_fs_t *_uv_req)
2362 auto instance_ptr = instance::from(_uv_req);
2363 instance_ptr->uv_error = _uv_req->result;
2365 ref_guard< instance > unref_req(*instance_ptr, adopt_ref);
2367 auto &scandir_cb = instance_ptr->request_cb_storage.value();
2368 if (scandir_cb) scandir_cb(scandir(_uv_req));
2377 friend class request::instance< rename >;
2381 using on_request_t = std::function<
void(
rename _request) >;
2389 explicit rename(uv_t *_uv_req) :
fs(_uv_req) {}
2393 ~rename() =
default;
2396 uv_req = instance::create();
2397 init< UV_FS_RENAME >();
2400 rename(
const rename&) =
default;
2403 rename(
rename&&)
noexcept =
default;
2407 template<
typename =
void >
static void rename_cb(::uv_fs_t*);
2410 on_request_t& on_request()
const noexcept {
return instance::from(uv_req)->request_cb_storage.value(); }
2418 return reinterpret_cast<
const char* >(
static_cast< uv_t* >(uv_req)->file.pathw);
2420 return static_cast< uv_t* >(uv_req)->path;
2428 return reinterpret_cast<
const char* >(
static_cast< uv_t* >(uv_req)->fs.info.new_pathw);
2430 return static_cast< uv_t* >(uv_req)->new_path;
2438 int run(
uv::
loop &_loop,
const char* _path,
const char* _new_path)
2440 ::uv_fs_req_cleanup(
static_cast< uv_t* >(uv_req));
2442 auto instance_ptr = instance::from(uv_req);
2444 if (!instance_ptr->request_cb_storage.value())
2446 return uv_status(::uv_fs_rename(
2447 static_cast<
uv::
loop::uv_t* >(_loop),
static_cast< uv_t* >(uv_req),
2454 instance_ptr->ref();
2457 auto uv_ret = ::uv_fs_rename(
2458 static_cast< uv::loop::uv_t* >(_loop),
static_cast< uv_t* >(uv_req),
2465 instance_ptr->unref();
2473 explicit operator
const uv_t*()
const noexcept {
return static_cast<
const uv_t* >(uv_req); }
2474 explicit operator uv_t*()
noexcept {
return static_cast< uv_t* >(uv_req); }
2477 template<
typename >
2478 void fs::
rename::rename_cb(::uv_fs_t *_uv_req)
2480 auto instance_ptr = instance::from(_uv_req);
2481 instance_ptr->uv_error = _uv_req->result;
2483 ref_guard< instance > unref_req(*instance_ptr, adopt_ref);
2485 auto &rename_cb = instance_ptr->request_cb_storage.value();
2486 if (rename_cb) rename_cb(rename(_uv_req));
2495 friend class request::instance< access >;
2499 using on_request_t = std::function<
void(
access _request) >;
2507 explicit access(uv_t *_uv_req) :
fs(_uv_req) {}
2511 ~access() =
default;
2514 uv_req = instance::create();
2515 init< UV_FS_ACCESS >();
2518 access(
const access&) =
default;
2521 access(
access&&)
noexcept =
default;
2525 template<
typename =
void >
static void access_cb(::uv_fs_t*);
2528 on_request_t& on_request()
const noexcept {
return instance::from(uv_req)->request_cb_storage.value(); }
2532 const char*
path()
const noexcept {
return static_cast< uv_t* >(uv_req)->path; }
2540 ::uv_fs_req_cleanup(
static_cast< uv_t* >(uv_req));
2542 auto instance_ptr = instance::from(uv_req);
2544 if (!instance_ptr->request_cb_storage.value())
2546 return uv_status(::uv_fs_access(
2547 static_cast<
uv::
loop::uv_t* >(_loop),
static_cast< uv_t* >(uv_req),
2554 instance_ptr->ref();
2557 auto uv_ret = ::uv_fs_access(
2558 static_cast< uv::loop::uv_t* >(_loop),
static_cast< uv_t* >(uv_req),
2565 instance_ptr->unref();
2573 explicit operator
const uv_t*()
const noexcept {
return static_cast<
const uv_t* >(uv_req); }
2574 explicit operator uv_t*()
noexcept {
return static_cast< uv_t* >(uv_req); }
2577 template<
typename >
2578 void fs::
access::access_cb(::uv_fs_t *_uv_req)
2580 auto instance_ptr = instance::from(_uv_req);
2581 instance_ptr->uv_error = _uv_req->result;
2583 ref_guard< instance > unref_req(*instance_ptr, adopt_ref);
2585 auto &access_cb = instance_ptr->request_cb_storage.value();
2586 if (access_cb) access_cb(access(_uv_req));
2595 friend class request::instance< link >;
2599 using on_request_t = std::function<
void(
link _request) >;
2607 explicit link(uv_t *_uv_req) :
fs(_uv_req) {}
2614 uv_req = instance::create();
2615 init< UV_FS_LINK >();
2618 link(
const link&) =
default;
2619 link& operator =(
const link&) =
default;
2621 link(
link&&)
noexcept =
default;
2622 link& operator =(
link&&)
noexcept =
default;
2625 template<
typename =
void >
static void link_cb(::uv_fs_t*);
2628 on_request_t& on_request()
const noexcept {
return instance::from(uv_req)->request_cb_storage.value(); }
2636 return reinterpret_cast<
const char* >(
static_cast< uv_t* >(uv_req)->file.pathw);
2638 return static_cast< uv_t* >(uv_req)->path;
2646 return reinterpret_cast<
const char* >(
static_cast< uv_t* >(uv_req)->fs.info.new_pathw);
2648 return static_cast< uv_t* >(uv_req)->new_path;
2668 int run(
uv::
loop &_loop,
const char* _path,
const char* _link_path,
bool _symlink,
int _symlink_flags = 0)
2670 ::uv_fs_req_cleanup(
static_cast< uv_t* >(uv_req));
2672 auto instance_ptr = instance::from(uv_req);
2674 if (!instance_ptr->request_cb_storage.value())
2676 if (_symlink)
return uv_status(::uv_fs_symlink(
2677 static_cast<
uv::
loop::uv_t* >(_loop),
static_cast< uv_t* >(uv_req),
2678 _path, _link_path, _symlink_flags,
2681 else return uv_status(::uv_fs_link(
2682 static_cast<
uv::
loop::uv_t* >(_loop),
static_cast< uv_t* >(uv_req),
2689 instance_ptr->ref();
2693 if (_symlink) uv_ret = ::uv_fs_symlink(
2694 static_cast< uv::loop::uv_t* >(_loop),
static_cast< uv_t* >(uv_req),
2695 _path, _link_path, _symlink_flags,
2698 else uv_ret = ::uv_fs_link(
2699 static_cast< uv::loop::uv_t* >(_loop),
static_cast< uv_t* >(uv_req),
2706 instance_ptr->unref();
2714 explicit operator
const uv_t*()
const noexcept {
return static_cast<
const uv_t* >(uv_req); }
2715 explicit operator uv_t*()
noexcept {
return static_cast< uv_t* >(uv_req); }
2718 template<
typename >
2719 void fs::
link::link_cb(::uv_fs_t *_uv_req)
2721 auto instance_ptr = instance::from(_uv_req);
2722 instance_ptr->uv_error = _uv_req->result;
2724 ref_guard< instance > unref_req(*instance_ptr, adopt_ref);
2726 auto &link_cb = instance_ptr->request_cb_storage.value();
2727 if (link_cb) link_cb(link(_uv_req));
2736 friend class request::instance< readlink >;
2740 using on_request_t = std::function<
void(
readlink _request) >;
2748 explicit readlink(uv_t *_uv_req) :
fs(_uv_req) {}
2752 ~readlink() =
default;
2755 uv_req = instance::create();
2756 init< UV_FS_READLINK >();
2759 readlink(
const readlink&) =
default;
2762 readlink(
readlink&&)
noexcept =
default;
2766 template<
typename =
void >
static void readlink_cb(::uv_fs_t*);
2769 on_request_t& on_request()
const noexcept {
return instance::from(uv_req)->request_cb_storage.value(); }
2773 const char*
path()
const noexcept {
return static_cast< uv_t* >(uv_req)->path; }
2776 const char*
result()
const noexcept {
return static_cast<
const char* >(
static_cast< uv_t* >(uv_req)->ptr); }
2784 ::uv_fs_req_cleanup(
static_cast< uv_t* >(uv_req));
2786 auto instance_ptr = instance::from(uv_req);
2788 if (!instance_ptr->request_cb_storage.value())
2790 return uv_status(::uv_fs_readlink(
2791 static_cast<
uv::
loop::uv_t* >(_loop),
static_cast< uv_t* >(uv_req),
2798 instance_ptr->ref();
2801 auto uv_ret = ::uv_fs_readlink(
2802 static_cast< uv::loop::uv_t* >(_loop),
static_cast< uv_t* >(uv_req),
2809 instance_ptr->unref();
2817 explicit operator
const uv_t*()
const noexcept {
return static_cast<
const uv_t* >(uv_req); }
2818 explicit operator uv_t*()
noexcept {
return static_cast< uv_t* >(uv_req); }
2821 template<
typename >
2822 void fs::
readlink::readlink_cb(::uv_fs_t *_uv_req)
2824 auto instance_ptr = instance::from(_uv_req);
2825 instance_ptr->uv_error = _uv_req->result;
2827 ref_guard< instance > unref_req(*instance_ptr, adopt_ref);
2829 auto &readlink_cb = instance_ptr->request_cb_storage.value();
2830 if (readlink_cb) readlink_cb(readlink(_uv_req));
2839 friend class request::instance< realpath >;
2843 using on_request_t = std::function<
void(
realpath _request) >;
2851 explicit realpath(uv_t *_uv_req) :
fs(_uv_req) {}
2855 ~realpath() =
default;
2858 uv_req = instance::create();
2859 init< UV_FS_REALPATH >();
2862 realpath(
const realpath&) =
default;
2865 realpath(
realpath&&)
noexcept =
default;
2869 template<
typename =
void >
static void realpath_cb(::uv_fs_t*);
2872 on_request_t& on_request()
const noexcept {
return instance::from(uv_req)->request_cb_storage.value(); }
2876 const char*
path()
const noexcept {
return static_cast< uv_t* >(uv_req)->path; }
2879 const char*
result()
const noexcept {
return static_cast<
const char* >(
static_cast< uv_t* >(uv_req)->ptr); }
2887 ::uv_fs_req_cleanup(
static_cast< uv_t* >(uv_req));
2889 auto instance_ptr = instance::from(uv_req);
2891 if (!instance_ptr->request_cb_storage.value())
2893 return uv_status(::uv_fs_realpath(
2894 static_cast<
uv::
loop::uv_t* >(_loop),
static_cast< uv_t* >(uv_req),
2901 instance_ptr->ref();
2904 auto uv_ret = ::uv_fs_realpath(
2905 static_cast< uv::loop::uv_t* >(_loop),
static_cast< uv_t* >(uv_req),
2912 instance_ptr->unref();
2920 explicit operator
const uv_t*()
const noexcept {
return static_cast<
const uv_t* >(uv_req); }
2921 explicit operator uv_t*()
noexcept {
return static_cast< uv_t* >(uv_req); }
2924 template<
typename >
2925 void fs::
realpath::realpath_cb(::uv_fs_t *_uv_req)
2927 auto instance_ptr = instance::from(_uv_req);
2928 instance_ptr->uv_error = _uv_req->result;
2930 ref_guard< instance > unref_req(*instance_ptr, adopt_ref);
2932 auto &realpath_cb = instance_ptr->request_cb_storage.value();
2933 if (realpath_cb) realpath_cb(realpath(_uv_req));
io handle_out() const noexcept
The I/O endpoint which this sendfile request has been writing data to.
Namespace for all uvcc definitions.
int run(uv::loop &_loop, const char *_path, ::uv_uid_t _uid, ::uv_gid_t _gid)
Run the request. Change the owner and group of a file or directory specified by _path.
Get canonicalized absolute pathname.
const char * path() const noexcept
The file path affected by request.
int run(file &_file, int _mode)
Run the request. Change permissions of the open _file.
Change the name or location of a file.
operator bool() const noexcept
Equivalent to (base() != nullptr).
file handle() const noexcept
The file which this stat request has been running on.
int run(uv::loop &_loop, const char *_path, int _mode)
Run the request. Change permissions of a file or directory specified by _path.
const char * result() const noexcept
The result of the readlink request.
The base class for the libuv requests.
Transfer data between file descriptors.
file handle() const noexcept
The file which this write request has been running on.
int run(uv::loop &_loop, const char *_path, bool _follow_symlinks=false)
Run the request. Get status information on a file or directory specified by _path.
Get information about a file.
const char * new_path() const noexcept
The file path affected by request.
Read value of a symbolic link.
int run(uv::loop &_loop, const char *_path, const char *_new_path)
Run the request. Renames a file, moving it between directories if required.
Synchronize a file's state with storage device.
const char * path() const noexcept
The file path affected by request.
const char * path() const noexcept
The file path affected by request.
Change ownership of a file. (Not implemented on Windows.)
int run(uv::loop &_loop, const char *_path)
Run the request. Get canonicalized absolute pathname.
file handle() const noexcept
The file which this read request has been running on.
const char * link_path() const noexcept
The new name for the path affected by request.
int64_t offset() const noexcept
The offset this write request has been performed at.
Truncate a file to a specified length.
int run(file &_file, buffer &_buf, int64_t _offset)
Run the request. Read data from the _file into the buffers described by _buf object.
The base calss for filesystem requests.
int64_t offset() const noexcept
The offset this read request has been performed at.
const char * path() const noexcept
The file path affected by request.
int scandir_next(::uv_dirent_t &_entry) const noexcept
Get the results of the scandir request.
int run(uv::loop &_loop, const char *_template)
Run the request. Create a temporary directory with unique name generated from _template string...
int read_stop() const
Stop reading data from the I/O endpoint.
int run(file &_file)
Run the request. Close a _file handle.
Delete a file name and possibly the file itself that the name refers to.
const char * path() const noexcept
The file path affected by request.
const char * path() const noexcept
The file path affected by request.
int64_t offset() const noexcept
The offset this sendfile request has been started to read data at from input file.
const ::uv_stat_t & result() const noexcept
The result of the stat request.
int run(file &_file, ::uv_uid_t _uid, ::uv_gid_t _gid)
Run the request. Change the owner and group of the open _file.
int run(file &_file, int64_t _offset)
Run the request. Truncate the _file to a size of _offset bytes.
const char * path() const noexcept
The file path affected by request.
Check user's permissions for a file.
const char * path() const noexcept
The path of the directory created by request.
const char * path() const noexcept
The file path affected by request.
file handle() const noexcept
The file which this truncate request has been running on.
file handle() const noexcept
The file which this utime request has been running on.
file handle() const noexcept
The file which this chown request has been running on.
int try_write(file &_file, const buffer &_buf, int64_t _offset)
Try to execute the request synchronously if it can be completed immediately...
int run(uv::loop &_loop, const char *_path, const char *_link_path, bool _symlink, int _symlink_flags=0)
Run the request. Make a new name for a target specified by _path.
int run(uv::loop &_loop, const char *_path)
Run the request. Read value of a symbolic link specified by _path.
The I/O event loop class.
int run(uv::loop &_loop, const char *_path, int _mode)
Run the request. Check if the calling process can access the file specified by _path using the access...
The base class for handles representing I/O endpoints: a file, TCP/UDP socket, pipe, TTY.
A scoped reference counting guard.
const char * path() const noexcept
The file path affected by request.
int run(uv::loop &_loop, const char *_path)
Run the request. Delete a file name specified by _path.
int64_t offset() const noexcept
The offset this trucate request has been performed at.
const char * path() const noexcept
The file path affected by request.
int run(file &_file, const buffer &_buf, int64_t _offset)
Run the request. Write data to the _file from the buffers described by _buf object.
int run(uv::loop &_loop, const char *_path)
Run the request. Scan a directory specified by _path.
const char * path() const noexcept
The file path affected by request.
int run(io &_out, file &_in, int64_t _offset, std::size_t _length)
Run the request. Read data from the _in file starting from the _offset and copy it to the _out endpoi...
int run(file &_file, bool _flush_all_metadata=false)
Run the request. Flush the data of the _file to the storage device.
Create a new link to a file.
file handle() const noexcept
The file which this chmod request has been running on.
const char * result() const noexcept
The result of the realpath request.
int run(uv::loop &_loop, const char *_path)
Run the request. Delete a directory (which must be empty) specified by _path.
file handle() const noexcept
The file which this sync request has been running on.
std::size_t write_queue_size() const noexcept
The amount of bytes waiting to be written to the file.
const char * path() const noexcept
The file path affected by request.
int run(uv::loop &_loop, const char *_path, int _mode)
Run the request. Create a directory specified by _path.
file handle_in() const noexcept
The file which this sendfile request has been reading data from.
int run(uv::loop &_loop, const char *_path, double _atime, double _mtime)
Run the request. Change last access and modification times for a file or directory specified by _path...
int run(file &_file)
Run the request. Get status information about the open _file.
const char * path() const noexcept
The file path affected by request.
::uv_fs_type fs_type() const noexcept
The tag indicating a subtype of the filesystem request.
file handle() const noexcept
The file which this close request has been running on.
Create a uniquely named temporary directory.
int run(file &_file, double _atime, double _mtime)
Run the request. Change last access and modification times for the open _file.