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
49: req_{std::make_unique<uv_fs_t>()} {}
std::unique_ptr< uv_fs_t > req_
Definition fs.cc:101

◆ 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
57 {
58 if (!requestDataIsNull(req_.get())) {
59 // A callback is pending and the FileOp is aborted. Clean up.
61 // The onFileOpDone callback will clean up after us.
62 uv_cancel((uv_req_t *)req_.release());
63 } else {
64 uv_fs_req_cleanup(req_.get());
65 }
66 }
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
72 {
73 return result_.has_value();
74 }
std::optional< ssize_t > result_
Definition fs.cc:103

◆ 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.

87 {
88 BOOST_ASSERT(result_);
89 BOOST_ASSERT(!requestDataIsNull(req_.get()));
91 if (result_ && result_.value() < 0) {
92 throw UvcoException(static_cast<uv_status>(result_.value()),
93 "file operation failed");
94 } else if (!result_) {
95 throw UvcoException(UV_EAGAIN,
96 "file operation not yet finished (this is a bug)");
97 }
98 }
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
76 {
77 BOOST_ASSERT(!result_);
78 BOOST_ASSERT_MSG(!handle_, "FileOpAwaiter_ can only be awaited once");
79 BOOST_ASSERT(requestDataIsNull(req_.get()));
80 setRequestData(req_.get(), this);
81 handle_ = handle;
82 return true;
83 }
std::coroutine_handle handle_
Definition fs.cc:102
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 || req->result == UV_ECANCELED) {
39 // cancelled
40 uv_fs_req_cleanup(req);
41 delete req;
42 return;
43 }
44 awaiter->result_ = req->result;
45 awaiter->schedule();
46 }
uv_fs_t & req()
Obtain the uv_fs_t struct to fill in before starting the operation.
Definition fs.cc:69
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.

69{ return *req_; }

◆ schedule()

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

◆ uvCallback()

uv_fs_cb uvco::anonymous_namespace{fs.cc}::FileOpAwaiter_::uvCallback ( )
inlinestaticnodiscard
70{ 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: