uvco 0.1
Loading...
Searching...
No Matches
uvco::anonymous_namespace{fs.cc}::FileOpAwaiter_ Class Reference

Public Member Functions

 FileOpAwaiter_ ()
 FileOpAwaiter_ (const FileOpAwaiter_ &)=delete
 FileOpAwaiter_ (FileOpAwaiter_ &&)=delete
FileOpAwaiter_operator= (const FileOpAwaiter_ &)=delete
FileOpAwaiter_operator= (FileOpAwaiter_ &&)=delete
 ~FileOpAwaiter_ ()
uv_fs_t & req ()
 Obtain the uv_fs_t struct to fill in before starting the operation.
bool await_ready () const noexcept
bool await_suspend (std::coroutine_handle<> handle)
void await_resume ()

Static Public Member Functions

static uv_fs_cb uvCallback ()

Private Member Functions

void schedule ()

Static Private Member Functions

static void onFileOpDone (uv_fs_t *req)

Private Attributes

std::unique_ptr< uv_fs_t > req_
std::coroutine_handle handle_
std::optional< ssize_t > result_ = std::nullopt

Constructor & Destructor Documentation

◆ FileOpAwaiter_() [1/3]

uvco::anonymous_namespace{fs.cc}::FileOpAwaiter_::FileOpAwaiter_ ( )
inline
52: req_{std::make_unique<uv_fs_t>()} {}
std::unique_ptr< uv_fs_t > req_
Definition fs.cc:104

◆ FileOpAwaiter_() [2/3]

uvco::anonymous_namespace{fs.cc}::FileOpAwaiter_::FileOpAwaiter_ ( const FileOpAwaiter_ & )
delete

◆ FileOpAwaiter_() [3/3]

uvco::anonymous_namespace{fs.cc}::FileOpAwaiter_::FileOpAwaiter_ ( FileOpAwaiter_ && )
delete

◆ ~FileOpAwaiter_()

uvco::anonymous_namespace{fs.cc}::FileOpAwaiter_::~FileOpAwaiter_ ( )
inline
60 {
61 if (!requestDataIsNull(req_.get())) {
62 // A callback is pending and the FileOp is aborted. Clean up.
64 // The onFileOpDone callback will clean up after us.
65 uv_cancel((uv_req_t *)req_.release());
66 } else {
67 uv_fs_req_cleanup(req_.get());
68 }
69 }
void resetRequestData(Request *req)
Definition internal_utils.h:95
bool requestDataIsNull(Request *req)
Check if request data is null.
Definition internal_utils.h:107

Member Function Documentation

◆ await_ready()

bool uvco::anonymous_namespace{fs.cc}::FileOpAwaiter_::await_ready ( ) const
inlinenodiscardnoexcept
75 {
76 return result_.has_value();
77 }
std::optional< ssize_t > result_
Definition fs.cc:106

◆ await_resume()

void uvco::anonymous_namespace{fs.cc}::FileOpAwaiter_::await_resume ( )
inline

The callback is guaranteed to have been called once the awaiting coroutine is resumed.

90 {
91 BOOST_ASSERT(result_);
92 BOOST_ASSERT(!requestDataIsNull(req_.get()));
94 if (result_ && result_.value() < 0) {
95 throw UvcoException(static_cast<uv_status>(result_.value()),
96 "file operation failed");
97 } else if (!result_) {
98 throw UvcoException(UV_EAGAIN,
99 "file operation not yet finished (this is a bug)");
100 }
101 }
int uv_status
Result of a libuv operation, an errno error code.
Definition internal_utils.h:22

◆ await_suspend()

bool uvco::anonymous_namespace{fs.cc}::FileOpAwaiter_::await_suspend ( std::coroutine_handle<> handle)
inline
79 {
80 BOOST_ASSERT(!result_);
81 BOOST_ASSERT_MSG(!handle_, "FileOpAwaiter_ can only be awaited once");
82 BOOST_ASSERT(requestDataIsNull(req_.get()));
83 setRequestData(req_.get(), this);
84 handle_ = handle;
85 return true;
86 }
std::coroutine_handle handle_
Definition fs.cc:105
void setRequestData(Request *req, Data *data)
Set data pointer on request.
Definition internal_utils.h:90

◆ onFileOpDone()

void uvco::anonymous_namespace{fs.cc}::FileOpAwaiter_::onFileOpDone ( uv_fs_t * req)
inlinestaticprivate
36 {
38 if (awaiter == nullptr) {
39 // cancelled
40 uv_fs_req_cleanup(req);
41 delete req;
42 return;
43 }
44 if (req->result == UV_ECANCELED) {
45 return;
46 }
47 awaiter->result_ = req->result;
48 awaiter->schedule();
49 }
uv_fs_t & req()
Obtain the uv_fs_t struct to fill in before starting the operation.
Definition fs.cc:72
Into * getRequestDataOrNull(const Request *req)
Definition internal_utils.h:69

◆ operator=() [1/2]

FileOpAwaiter_ & uvco::anonymous_namespace{fs.cc}::FileOpAwaiter_::operator= ( const FileOpAwaiter_ & )
delete

◆ operator=() [2/2]

FileOpAwaiter_ & uvco::anonymous_namespace{fs.cc}::FileOpAwaiter_::operator= ( FileOpAwaiter_ && )
delete

◆ req()

uv_fs_t & uvco::anonymous_namespace{fs.cc}::FileOpAwaiter_::req ( )
inlinenodiscard

Obtain the uv_fs_t struct to fill in before starting the operation.

72{ return *req_; }

◆ schedule()

void uvco::anonymous_namespace{fs.cc}::FileOpAwaiter_::schedule ( )
inlineprivate
108 {
109 if (handle_) {
111 handle_ = nullptr;
112 }
113 }
static void enqueue(std::coroutine_handle<> handle)
Definition loop.cc:94

◆ uvCallback()

uv_fs_cb uvco::anonymous_namespace{fs.cc}::FileOpAwaiter_::uvCallback ( )
inlinestaticnodiscard
73{ return onFileOpDone; }
static void onFileOpDone(uv_fs_t *req)
Definition fs.cc:36

Member Data Documentation

◆ handle_

std::coroutine_handle uvco::anonymous_namespace{fs.cc}::FileOpAwaiter_::handle_
private

◆ req_

std::unique_ptr<uv_fs_t> uvco::anonymous_namespace{fs.cc}::FileOpAwaiter_::req_
private

◆ result_

std::optional<ssize_t> uvco::anonymous_namespace{fs.cc}::FileOpAwaiter_::result_ = std::nullopt
private

The documentation for this class was generated from the following file: