WPILibC++ 2024.3.2
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 <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 * GetAddrInfo request.
25 * For use with `GetAddrInfo()` function family.
26 */
27class GetAddrInfoReq : public RequestImpl<GetAddrInfoReq, uv_getaddrinfo_t> {
28 public:
30
31 Loop& GetLoop() const { return *static_cast<Loop*>(GetRaw()->loop->data); }
32
33 /**
34 * Resolved lookup signal.
35 * Parameter is resolved address info.
36 */
38};
39
40/**
41 * Asynchronous getaddrinfo(3). HandleResolvedAddress() is called on the
42 * request when the resolution completes. HandleError() is called on the
43 * request if any errors occur.
44 *
45 * Either node or service may be empty but not both.
46 *
47 * @param loop Event loop
48 * @param req request
49 * @param node Either a numerical network address or a network hostname.
50 * @param service Either a service name or a port number as a string.
51 * @param hints Optional `addrinfo` data structure with additional address
52 * type constraints.
53 */
54void GetAddrInfo(Loop& loop, const std::shared_ptr<GetAddrInfoReq>& req,
55 std::string_view node, std::string_view service = {},
56 const addrinfo* hints = nullptr);
57
58/**
59 * Asynchronous getaddrinfo(3). HandleResolvedAddress() is called on the
60 * request when the resolution completes. HandleError() is called on the
61 * request if any errors occur.
62 *
63 * Either node or service may be empty but not both.
64 *
65 * @param loop Event loop
66 * @param req request
67 * @param node Either a numerical network address or a network hostname.
68 * @param service Either a service name or a port number as a string.
69 * @param hints Optional `addrinfo` data structure with additional address
70 * type constraints.
71 */
72inline void GetAddrInfo(const std::shared_ptr<Loop>& loop,
73 const std::shared_ptr<GetAddrInfoReq>& req,
74 std::string_view node, std::string_view service = {},
75 const addrinfo* hints = nullptr) {
76 GetAddrInfo(*loop, req, node, service, hints);
77}
78
79/**
80 * Asynchronous getaddrinfo(3). The callback is called when the resolution
81 * completes, and errors are forwarded to the loop. This is a convenience
82 * wrapper.
83 *
84 * Either node or service may be empty but not both.
85 *
86 * @param loop Event loop
87 * @param callback Callback function to call when resolution completes
88 * @param node Either a numerical network address or a network hostname.
89 * @param service Either a service name or a port number as a string.
90 * @param hints Optional `addrinfo` data structure with additional address
91 * type constraints.
92 */
93void GetAddrInfo(Loop& loop, std::function<void(const addrinfo&)> callback,
94 std::string_view node, std::string_view service = {},
95 const addrinfo* hints = nullptr);
96
97/**
98 * Asynchronous getaddrinfo(3). The callback is called when the resolution
99 * completes, and errors are forwarded to the loop. This is a convenience
100 * wrapper.
101 *
102 * Either node or service may be empty but not both.
103 *
104 * @param loop Event loop
105 * @param callback Callback function to call when resolution completes
106 * @param node Either a numerical network address or a network hostname.
107 * @param service Either a service name or a port number as a string.
108 * @param hints Optional `addrinfo` data structure with additional address
109 * type constraints.
110 */
111inline void GetAddrInfo(const std::shared_ptr<Loop>& loop,
112 std::function<void(const addrinfo&)> callback,
113 std::string_view node, std::string_view service = {},
114 const addrinfo* hints = nullptr) {
115 GetAddrInfo(*loop, std::move(callback), node, service, hints);
116}
117
118} // namespace wpi::uv
119
120#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:27
sig::Signal< const addrinfo & > resolved
Resolved lookup signal.
Definition: GetAddrInfo.h:37
Loop & GetLoop() const
Definition: GetAddrInfo.h:31
Event loop.
Definition: Loop.h:37
Request.
Definition: Request.h:135
uv_getaddrinfo_t * GetRaw() noexcept
Get the underlying request data structure.
Definition: Request.h:150
basic_string_view< char > string_view
Definition: core.h:501
Definition: WebSocket.h:27
void GetAddrInfo(Loop &loop, const std::shared_ptr< GetAddrInfoReq > &req, std::string_view node, std::string_view service={}, const addrinfo *hints=nullptr)
Asynchronous getaddrinfo(3).
UV_REQ_FIELDS uv_loop_t * loop
Definition: uv.h:940
void * data
Definition: uv.h:1861