WPILibC++ 2025.2.1
Loading...
Searching...
No Matches
GetAddrInfo.h
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#ifndef WPINET_UV_GETADDRINFO_H_
6#define WPINET_UV_GETADDRINFO_H_
7
8#include <uv.h>
9
10#include <functional>
11#include <memory>
12#include <optional>
13#include <string_view>
14#include <utility>
15
16#include <wpi/Signal.h>
17
18#include "wpinet/uv/Request.h"
19
20namespace wpi::uv {
21
22class Loop;
23
24/**
25 * GetAddrInfo request.
26 * For use with `GetAddrInfo()` function family.
27 */
28class GetAddrInfoReq : public RequestImpl<GetAddrInfoReq, uv_getaddrinfo_t> {
29 public:
31
32 Loop& GetLoop() const { return *static_cast<Loop*>(GetRaw()->loop->data); }
33
34 /**
35 * Resolved lookup signal.
36 * Parameter is resolved address info.
37 */
39};
40
41/**
42 * Asynchronous getaddrinfo(3). HandleResolvedAddress() is called on the
43 * request when the resolution completes. HandleError() is called on the
44 * request if any errors occur.
45 *
46 * Either node or service may be empty but not both.
47 *
48 * @param loop Event loop
49 * @param req request
50 * @param node Either a numerical network address or a network hostname.
51 * @param service Either a service name or a port number as a string.
52 * @param hints Optional `addrinfo` data structure with additional address
53 * type constraints.
54 */
55void GetAddrInfo(Loop& loop, const std::shared_ptr<GetAddrInfoReq>& req,
56 std::string_view node, std::string_view service = {},
57 std::optional<addrinfo> hints = {});
58
59/**
60 * Asynchronous getaddrinfo(3). HandleResolvedAddress() is called on the
61 * request when the resolution completes. HandleError() is called on the
62 * request if any errors occur.
63 *
64 * Either node or service may be empty but not both.
65 *
66 * @param loop Event loop
67 * @param req request
68 * @param node Either a numerical network address or a network hostname.
69 * @param service Either a service name or a port number as a string.
70 * @param hints Optional `addrinfo` data structure with additional address
71 * type constraints.
72 */
73inline void GetAddrInfo(const std::shared_ptr<Loop>& loop,
74 const std::shared_ptr<GetAddrInfoReq>& req,
75 std::string_view node, std::string_view service = {},
76 std::optional<addrinfo> hints = {}) {
77 GetAddrInfo(*loop, req, node, service, hints);
78}
79
80/**
81 * Asynchronous getaddrinfo(3). The callback is called when the resolution
82 * completes, and errors are forwarded to the loop. This is a convenience
83 * wrapper.
84 *
85 * Either node or service may be empty but not both.
86 *
87 * @param loop Event loop
88 * @param callback Callback function to call when resolution completes
89 * @param node Either a numerical network address or a network hostname.
90 * @param service Either a service name or a port number as a string.
91 * @param hints Optional `addrinfo` data structure with additional address
92 * type constraints.
93 */
94void GetAddrInfo(Loop& loop, std::function<void(const addrinfo&)> callback,
95 std::string_view node, std::string_view service = {},
96 std::optional<addrinfo> hints = {});
97
98/**
99 * Asynchronous getaddrinfo(3). The callback is called when the resolution
100 * completes, and errors are forwarded to the loop. This is a convenience
101 * wrapper.
102 *
103 * Either node or service may be empty but not both.
104 *
105 * @param loop Event loop
106 * @param callback Callback function to call when resolution completes
107 * @param node Either a numerical network address or a network hostname.
108 * @param service Either a service name or a port number as a string.
109 * @param hints Optional `addrinfo` data structure with additional address
110 * type constraints.
111 */
112inline void GetAddrInfo(const std::shared_ptr<Loop>& loop,
113 std::function<void(const addrinfo&)> callback,
114 std::string_view node, std::string_view service = {},
115 std::optional<addrinfo> hints = {}) {
116 GetAddrInfo(*loop, std::move(callback), node, service, hints);
117}
118
119} // namespace wpi::uv
120
121#endif // WPINET_UV_GETADDRINFO_H_
SignalBase is an implementation of the observer pattern, through the use of an emitting object and sl...
Definition Signal.h:495
GetAddrInfo request.
Definition GetAddrInfo.h:28
sig::Signal< const addrinfo & > resolved
Resolved lookup signal.
Definition GetAddrInfo.h:38
Loop & GetLoop() const
Definition GetAddrInfo.h:32
Event loop.
Definition Loop.h:37
Request.
Definition Request.h:135
uv_getaddrinfo_t * GetRaw() noexcept
Definition Request.h:150
Definition Loop.h:22
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).
UV_REQ_FIELDS uv_loop_t * loop
Definition uv.h:968
void * data
Definition uv.h:1907