uvco 0.1
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
uvco::Resolver Class Reference

Asynchronous name resolution using the libuv getaddrinfo(3) interface. More...

#include <name_resolution.h>

Collaboration diagram for uvco::Resolver:
Collaboration graph
[legend]

Classes

struct  AddrinfoAwaiter_
 

Public Member Functions

 Resolver (const Loop &loop)
 Instantiate a resolver based on an event loop.
 
Promise< AddressHandlegai (std::string_view host, std::string_view port, int af_hint=AF_UNSPEC)
 Resolve a host and port string. Throws an UvcoException upon error.
 
Promise< AddressHandlegai (std::string_view host, uint16_t port, int af_hint=AF_UNSPEC)
 

Static Private Member Functions

static void onAddrinfo (uv_getaddrinfo_t *req, uv_status status, struct addrinfo *result)
 

Private Attributes

const Looploop_
 

Detailed Description

Asynchronous name resolution using the libuv getaddrinfo(3) interface.

Constructor & Destructor Documentation

◆ Resolver()

uvco::Resolver::Resolver ( const Loop loop)
inlineexplicit

Instantiate a resolver based on an event loop.

89: loop_{&loop} {}
const Loop * loop_
Definition name_resolution.h:100

Member Function Documentation

◆ gai() [1/2]

Promise< AddressHandle > uvco::Resolver::gai ( std::string_view  host,
std::string_view  port,
int  af_hint = AF_UNSPEC 
)

Resolve a host and port string. Throws an UvcoException upon error.

154 {
155 AddrinfoAwaiter_ awaiter;
156 awaiter.req_.data = &awaiter;
157 struct addrinfo hints {};
158 hints.ai_family = af_hint;
159 hints.ai_socktype = SOCK_STREAM;
160
161 uv_getaddrinfo(loop_->uvloop(), &awaiter.req_, onAddrinfo, host.data(),
162 port.data(), &hints);
163 // Npte: we rely on libuv not resuming before awaiting the result.
164 struct addrinfo *result = co_await awaiter;
165
166 uv_status status = awaiter.status_.value();
167 if (status != 0) {
168 throw UvcoException{status, "getaddrinfo()"};
169 }
170
171 AddressHandle address{result};
172 uv_freeaddrinfo(result);
173
174 co_return address;
175}
uv_loop_t * uvloop() const
Get a non-owned pointer to the loop.
Definition loop.cc:62
static void onAddrinfo(uv_getaddrinfo_t *req, uv_status status, struct addrinfo *result)
Definition name_resolution.cc:177
int uv_status
Result of a libuv operation, an errno error code.
Definition internal_utils.h:22

◆ gai() [2/2]

Promise< AddressHandle > uvco::Resolver::gai ( std::string_view  host,
uint16_t  port,
int  af_hint = AF_UNSPEC 
)

Resolve a host string and numeric port. Throws an UvcoException upon error.

148 {
149 const std::string portStr = std::to_string(port);
150 return gai(host, portStr, af_hint);
151}
Promise< AddressHandle > gai(std::string_view host, std::string_view port, int af_hint=AF_UNSPEC)
Resolve a host and port string. Throws an UvcoException upon error.
Definition name_resolution.cc:153

◆ onAddrinfo()

void uvco::Resolver::onAddrinfo ( uv_getaddrinfo_t *  req,
uv_status  status,
struct addrinfo *  result 
)
staticprivate
178 {
179 auto *awaiter = getRequestData<AddrinfoAwaiter_>(req);
180 awaiter->addrinfo_ = result;
181 awaiter->status_ = status;
182 BOOST_ASSERT(awaiter->handle_);
183 Loop::enqueue(*awaiter->handle_);
184}
static void enqueue(std::coroutine_handle<> handle)
Definition loop.cc:73

Member Data Documentation

◆ loop_

const Loop* uvco::Resolver::loop_
private

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