pars 0.2.1
Loading...
Searching...
No Matches
pars::net::socket Class Reference

Represents an nng_socket. More...

#include <socket.h>

Public Member Functions

 socket (ev::enqueuer &r, nngxx::socket &&s)
 Construct a socket.
 
 ~socket ()
 
 operator tool_view ()
 
void set_options (const socket_opt opts)
 
socket_opt options () const
 
void dial (const char *addr)
 
void listen (const char *addr)
 
void connect (const char *addr, const cmode mode)
 
nngxx::ctx make_ctx ()
 
void send_aio (nngxx::aio_view &a)
 
void recv_aio (nngxx::aio_view &a)
 
template<ev::event_c event_t>
void send (event_t ev, pipe p={})
 
void recv ()
 
void stop ()
 
int id () const
 
int socket_id () const
 
const char * proto_name () const
 
auto format_to (std::format_context &ctx) const -> decltype(ctx.out())
 

Detailed Description

Represents an nng_socket.

Definition at line 70 of file socket.h.

Constructor & Destructor Documentation

◆ socket()

pars::net::socket::socket ( ev::enqueuer & r,
nngxx::socket && s )
inline

Construct a socket.

Definition at line 74 of file socket.h.

75 : router_m{r}
76 , socket_m{std::move(s)}
77 {
78 register_pipe_notify();
79 }

◆ ~socket()

pars::net::socket::~socket ( )
inline

Definition at line 81 of file socket.h.

81{ stop(); }

References stop().

Here is the call graph for this function:

Member Function Documentation

◆ connect()

void pars::net::socket::connect ( const char * addr,
const cmode mode )
inline

Definition at line 114 of file socket.h.

115 {
116 switch (mode)
117 {
118 case cmode::dial:
119 dial(addr);
120
121 break;
122 case cmode::listen:
123 listen(addr);
124
125 break;
126 }
127 }

References pars::net::dial, and pars::net::listen.

◆ dial()

void pars::net::socket::dial ( const char * addr)
inline

Definition at line 110 of file socket.h.

110{ emplace_dialer(addr).start().or_abort(); }

◆ format_to()

auto pars::net::socket::format_to ( std::format_context & ctx) const -> decltype(ctx.out())
inline

Definition at line 154 of file socket.h.

155 {
156 return std::format_to(ctx.out(), "Socket #{}-{}", id(), proto_name());
157 }
const char * proto_name() const
Definition socket.h:149
clev::own< nng_ctx > ctx
Definition ctx.h:39

References proto_name().

Here is the call graph for this function:

◆ id()

int pars::net::socket::id ( ) const
inline

Definition at line 145 of file socket.h.

145{ return socket_m.id(); }

Referenced by socket_id().

Here is the caller graph for this function:

◆ listen()

void pars::net::socket::listen ( const char * addr)
inline

Definition at line 112 of file socket.h.

112{ emplace_listener(addr).start().or_abort(); }

◆ make_ctx()

nngxx::ctx pars::net::socket::make_ctx ( )
inline

Definition at line 129 of file socket.h.

129{ return nngxx::make_ctx(socket_m).value_or_abort(); }

◆ operator tool_view()

pars::net::socket::operator tool_view ( )
inline

Definition at line 83 of file socket.h.

83{ return tool_view{socket_m}; }

◆ options()

socket_opt pars::net::socket::options ( ) const
inline

Definition at line 100 of file socket.h.

101 {
102 return {
103 .recv_timeout = socket_m.get_recv_timeout().value_or_abort(),
104 .send_timeout = socket_m.get_send_timeout().value_or_abort(),
105 .req_resend_time = socket_m.get_req_resend_time().value_or_abort(),
106 .req_resend_tick = socket_m.get_req_resend_tick().value_or_abort(),
107 };
108 }

◆ proto_name()

const char * pars::net::socket::proto_name ( ) const
inline

Definition at line 149 of file socket.h.

150 {
151 return socket_m.proto_name().value_or("<not-found>");
152 }

Referenced by format_to().

Here is the caller graph for this function:

◆ recv()

void pars::net::socket::recv ( )
inline

Definition at line 141 of file socket.h.

141{ op_m.recv(router_m, *this); }

◆ recv_aio()

void pars::net::socket::recv_aio ( nngxx::aio_view & a)
inline

Definition at line 133 of file socket.h.

133{ socket_m.recv(a); }

◆ send()

template<ev::event_c event_t>
void pars::net::socket::send ( event_t ev,
pipe p = {} )
inline

Definition at line 136 of file socket.h.

136 {})
137 {
138 op_m.send(router_m, *this, p, ev);
139 }

◆ send_aio()

void pars::net::socket::send_aio ( nngxx::aio_view & a)
inline

Definition at line 131 of file socket.h.

131{ socket_m.send(a); }

◆ set_options()

void pars::net::socket::set_options ( const socket_opt opts)
inline

Definition at line 85 of file socket.h.

86 {
87 if (opts.recv_timeout)
88 socket_m.set_recv_timeout(*opts.recv_timeout).or_abort();
89
90 if (opts.send_timeout)
91 socket_m.set_send_timeout(*opts.send_timeout).or_abort();
92
93 if (opts.req_resend_time)
94 socket_m.set_req_resend_time(*opts.req_resend_time).or_abort();
95
96 if (opts.req_resend_tick)
97 socket_m.set_req_resend_tick(*opts.req_resend_tick).or_abort();
98 }

References pars::net::socket_opt::recv_timeout, pars::net::socket_opt::req_resend_tick, pars::net::socket_opt::req_resend_time, and pars::net::socket_opt::send_timeout.

◆ socket_id()

int pars::net::socket::socket_id ( ) const
inline

Definition at line 147 of file socket.h.

147{ return id(); }
int id() const
Definition socket.h:145

References id().

Here is the call graph for this function:

◆ stop()

void pars::net::socket::stop ( )
inline

Definition at line 143 of file socket.h.

143{ op_m.stop(); }

Referenced by ~socket().

Here is the caller graph for this function:

The documentation for this class was generated from the following file: