pars 0.2.1.99
Loading...
Searching...
No Matches
client.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 "pars/ev/enqueuer.h"
33#include "pars/net/req.h"
34#include "pars/net/socket_opt.h"
35
36namespace pars::comp
37{
38
39class client
40{
41public:
43 : req_m{h, r}
44 {
45 }
46
47 net::req& req() { return req_m; }
48
53
54 void init(const init_p& params) { req_m.sock().set_options(params.req_opts); }
55
61
62 void connect(const connect_p& params)
63 {
64 req_m.sock().connect(params.service_addr, params.service_cmode);
65 }
66
67 void graceful_terminate() { req_m.stop(); }
68
69private:
70 net::req req_m;
71};
72
73} // namespace pars::comp
void init(const init_p &params)
Definition client.h:54
void connect(const connect_p &params)
Definition client.h:62
void graceful_terminate()
Definition client.h:67
client(ev::hf_registry &h, ev::enqueuer &r)
Definition client.h:42
net::req & req()
Definition client.h:47
Represents an nng_req protocol.
Definition req.h:45
char * service_addr
connect addr for req
Definition client.h:59
net::cmode service_cmode
connect mode for req
Definition client.h:58
net::socket_opt req_opts
Definition client.h:51
Represents the options that can be configured for a given socket.
Definition socket_opt.h:48