WPILibC++ 2027.0.0-alpha-3
Loading...
Searching...
No Matches
GetNameInfo.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_GETNAMEINFO_H_
6#define WPINET_UV_GETNAMEINFO_H_
7
8#include <uv.h>
9
10#include <functional>
11#include <memory>
12#include <string_view>
13#include <utility>
14
15#include <wpi/Signal.h>
16
17#include "wpinet/uv/Request.h"
18
19namespace wpi::uv {
20
21class Loop;
22
23/**
24 * GetNameInfo request.
25 * For use with `GetNameInfo()` function family.
26 */
27class GetNameInfoReq : public RequestImpl<GetNameInfoReq, uv_getnameinfo_t> {
28 public:
30
31 Loop& GetLoop() const { return *static_cast<Loop*>(GetRaw()->loop->data); }
32
33 /**
34 * Resolved lookup signal.
35 * Parameters are hostname and service.
36 */
38};
39
40/**
41 * Asynchronous getnameinfo(3). HandleResolvedName() is called on the
42 * request when the resolution completes. HandleError() is called on the
43 * request if any errors occur.
44 *
45 * @param loop Event loop
46 * @param req request
47 * @param addr Initialized `sockaddr_in` or `sockaddr_in6` data structure.
48 * @param flags Optional flags to modify the behavior of `getnameinfo`.
49 */
50void GetNameInfo(Loop& loop, const std::shared_ptr<GetNameInfoReq>& req,
51 const sockaddr& addr, int flags = 0);
52
53/**
54 * Asynchronous getnameinfo(3). HandleResolvedName() is called on the
55 * request when the resolution completes. HandleError() is called on the
56 * request if any errors occur.
57 *
58 * @param loop Event loop
59 * @param req request
60 * @param addr Initialized `sockaddr_in` or `sockaddr_in6` data structure.
61 * @param flags Optional flags to modify the behavior of `getnameinfo`.
62 */
63inline void GetNameInfo(const std::shared_ptr<Loop>& loop,
64 const std::shared_ptr<GetNameInfoReq>& req,
65 const sockaddr& addr, int flags = 0) {
66 GetNameInfo(*loop, req, addr, flags);
67}
68
69/**
70 * Asynchronous getnameinfo(3). The callback is called when the resolution
71 * completes, and errors are forwarded to the loop.
72 *
73 * @param loop Event loop
74 * @param callback Callback function to call when resolution completes
75 * @param addr Initialized `sockaddr_in` or `sockaddr_in6` data structure.
76 * @param flags Optional flags to modify the behavior of `getnameinfo`.
77 */
78void GetNameInfo(Loop& loop,
79 std::function<void(const char*, const char*)> callback,
80 const sockaddr& addr, int flags = 0);
81
82/**
83 * Asynchronous getnameinfo(3). The callback is called when the resolution
84 * completes, and errors are forwarded to the loop.
85 *
86 * @param loop Event loop
87 * @param callback Callback function to call when resolution completes
88 * @param addr Initialized `sockaddr_in` or `sockaddr_in6` data structure.
89 * @param flags Optional flags to modify the behavior of `getnameinfo`.
90 */
91inline void GetNameInfo(const std::shared_ptr<Loop>& loop,
92 std::function<void(const char*, const char*)> callback,
93 const sockaddr& addr, int flags = 0) {
94 GetNameInfo(*loop, std::move(callback), addr, flags);
95}
96
97/**
98 * Asynchronous IPv4 getnameinfo(3). HandleResolvedName() is called on the
99 * request when the resolution completes. HandleError() is called on the
100 * request if any errors occur.
101 *
102 * @param loop Event loop
103 * @param req request
104 * @param ip A valid IPv4 address
105 * @param port A valid port number
106 * @param flags Optional flags to modify the behavior of `getnameinfo`.
107 */
108void GetNameInfo4(Loop& loop, const std::shared_ptr<GetNameInfoReq>& req,
109 std::string_view ip, unsigned int port, int flags = 0);
110
111/**
112 * Asynchronous IPv4 getnameinfo(3). HandleResolvedName() is called on the
113 * request when the resolution completes. HandleError() is called on the
114 * request if any errors occur.
115 *
116 * @param loop Event loop
117 * @param req request
118 * @param ip A valid IPv4 address
119 * @param port A valid port number
120 * @param flags Optional flags to modify the behavior of `getnameinfo`.
121 */
122inline void GetNameInfo4(const std::shared_ptr<Loop>& loop,
123 const std::shared_ptr<GetNameInfoReq>& req,
124 std::string_view ip, unsigned int port,
125 int flags = 0) {
126 return GetNameInfo4(*loop, req, ip, port, flags);
127}
128
129/**
130 * Asynchronous IPv4 getnameinfo(3). The callback is called when the resolution
131 * completes, and errors are forwarded to the loop.
132 *
133 * @param loop Event loop
134 * @param callback Callback function to call when resolution completes
135 * @param ip A valid IPv4 address
136 * @param port A valid port number
137 * @param flags Optional flags to modify the behavior of `getnameinfo`.
138 */
140 std::function<void(const char*, const char*)> callback,
141 std::string_view ip, unsigned int port, int flags = 0);
142
143/**
144 * Asynchronous IPv4 getnameinfo(3). The callback is called when the resolution
145 * completes, and errors are forwarded to the loop. This is a convenience
146 * wrapper.
147 *
148 * @param loop Event loop
149 * @param ip A valid IPv4 address
150 * @param port A valid port number
151 * @param callback Callback function to call when resolution completes
152 * @param flags Optional flags to modify the behavior of `getnameinfo`.
153 */
154inline void GetNameInfo4(const std::shared_ptr<Loop>& loop,
155 std::function<void(const char*, const char*)> callback,
156 std::string_view ip, unsigned int port,
157 int flags = 0) {
158 return GetNameInfo4(*loop, std::move(callback), ip, port, flags);
159}
160
161/**
162 * Asynchronous IPv6 getnameinfo(3). HandleResolvedName() is called on the
163 * request when the resolution completes. HandleError() is called on the
164 * request if any errors occur.
165 *
166 * @param loop Event loop
167 * @param req request
168 * @param ip A valid IPv6 address
169 * @param port A valid port number
170 * @param flags Optional flags to modify the behavior of `getnameinfo`.
171 */
172void GetNameInfo6(Loop& loop, const std::shared_ptr<GetNameInfoReq>& req,
173 std::string_view ip, unsigned int port, int flags = 0);
174
175/**
176 * Asynchronous IPv6 getnameinfo(3). HandleResolvedName() is called on the
177 * request when the resolution completes. HandleError() is called on the
178 * request if any errors occur.
179 *
180 * @param loop Event loop
181 * @param req request
182 * @param ip A valid IPv6 address
183 * @param port A valid port number
184 * @param flags Optional flags to modify the behavior of `getnameinfo`.
185 */
186inline void GetNameInfo6(const std::shared_ptr<Loop>& loop,
187 const std::shared_ptr<GetNameInfoReq>& req,
188 std::string_view ip, unsigned int port,
189 int flags = 0) {
190 GetNameInfo6(*loop, req, ip, port, flags);
191}
192
193/**
194 * Asynchronous IPv6 getnameinfo(3). The callback is called when the resolution
195 * completes, and errors are forwarded to the loop. This is a convenience
196 * wrapper.
197 *
198 * @param loop Event loop
199 * @param callback Callback function to call when resolution completes
200 * @param ip A valid IPv6 address
201 * @param port A valid port number
202 * @param flags Optional flags to modify the behavior of `getnameinfo`.
203 */
205 std::function<void(const char*, const char*)> callback,
206 std::string_view ip, unsigned int port, int flags = 0);
207
208/**
209 * Asynchronous IPv6 getnameinfo(3). The callback is called when the resolution
210 * completes, and errors are forwarded to the loop. This is a convenience
211 * wrapper.
212 *
213 * @param loop Event loop
214 * @param callback Callback function to call when resolution completes
215 * @param ip A valid IPv6 address
216 * @param port A valid port number
217 * @param flags Optional flags to modify the behavior of `getnameinfo`.
218 */
219inline void GetNameInfo6(const std::shared_ptr<Loop>& loop,
220 std::function<void(const char*, const char*)> callback,
221 std::string_view ip, unsigned int port,
222 int flags = 0) {
223 return GetNameInfo6(*loop, std::move(callback), ip, port, flags);
224}
225
226} // namespace wpi::uv
227
228#endif // WPINET_UV_GETNAMEINFO_H_
SignalBase is an implementation of the observer pattern, through the use of an emitting object and sl...
Definition Signal.h:495
GetNameInfo request.
Definition GetNameInfo.h:27
Loop & GetLoop() const
Definition GetNameInfo.h:31
sig::Signal< const char *, const char * > resolved
Resolved lookup signal.
Definition GetNameInfo.h:37
Event loop.
Definition Loop.h:37
Request.
Definition Request.h:135
uv_getnameinfo_t * GetRaw() noexcept
Definition Request.h:150
Definition Loop.h:22
void GetNameInfo6(Loop &loop, const std::shared_ptr< GetNameInfoReq > &req, std::string_view ip, unsigned int port, int flags=0)
Asynchronous IPv6 getnameinfo(3).
void GetNameInfo(Loop &loop, const std::shared_ptr< GetNameInfoReq > &req, const sockaddr &addr, int flags=0)
Asynchronous getnameinfo(3).
void GetNameInfo4(Loop &loop, const std::shared_ptr< GetNameInfoReq > &req, std::string_view ip, unsigned int port, int flags=0)
Asynchronous IPv4 getnameinfo(3).
flags
Definition http_parser.h:206
UV_REQ_FIELDS uv_loop_t * loop
Definition uv.h:991
void * data
Definition uv.h:1907