WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
GetAddrInfo.hpp
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <functional>
8#include <memory>
9#include <optional>
10#include <string_view>
11#include <utility>
12
13#include <uv.h>
14
16#include "wpi/util/Signal.h"
17
18namespace wpi::net::uv {
19
20class Loop;
21
22/**
23 * GetAddrInfo request.
24 * For use with `GetAddrInfo()` function family.
25 */
26class GetAddrInfoReq : public RequestImpl<GetAddrInfoReq, uv_getaddrinfo_t> {
27 public:
29
30 Loop& GetLoop() const { return *static_cast<Loop*>(GetRaw()->loop->data); }
31
32 /**
33 * Resolved lookup signal.
34 * Parameter is resolved address info.
35 */
37};
38
39/**
40 * Asynchronous getaddrinfo(3). HandleResolvedAddress() is called on the
41 * request when the resolution completes. HandleError() is called on the
42 * request if any errors occur.
43 *
44 * Either node or service may be empty but not both.
45 *
46 * @param loop Event loop
47 * @param req request
48 * @param node Either a numerical network address or a network hostname.
49 * @param service Either a service name or a port number as a string.
50 * @param hints Optional `addrinfo` data structure with additional address
51 * type constraints.
52 */
53void GetAddrInfo(Loop& loop, const std::shared_ptr<GetAddrInfoReq>& req,
54 std::string_view node, std::string_view service = {},
55 std::optional<addrinfo> hints = {});
56
57/**
58 * Asynchronous getaddrinfo(3). HandleResolvedAddress() is called on the
59 * request when the resolution completes. HandleError() is called on the
60 * request if any errors occur.
61 *
62 * Either node or service may be empty but not both.
63 *
64 * @param loop Event loop
65 * @param req request
66 * @param node Either a numerical network address or a network hostname.
67 * @param service Either a service name or a port number as a string.
68 * @param hints Optional `addrinfo` data structure with additional address
69 * type constraints.
70 */
71inline void GetAddrInfo(const std::shared_ptr<Loop>& loop,
72 const std::shared_ptr<GetAddrInfoReq>& req,
73 std::string_view node, std::string_view service = {},
74 std::optional<addrinfo> hints = {}) {
75 GetAddrInfo(*loop, req, node, service, hints);
76}
77
78/**
79 * Asynchronous getaddrinfo(3). The callback is called when the resolution
80 * completes, and errors are forwarded to the loop. This is a convenience
81 * wrapper.
82 *
83 * Either node or service may be empty but not both.
84 *
85 * @param loop Event loop
86 * @param callback Callback function to call when resolution completes
87 * @param node Either a numerical network address or a network hostname.
88 * @param service Either a service name or a port number as a string.
89 * @param hints Optional `addrinfo` data structure with additional address
90 * type constraints.
91 */
92void GetAddrInfo(Loop& loop, std::function<void(const addrinfo&)> callback,
93 std::string_view node, std::string_view service = {},
94 std::optional<addrinfo> hints = {});
95
96/**
97 * Asynchronous getaddrinfo(3). The callback is called when the resolution
98 * completes, and errors are forwarded to the loop. This is a convenience
99 * wrapper.
100 *
101 * Either node or service may be empty but not both.
102 *
103 * @param loop Event loop
104 * @param callback Callback function to call when resolution completes
105 * @param node Either a numerical network address or a network hostname.
106 * @param service Either a service name or a port number as a string.
107 * @param hints Optional `addrinfo` data structure with additional address
108 * type constraints.
109 */
110inline void GetAddrInfo(const std::shared_ptr<Loop>& loop,
111 std::function<void(const addrinfo&)> callback,
112 std::string_view node, std::string_view service = {},
113 std::optional<addrinfo> hints = {}) {
114 GetAddrInfo(*loop, std::move(callback), node, service, hints);
115}
116
117} // namespace wpi::net::uv
Loop & GetLoop() const
Definition GetAddrInfo.hpp:30
wpi::util::sig::Signal< const addrinfo & > resolved
Resolved lookup signal.
Definition GetAddrInfo.hpp:36
Event loop.
Definition Loop.hpp:35
uv_getaddrinfo_t * GetRaw() noexcept
Definition Request.hpp:149
Definition Prepare.hpp:14
void GetAddrInfo(Loop &loop, const std::shared_ptr< GetAddrInfoReq > &req, std::string_view node, std::string_view service={}, std::optional< addrinfo > hints={})
Asynchronous getaddrinfo(3).
SignalBase< detail::NullMutex, T... > Signal
Specialization of SignalBase to be used in single threaded contexts.
Definition Signal.h:809
UV_REQ_FIELDS uv_loop_t * loop
Definition uv.h:968
void * data
Definition uv.h:1907