pars
0.2.1.99
Loading...
Searching...
No Matches
lib
include
pars
comp
backend.h
Go to the documentation of this file.
1
/*
2
Copyright (c) 2025 Giuseppe Roberti.
3
All rights reserved.
4
5
Redistribution and use in source and binary forms, with or without modification,
6
are permitted provided that the following conditions are met:
7
8
1. Redistributions of source code must retain the above copyright notice, this
9
list of conditions and the following disclaimer.
10
11
2. Redistributions in binary form must reproduce the above copyright notice,
12
this list of conditions and the following disclaimer in the documentation and/or
13
other materials provided with the distribution.
14
15
3. Neither the name of the copyright holder nor the names of its contributors
16
may be used to endorse or promote products derived from this software without
17
specific prior written permission.
18
19
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26
ANY 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
28
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
*/
30
#pragma once
31
32
#include "
pars/ev/enqueuer.h
"
33
#include "
pars/net/rep.h
"
34
#include "
pars/net/socket_opt.h
"
35
36
#include <format>
37
38
namespace
pars::comp
39
{
40
41
class
backend
42
{
43
public
:
44
backend
(
ev::hf_registry
& h,
ev::enqueuer
& r)
45
: rep_m{h, r}
46
{
47
}
48
49
struct
init_p
50
{
51
int
num_ctxs
= 1;
52
net::socket_opt
rep_opts
;
53
};
54
55
void
init
(
const
init_p
& params)
56
{
57
rep_m.sock().set_options(params.
rep_opts
);
58
59
rep_m.ctxs().start_recv(params.
num_ctxs
);
60
}
61
62
struct
connect_p
63
{
64
net::cmode
service_cmode
=
net::cmode::listen
;
65
char
*
service_addr
=
nullptr
;
66
};
67
68
void
connect
(
const
connect_p
& params)
69
{
70
rep_m.sock().connect(params.
service_addr
, params.
service_cmode
);
71
}
72
73
net::rep
&
rep
() {
return
rep_m; }
74
75
void
graceful_terminate
() { rep_m.stop(); }
76
77
auto
format_to
(std::format_context& ctx)
const
->
decltype
(ctx.out())
78
{
79
return
std::format_to(ctx.out(),
"[rep:{}]"
, rep_m.sock());
80
}
81
82
private
:
83
net::rep
rep_m;
84
};
85
86
}
// namespace pars::comp
pars::comp::backend::graceful_terminate
void graceful_terminate()
Definition
backend.h:75
pars::comp::backend::init
void init(const init_p ¶ms)
Definition
backend.h:55
pars::comp::backend::connect
void connect(const connect_p ¶ms)
Definition
backend.h:68
pars::comp::backend::backend
backend(ev::hf_registry &h, ev::enqueuer &r)
Definition
backend.h:44
pars::comp::backend::rep
net::rep & rep()
Definition
backend.h:73
pars::comp::backend::format_to
auto format_to(std::format_context &ctx) const -> decltype(ctx.out())
Definition
backend.h:77
pars::ev::enqueuer
Definition
enqueuer.h:43
pars::net::rep
Represents an nng_rep protocol.
Definition
rep.h:45
enqueuer.h
pars::comp
Definition
backend.h:39
pars::net::cmode
cmode
Definition
socket.h:50
pars::net::cmode::listen
@ listen
Definition
socket.h:52
rep.h
socket_opt.h
pars::comp::backend::connect_p
Definition
backend.h:63
pars::comp::backend::connect_p::service_cmode
net::cmode service_cmode
connect mode for rep
Definition
backend.h:64
pars::comp::backend::connect_p::service_addr
char * service_addr
connect addr for rep
Definition
backend.h:65
pars::comp::backend::init_p
Definition
backend.h:50
pars::comp::backend::init_p::num_ctxs
int num_ctxs
Definition
backend.h:51
pars::comp::backend::init_p::rep_opts
net::socket_opt rep_opts
Definition
backend.h:52
pars::ev::hf_registry
Definition
hf_registry.h:64
pars::net::socket_opt
Represents the options that can be configured for a given socket.
Definition
socket_opt.h:48
Generated by
1.13.2