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