WPILibC++ 2023.4.3-108-ge5452e3
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 * @return Connection object for the callback
91 */
92inline void GetNameInfo(const std::shared_ptr<Loop>& loop,
93 std::function<void(const char*, const char*)> callback,
94 const sockaddr& addr, int flags = 0) {
95 GetNameInfo(*loop, std::move(callback), addr, flags);
96}
97
98/**
99 * Asynchronous IPv4 getnameinfo(3). HandleResolvedName() is called on the
100 * request when the resolution completes. HandleError() is called on the
101 * request if any errors occur.
102 *
103 * @param loop Event loop
104 * @param req request
105 * @param ip A valid IPv4 address
106 * @param port A valid port number
107 * @param flags Optional flags to modify the behavior of `getnameinfo`.
108 */
109void GetNameInfo4(Loop& loop, const std::shared_ptr<GetNameInfoReq>& req,
110 std::string_view ip, unsigned int port, int flags = 0);
111
112/**
113 * Asynchronous IPv4 getnameinfo(3). HandleResolvedName() is called on the
114 * request when the resolution completes. HandleError() is called on the
115 * request if any errors occur.
116 *
117 * @param loop Event loop
118 * @param req request
119 * @param ip A valid IPv4 address
120 * @param port A valid port number
121 * @param flags Optional flags to modify the behavior of `getnameinfo`.
122 */
123inline void GetNameInfo4(const std::shared_ptr<Loop>& loop,
124 const std::shared_ptr<GetNameInfoReq>& req,
125 std::string_view ip, unsigned int port,
126 int flags = 0) {
127 return GetNameInfo4(*loop, req, ip, port, flags);
128}
129
130/**
131 * Asynchronous IPv4 getnameinfo(3). The callback is called when the resolution
132 * completes, and errors are forwarded to the loop.
133 *
134 * @param loop Event loop
135 * @param callback Callback function to call when resolution completes
136 * @param ip A valid IPv4 address
137 * @param port A valid port number
138 * @param flags Optional flags to modify the behavior of `getnameinfo`.
139 */
141 std::function<void(const char*, const char*)> callback,
142 std::string_view ip, unsigned int port, int flags = 0);
143
144/**
145 * Asynchronous IPv4 getnameinfo(3). The callback is called when the resolution
146 * completes, and errors are forwarded to the loop. This is a convenience
147 * wrapper.
148 *
149 * @param loop Event loop
150 * @param ip A valid IPv4 address
151 * @param port A valid port number
152 * @param callback Callback function to call when resolution completes
153 * @param flags Optional flags to modify the behavior of `getnameinfo`.
154 */
155inline void GetNameInfo4(const std::shared_ptr<Loop>& loop,
156 std::function<void(const char*, const char*)> callback,
157 std::string_view ip, unsigned int port,
158 int flags = 0) {
159 return GetNameInfo4(*loop, std::move(callback), ip, port, flags);
160}
161
162/**
163 * Asynchronous IPv6 getnameinfo(3). HandleResolvedName() is called on the
164 * request when the resolution completes. HandleError() is called on the
165 * request if any errors occur.
166 *
167 * @param loop Event loop
168 * @param req request
169 * @param ip A valid IPv6 address
170 * @param port A valid port number
171 * @param flags Optional flags to modify the behavior of `getnameinfo`.
172 */
173void GetNameInfo6(Loop& loop, const std::shared_ptr<GetNameInfoReq>& req,
174 std::string_view ip, unsigned int port, int flags = 0);
175
176/**
177 * Asynchronous IPv6 getnameinfo(3). HandleResolvedName() is called on the
178 * request when the resolution completes. HandleError() is called on the
179 * request if any errors occur.
180 *
181 * @param loop Event loop
182 * @param req request
183 * @param ip A valid IPv6 address
184 * @param port A valid port number
185 * @param flags Optional flags to modify the behavior of `getnameinfo`.
186 */
187inline void GetNameInfo6(const std::shared_ptr<Loop>& loop,
188 const std::shared_ptr<GetNameInfoReq>& req,
189 std::string_view ip, unsigned int port,
190 int flags = 0) {
191 GetNameInfo6(*loop, req, ip, port, flags);
192}
193
194/**
195 * Asynchronous IPv6 getnameinfo(3). The callback is called when the resolution
196 * completes, and errors are forwarded to the loop. This is a convenience
197 * wrapper.
198 *
199 * @param loop Event loop
200 * @param callback Callback function to call when resolution completes
201 * @param ip A valid IPv6 address
202 * @param port A valid port number
203 * @param flags Optional flags to modify the behavior of `getnameinfo`.
204 */
206 std::function<void(const char*, const char*)> callback,
207 std::string_view ip, unsigned int port, int flags = 0);
208
209/**
210 * Asynchronous IPv6 getnameinfo(3). The callback is called when the resolution
211 * completes, and errors are forwarded to the loop. This is a convenience
212 * wrapper.
213 *
214 * @param loop Event loop
215 * @param callback Callback function to call when resolution completes
216 * @param ip A valid IPv6 address
217 * @param port A valid port number
218 * @param flags Optional flags to modify the behavior of `getnameinfo`.
219 */
220inline void GetNameInfo6(const std::shared_ptr<Loop>& loop,
221 std::function<void(const char*, const char*)> callback,
222 std::string_view ip, unsigned int port,
223 int flags = 0) {
224 return GetNameInfo6(*loop, std::move(callback), ip, port, flags);
225}
226
227} // namespace wpi::uv
228
229#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:130
uv_getnameinfo_t * GetRaw() noexcept
Get the underlying request data structure.
Definition: Request.h:145
basic_string_view< char > string_view
Definition: core.h:520
Definition: Buffer.h:18
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:916
void * data
Definition: uv.h:1795