pars 0.2.1
Loading...
Searching...
No Matches
socket.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/err.h"
34#include "nngxx/iface/value.h"
35#include "nngxx/pipe.h"
36#include "nngxx/socket_decl.h"
37
38template<>
39struct clev::iface<nng_socket> : nngxx::value<nng_socket>
40{
41 using value::value;
42
43 [[nodiscard]] inline static nng_socket empty() noexcept
44 {
45 return NNG_SOCKET_INITIALIZER;
46 };
47
48 [[nodiscard]] inline static clev::expected<void>
49 destroy(nng_socket v) noexcept
50 {
51 return nngxx::invoke(nng_socket_close, v);
52 }
53
54 [[nodiscard]] inline int id() const noexcept { return nng_socket_id(v); }
55
56 inline void send(nngxx::aio_view& a) noexcept { nng_send_aio(v, a); }
57
58 inline void recv(nngxx::aio_view& a) noexcept { nng_recv_aio(v, a); }
59
60 [[nodiscard]] inline clev::expected<void>
61 pipe_notify(nngxx::pipe_ev ev, nng_pipe_cb cb, void* arg) noexcept
62 {
63 return nngxx::invoke(nng_pipe_notify, v, cast_pipe_ev(ev), cb, arg);
64 }
65
66 [[nodiscard]] inline clev::expected<const char*> proto_name() const noexcept
67 {
68 const char* proto_name;
69
70 return nngxx::invoke(nng_socket_proto_name, v, &proto_name)
71 .transform_to(std::move(proto_name));
72 }
73};
expected(value_t &&) -> expected< value_t >
pipe_ev
Definition pipe.h:40
nng_pipe_ev cast_pipe_ev(pipe_ev ev) noexcept
Definition pipe.h:47
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
auto transform_to(to_value_t &&v) &&noexcept
Definition err.h:119
value() noexcept
Definition value.h:47