uvw 3.1.0
Loading...
Searching...
No Matches
request.hpp
1#ifndef UVW_REQUEST_INCLUDE_H
2#define UVW_REQUEST_INCLUDE_H
3
4#include <memory>
5#include <type_traits>
6#include <utility>
7#include <uv.h>
8#include "config.h"
9#include "resource.hpp"
10
11namespace uvw {
12
18template<typename T, typename U, typename... E>
19class request: public resource<T, U, E...> {
20protected:
21 static auto reserve(U *req) {
22 auto ptr = static_cast<T *>(req->data)->shared_from_this();
23 ptr->self_reset();
24 return ptr;
25 }
26
27public:
28 using resource<T, U, E...>::resource;
29
42 int cancel() {
43 return uv_cancel(reinterpret_cast<uv_req_t *>(this->raw()));
44 }
45
50 std::size_t size() const noexcept {
51 return uv_req_size(reinterpret_cast<const uv_req_t *>(this->raw())->type);
52 }
53};
54
55} // namespace uvw
56
57#endif // UVW_REQUEST_INCLUDE_H
Request base class.
Definition: request.hpp:19
int cancel()
Cancels a pending request.
Definition: request.hpp:42
std::size_t size() const noexcept
Returns the size of the underlying request type.
Definition: request.hpp:50
Common class for almost all the resources available in uvw.
Definition: resource.hpp:18
uvw default namespace.
Definition: async.h:8
static constexpr std::uint32_t type() noexcept
Returns a numerical identifier for a given type.
Definition: type_info.hpp:53
const U * raw() const noexcept
Gets the underlying raw data structure.
Definition: uv_type.hpp:59