uvco 0.1
Loading...
Searching...
No Matches
Utilities

Classes

struct  uvco::UvHandleDeleter
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)
 Obtain data pointer set on handle with nullptr check and type cast.
template<typename Into, typename Handle>
Into * uvco::getDataOrNull (const Handle *handle)
template<typename Into, typename Request>
Into * uvco::getRequestData (const Request *req)
 Obtain data pointer set on request with nullptr check and type cast.
template<typename Into, typename Request>
Into * uvco::getRequestDataOrNull (const Request *req)
template<typename Handle, typename Data>
void uvco::setData (Handle *handle, Data *data)
 Obtain data pointer set on request with type cast. Data may be nullptr.
template<typename Handle>
void uvco::resetData (Handle *handle)
 Reset data pointer on handle to nullptr.
template<typename Request, typename Data>
void uvco::setRequestData (Request *req, Data *data)
 Set data pointer on request.
template<typename Request>
void uvco::resetRequestData (Request *req)
template<typename Handle>
bool uvco::dataIsNull (Handle *handle)
 Check if handle data is null.
template<typename Request>
bool uvco::requestDataIsNull (Request *req)
 Check if request data is null.

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)

Check if handle data is null.

101 {
102 BOOST_ASSERT(handle != nullptr);
103 return nullptr == uv_handle_get_data((const uv_handle_t *)handle);
104}

◆ freeUvBuf()

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

◆ getData()

template<typename Into, typename Handle>
Into * uvco::getData ( const Handle * handle)

Obtain data pointer set on handle with nullptr check and type cast.

42 {
43 BOOST_ASSERT(handle != nullptr);
44 const void *data = uv_handle_get_data((const uv_handle_t *)handle);
45 BOOST_ASSERT(nullptr != data);
46 return (Into *)data;
47}

◆ getDataOrNull()

template<typename Into, typename Handle>
Into * uvco::getDataOrNull ( const Handle * handle)

Obtain data pointer set on handle with type cast. Returns nullptr if no data is set.

51 {
52 BOOST_ASSERT(handle != nullptr);
53 const void *data = uv_handle_get_data((const uv_handle_t *)handle);
54 return (Into *)data;
55}

◆ getRequestData()

template<typename Into, typename Request>
Into * uvco::getRequestData ( const Request * req)

Obtain data pointer set on request with nullptr check and type cast.

59 {
60 BOOST_ASSERT(req != nullptr);
61 const void *data = uv_req_get_data((const uv_req_t *)req);
62 BOOST_ASSERT(nullptr != data);
63 return (Into *)data;
64}

◆ getRequestDataOrNull()

template<typename Into, typename Request>
Into * uvco::getRequestDataOrNull ( const Request * req)

Obtain data pointer set on request with type cast. Returns nullptr if data is nullptr.

69 {
70 BOOST_ASSERT(req != nullptr);
71 const void *data = uv_req_get_data((const uv_req_t *)req);
72 return (Into *)data;
73}

◆ requestDataIsNull()

template<typename Request>
bool uvco::requestDataIsNull ( Request * req)

Check if request data is null.

107 {
108 return nullptr == uv_req_get_data((const uv_req_t *)req);
109}

◆ resetData()

template<typename Handle>
void uvco::resetData ( Handle * handle)

Reset data pointer on handle to nullptr.

83 {
84 BOOST_ASSERT(handle != nullptr);
85 uv_handle_set_data((uv_handle_t *)handle, nullptr);
86}

◆ resetRequestData()

template<typename Request>
void uvco::resetRequestData ( Request * req)
95 {
96 BOOST_ASSERT(req != nullptr);
97 uv_req_set_data((uv_req_t *)req, (void *)nullptr);
98}

◆ setData()

template<typename Handle, typename Data>
void uvco::setData ( Handle * handle,
Data * data )

Obtain data pointer set on request with type cast. Data may be nullptr.

77 {
78 BOOST_ASSERT(handle != nullptr);
79 uv_handle_set_data((uv_handle_t *)handle, (void *)data);
80}

◆ setRequestData()

template<typename Request, typename Data>
void uvco::setRequestData ( Request * req,
Data * data )

Set data pointer on request.

90 {
91 BOOST_ASSERT(req != nullptr);
92 uv_req_set_data((uv_req_t *)req, (void *)data);
93}

Variable Documentation

◆ TRACK_LIFETIMES

const bool uvco::TRACK_LIFETIMES = true