pars 0.2.1
Loading...
Searching...
No Matches
aio.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/err.h"
33#include "nngxx/iface/value.h"
34#include "nngxx/msg.h"
35
36#include <nng/nng.h>
37
38template<>
39struct clev::iface<nng_aio*> : nngxx::value<nng_aio*>
40{
41 using value::value;
42
43 inline static nng_aio* empty() noexcept { return nullptr; }
44
45 [[nodiscard]] inline static clev::expected<void> destroy(nng_aio* v) noexcept
46 {
47 return nngxx::invoke(nng_aio_free, v);
48 }
49
50 [[nodiscard]] inline static clev::expected<nng_aio*> alloc(void (*cb)(void*),
51 void* arg) noexcept
52 {
53 return nngxx::make(nng_aio_alloc, cb, arg);
54 }
55
56 inline void wait() const noexcept { nng_aio_wait(v); }
57
58 inline void abort(nngxx::err err) noexcept
59 {
60 nng_aio_abort(v, static_cast<int>(err));
61 }
62
63 inline void cancel() noexcept { nng_aio_cancel(v); }
64
65 inline void stop() noexcept { nng_aio_stop(v); }
66
67 [[nodiscard]] inline nngxx::msg release_msg() noexcept
68 {
69 auto m = nng_aio_get_msg(v);
70
71 nng_aio_set_msg(v, nullptr);
72
73 return m;
74 }
75
76 [[nodiscard]] inline clev::expected<void> result() const noexcept
77 {
78 return nngxx::invoke(nng_aio_result, v);
79 }
80
81 inline void set_msg(nngxx::msg m) noexcept
82 {
83 nng_aio_set_msg(v, m.release());
84 }
85};
clev::own< nng_msg * > msg
Definition msg.h:39
clev::expected< std::remove_pointer_t< arg_t > > make(ret_t(*f)(arg_t, args_t...), args_t... args) noexcept
Definition err.h:114
err
Definition err.h:74
clev::expected< void > invoke(ret_t(*f)(args_t...), args_t... args) noexcept
Definition err.h:123
value() noexcept
Definition value.h:47