pars 0.2.1.99
Loading...
Searching...
No Matches
opt.h
Go to the documentation of this file.
1/*
2Copyright (c) 2025 Giuseppe Roberti.
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without modification,
6are permitted provided that the following conditions are met:
7
81. Redistributions of source code must retain the above copyright notice, this
9list of conditions and the following disclaimer.
10
112. Redistributions in binary form must reproduce the above copyright notice,
12this list of conditions and the following disclaimer in the documentation and/or
13other materials provided with the distribution.
14
153. Neither the name of the copyright holder nor the names of its contributors
16may be used to endorse or promote products derived from this software without
17specific prior written permission.
18
19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29*/
30#pragma once
31
32#include <nng/nng.h>
33#include <nng/protocol/reqrep0/req.h>
34
35namespace nngxx
36{
37
38enum class opt
39{
42 // proto, // deprecated
43 // protoname, // deprecated
44 // peer, // deprecated
45 // peername, // deprecated
65};
66
77
78template<opt o>
79[[nodiscard]] static constexpr const char* opt_to_nng_value() noexcept
80{
81 if constexpr (o == opt::sockname)
82 {
83 return NNG_OPT_SOCKNAME;
84 }
85 else if constexpr (o == opt::raw)
86 {
87 return NNG_OPT_RAW;
88 }
89 else if constexpr (o == opt::recvbuf)
90 {
91 return NNG_OPT_RECVBUF;
92 }
93 else if constexpr (o == opt::sendbuf)
94 {
95 return NNG_OPT_SENDBUF;
96 }
97 else if constexpr (o == opt::recvfd)
98 {
99 return NNG_OPT_RECVFD;
100 }
101 else if constexpr (o == opt::sendfd)
102 {
103 return NNG_OPT_SENDFD;
104 }
105 else if constexpr (o == opt::recvtimeo)
106 {
107 return NNG_OPT_RECVTIMEO;
108 }
109 else if constexpr (o == opt::sendtimeo)
110 {
111 return NNG_OPT_SENDTIMEO;
112 }
113 else if constexpr (o == opt::locaddr)
114 {
115 return NNG_OPT_LOCADDR;
116 }
117 else if constexpr (o == opt::remaddr)
118 {
119 return NNG_OPT_REMADDR;
120 }
121 else if constexpr (o == opt::url)
122 {
123 return NNG_OPT_URL;
124 }
125 else if constexpr (o == opt::maxttl)
126 {
127 return NNG_OPT_MAXTTL;
128 }
129 else if constexpr (o == opt::recvmaxsz)
130 {
131 return NNG_OPT_RECVMAXSZ;
132 }
133 else if constexpr (o == opt::reconnmint)
134 {
135 return NNG_OPT_RECONNMINT;
136 }
137 else if constexpr (o == opt::reconnmaxt)
138 {
139 return NNG_OPT_RECONNMAXT;
140 }
141 else if constexpr (o == opt::peergid)
142 {
143 return NNG_OPT_PEER_GID;
144 }
145 else if constexpr (o == opt::peerpid)
146 {
147 return NNG_OPT_PEER_UID;
148 }
149 else if constexpr (o == opt::peeruid)
150 {
151 return NNG_OPT_PEER_UID;
152 }
153 else if constexpr (o == opt::peerzoneid)
154 {
155 return NNG_OPT_PEER_ZONEID;
156 }
157 else if constexpr (o == opt::req_resend_time)
158 {
159 return NNG_OPT_REQ_RESENDTIME;
160 }
161 else if constexpr (o == opt::req_resend_tick)
162 {
163 return NNG_OPT_REQ_RESENDTICK;
164 }
165}
166
167template<opt o>
168[[nodiscard]] static constexpr opt_overload opt_to_nng_overload() noexcept
169{
170 if constexpr (o == opt::sockname)
171 {
173 }
174 else if constexpr (o == opt::raw)
175 {
177 }
178 else if constexpr (o == opt::recvbuf)
179 {
181 }
182 else if constexpr (o == opt::sendbuf)
183 {
185 }
186 else if constexpr (o == opt::recvfd)
187 {
189 }
190 else if constexpr (o == opt::sendfd)
191 {
193 }
194 else if constexpr (o == opt::recvtimeo)
195 {
197 }
198 else if constexpr (o == opt::sendtimeo)
199 {
201 }
202 else if constexpr (o == opt::locaddr)
203 {
205 }
206 else if constexpr (o == opt::remaddr)
207 {
209 }
210 else if constexpr (o == opt::url)
211 {
213 }
214 else if constexpr (o == opt::maxttl)
215 {
217 }
218 else if constexpr (o == opt::recvmaxsz)
219 {
220 return opt_overload::size;
221 }
222 else if constexpr (o == opt::reconnmint)
223 {
225 }
226 else if constexpr (o == opt::reconnmaxt)
227 {
229 }
230 else if constexpr (o == opt::peergid)
231 {
233 }
234 else if constexpr (o == opt::peerpid)
235 {
237 }
238 else if constexpr (o == opt::peeruid)
239 {
241 }
242 else if constexpr (o == opt::peerzoneid)
243 {
245 }
246 else if constexpr (o == opt::req_resend_time)
247 {
249 }
250 else if constexpr (o == opt::req_resend_tick)
251 {
253 }
254}
255
256template<opt o>
258
259template<opt o>
261
262template<>
264{
265 using return_type = const char*;
266};
267
268template<>
270{
271 using return_type = nng_duration;
272};
273
274template<>
276{
277 using return_type = nng_duration;
278};
279
280template<>
282{
283 using return_type = nng_duration;
284};
285
286template<>
288{
289 using return_type = nng_duration;
290};
291
292} // namespace nngxx
Definition aio.h:35
opt_overload
Definition opt.h:68
opt
Definition opt.h:39
@ maxttl
Definition opt.h:55
@ remaddr
Definition opt.h:53
@ sockname
Definition opt.h:40
@ req_resend_time
Definition opt.h:63
@ peerzoneid
Definition opt.h:62
@ sendtimeo
Definition opt.h:51
@ peerpid
Definition opt.h:60
@ peeruid
Definition opt.h:61
@ locaddr
Definition opt.h:52
@ reconnmint
Definition opt.h:57
@ url
Definition opt.h:54
@ recvbuf
Definition opt.h:46
@ recvtimeo
Definition opt.h:50
@ recvmaxsz
Definition opt.h:56
@ peergid
Definition opt.h:59
@ recvfd
Definition opt.h:48
@ raw
Definition opt.h:41
@ reconnmaxt
Definition opt.h:58
@ sendbuf
Definition opt.h:47
@ sendfd
Definition opt.h:49
@ req_resend_tick
Definition opt.h:64
opt_to_nng_type< o >::return_type opt_to_nng_type_t
Definition opt.h:260