pars 0.2.1
Loading...
Searching...
No Matches
ctx.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 "nngxx/aio.h"
33#include "nngxx/iface/value.h"
34#include "nngxx/socket.h"
35
36#include <nng/nng.h>
37
38template<>
39struct clev::iface<nng_ctx> : nngxx::value<nng_ctx>
40{
41 using value::value;
42
43 [[nodiscard]] inline static nng_ctx empty() noexcept
44 {
45 return NNG_CTX_INITIALIZER;
46 };
47
48 [[nodiscard]] inline static clev::expected<void> destroy(nng_ctx v) noexcept
49 {
50 return nngxx::invoke(nng_ctx_close, v);
51 }
52
53 [[nodiscard]] inline int id() const noexcept { return nng_ctx_id(v); }
54
55 inline void send(nngxx::aio_view& a) noexcept { nng_ctx_send(v, a); }
56
57 inline void recv(nngxx::aio_view& a) noexcept { nng_ctx_recv(v, a); }
58
59 [[nodiscard]] inline clev::expected<void> open(nngxx::socket_view& s) noexcept
60 {
61 return nngxx::invoke(nng_ctx_open, &v, static_cast<nng_socket>(s));
62 }
63};
64
clev::iface< nng_socket > socket_view
Definition socket_decl.h:43
clev::iface< nng_aio * > aio_view
Definition aio.h:37
clev::expected< void > invoke(ret_t(*f)(args_t...), args_t... args) noexcept
Definition err.h:123
constexpr bool nngxx_socket_is_really_needed_v
Definition socket.h:90
value() noexcept
Definition value.h:47