| Coverage Report |
 |
|
|
 |
: /*
: Copyright (c) 2025 Giuseppe Roberti.
: All rights reserved.
:
: Redistribution and use in source and binary forms, with or without modification,
: are permitted provided that the following conditions are met:
:
: 1. Redistributions of source code must retain the above copyright notice, this
: list of conditions and the following disclaimer.
:
: 2. Redistributions in binary form must reproduce the above copyright notice,
: this list of conditions and the following disclaimer in the documentation and/or
: other materials provided with the distribution.
:
: 3. Neither the name of the copyright holder nor the names of its contributors
: may be used to endorse or promote products derived from this software without
: specific prior written permission.
:
: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
: ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
: DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
: ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
: LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
: ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
: SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
: */
: #pragma once
:
: #include "nngxx/aio.h"
: #include "nngxx/ctx.h"
:
: #include "pars/ev/enqueuer.h"
: #include "pars/net/context_opt.h"
: #include "pars/net/op.h"
: #include "pars/net/socket.h"
:
: #include <format>
:
: namespace pars::net
: {
:
: class context
: {
: public:
: context(ev::enqueuer& r, nngxx::ctx&& c, const net::socket& s)
: : router_m{r}
: , ctx_m{std::move(c)}
: , sock_m{s}
: {
: }
:
0 / 1 : ~context() { stop(); }
:
0 / 1 : operator tool_view() { return tool_view{ctx_m}; }
:
: void set_options(context_opt opts)
: {
0 / 1 : if (opts.recv_timeout)
0 / 1 : ctx_m.set_recv_timeout(*opts.recv_timeout).or_abort();
:
0 / 1 : if (opts.send_timeout)
0 / 1 : ctx_m.set_send_timeout(*opts.send_timeout).or_abort();
: }
:
: context_opt options() const
: {
0 / 1 : return {.recv_timeout = ctx_m.get_recv_timeout().value_or_abort(),
0 / 1 : .send_timeout = ctx_m.get_send_timeout().value_or_abort()};
: }
:
0 / 1 : void send_aio(nngxx::aio_view& a) { ctx_m.send(a); }
:
0 / 1 : void recv_aio(nngxx::aio_view& a) { ctx_m.recv(a); }
:
: template<ev::event_c event_t>
: void send(event_t ev, pipe p)
: {
: op_m.send(router_m, *this, p, ev);
: }
:
0 / 1 : void recv() { op_m.recv(router_m, *this); }
:
0 / 1 : void stop() { op_m.stop(); }
:
0 / 1 : int id() const { return ctx_m.id(); }
:
0 / 1 : int socket_id() const { return sock_m.id(); }
:
0 / 1 : const net::socket& sock() const { return sock_m; }
:
: auto format_to(std::format_context& ctx) const -> decltype(ctx.out())
: {
0 / 1 : return std::format_to(ctx.out(), "context #{}", id());
: }
:
: private:
: ev::enqueuer& router_m;
: op op_m;
: nngxx::ctx ctx_m;
: const net::socket& sock_m;
: };
:
: } // namespace pars::net
 |
| Generated by: llvmcov2html |