uvco 0.1
Loading...
Searching...
No Matches
Classes | Typedefs | Functions | Variables
Utilities

Classes

struct  uvco::UvHandleDeleter
 
class  uvco::RefCounted< T >
 
class  uvco::LifetimeTracker< T >
 
class  uvco::FlagGuard
 
class  uvco::ZeroAtExit< T >
 

Typedefs

using uvco::uv_status = int
 Result of a libuv operation, an errno error code.
 

Functions

void uvco::allocator (uv_handle_t *, size_t sugg, uv_buf_t *buf)
 libuv allocator.
 
void uvco::freeUvBuf (const uv_buf_t *buf)
 
template<typename R , typename F >
requires std::is_invocable_r_v<R, F, std::string_view>
uvco::callWithNullTerminated (std::string_view view, F &&f)
 
template<typename Into , typename Handle >
Into * uvco::getData (const Handle *handle)
 
template<typename Into , typename Request >
Into * uvco::getRequestData (const Request *req)
 
template<typename Handle , typename Data >
void uvco::setData (Handle *handle, Data *data)
 
template<typename Request , typename Data >
void uvco::setRequestData (Request *req, Data *data)
 
template<typename Handle >
bool uvco::dataIsNull (Handle *handle)
 
template<typename Request >
bool uvco::requestDataIsNull (Request *req)
 
template<typename T , typename... Args>
requires std::derived_from<T, RefCounted<T>>
T * uvco::makeRefCounted (Args... args)
 Create a new refcounted value. T must derive from RefCounted<T>.
 

Variables

const bool uvco::TRACK_LIFETIMES = true
 

Detailed Description

Typedef Documentation

◆ uv_status

using uvco::uv_status = int

Result of a libuv operation, an errno error code.

Function Documentation

◆ allocator()

void uvco::allocator ( uv_handle_t *  ,
size_t  sugg,
uv_buf_t *  buf 
)

libuv allocator.

18 {
19 constexpr static size_t defaultSize = 4080;
20 const size_t size = std::min(defaultSize, sugg);
21 char *underlying = new char[size];
22 buf->base = underlying;
23 buf->len = size;
24}

◆ callWithNullTerminated()

template<typename R , typename F >
requires std::is_invocable_r_v<R, F, std::string_view>
R uvco::callWithNullTerminated ( std::string_view  view,
F &&  f 
)
33 {
34 if (view.data()[view.size()] == '\0') {
35 return f(view.data());
36 }
37 std::string str(view);
38 return f(str.c_str());
39}

◆ dataIsNull()

template<typename Handle >
bool uvco::dataIsNull ( Handle *  handle)
66 {
67 return nullptr == uv_handle_get_data((const uv_handle_t *)handle);
68}

◆ freeUvBuf()

void uvco::freeUvBuf ( const uv_buf_t *  buf)
26 {
27 if (buf)
28 delete[] buf->base;
29}

◆ getData()

template<typename Into , typename Handle >
Into * uvco::getData ( const Handle *  handle)
41 {
42 const void *data = uv_handle_get_data((const uv_handle_t *)handle);
43 BOOST_ASSERT(nullptr != data);
44 return (Into *)data;
45}

◆ getRequestData()

template<typename Into , typename Request >
Into * uvco::getRequestData ( const Request *  req)
48 {
49 const void *data = uv_req_get_data((const uv_req_t *)req);
50 BOOST_ASSERT(nullptr != data);
51 return (Into *)data;
52}

◆ makeRefCounted()

template<typename T , typename... Args>
requires std::derived_from<T, RefCounted<T>>
T * uvco::makeRefCounted ( Args...  args)

Create a new refcounted value. T must derive from RefCounted<T>.

135{
136 if constexpr (sizeof...(args) == 0) {
137 return new T{};
138 } else {
139 return new T{std::forward<Args...>(args...)};
140 }
141}

◆ requestDataIsNull()

template<typename Request >
bool uvco::requestDataIsNull ( Request *  req)
70 {
71 return nullptr == uv_req_get_data((const uv_req_t *)req);
72}

◆ setData()

template<typename Handle , typename Data >
void uvco::setData ( Handle *  handle,
Data *  data 
)
55 {
56 BOOST_ASSERT(handle != nullptr);
57 uv_handle_set_data((uv_handle_t *)handle, (void *)data);
58}

◆ setRequestData()

template<typename Request , typename Data >
void uvco::setRequestData ( Request *  req,
Data *  data 
)
61 {
62 BOOST_ASSERT(req != nullptr);
63 uv_req_set_data((uv_req_t *)req, (void *)data);
64}

Variable Documentation

◆ TRACK_LIFETIMES

const bool uvco::TRACK_LIFETIMES = true