3 #ifndef _XDRPP_SRPC_H_HEADER_INCLUDED_ 4 #define _XDRPP_SRPC_H_HEADER_INCLUDED_ 1 13 extern bool xdr_trace_client;
15 msg_ptr read_message(sock_t s);
16 void write_message(sock_t s,
const msg_ptr &m);
18 void prepare_call(uint32_t prog, uint32_t vers, uint32_t proc, rpc_msg &hdr);
19 template<
typename P>
inline void 20 prepare_call(rpc_msg &hdr)
22 prepare_call(P::interface_type::program, P::interface_type::version,
32 template<
typename T>
static T &&moveret(T &t) {
return std::move(t); }
35 template<
typename T>
const T &arg_tuple(
const T &t) {
return t; }
36 template<
typename...T> std::tuple<
const T &...> arg_tuple(
const T &...t) {
37 return std::make_tuple(std::cref(t)...);
44 template<
typename P,
typename...A>
typename std::conditional<
45 std::is_void<typename P::res_type>::value, void,
46 std::unique_ptr<typename P::res_type>>::type
47 invoke(
const A &...a) {
50 uint32_t xid = hdr.xid;
52 if (xdr_trace_client) {
53 std::string s =
"CALL ";
55 s +=
" -> [xid " + std::to_string(xid) +
"]";
59 msg_ptr m = read_message(s_);
68 archive(g, r.activate());
70 if (xdr_trace_client) {
71 std::string s =
"REPLY ";
73 s +=
" <- [xid " + std::to_string(xid) +
"]";
95 typename T::template _xdr_client<synchronous_client_base>;
98 template<
typename T,
typename Session,
typename Interface>
100 template<
typename P,
typename A>
typename 101 std::enable_if<std::is_same<void, typename P::res_type>::value,
103 dispatch1(Session *s, A &a) {
105 dispatch_with_session<P>(server_, s, std::move(a));
108 template<
typename P,
typename A>
typename 109 std::enable_if<!std::is_same<void, typename P::res_type>::value,
110 std::unique_ptr<typename P::res_type>>::type
111 dispatch1(Session *s, A &a) {
112 return dispatch_with_session<P>(server_, s, std::move(a));
119 :
service_base(Interface::program, Interface::version), server_(server) {}
121 void process(
void *session,
rpc_msg &hdr,
xdr_get &g, cb_t reply)
override {
122 if (!check_call(hdr))
124 if (!Interface::call_dispatch(*
this, hdr.body.cbody().proc,
125 static_cast<Session *
>(session),
126 hdr, g, std::move(reply)))
127 reply(rpc_accepted_error_msg(hdr.xid, PROC_UNAVAIL));
131 void dispatch(Session *session,
rpc_msg &hdr,
xdr_get &g, cb_t reply) {
133 if (!decode_arg(g, arg))
134 return reply(rpc_accepted_error_msg(hdr.xid, GARBAGE_ARGS));
136 if (xdr_trace_server) {
137 std::string s =
"CALL ";
139 s +=
" <- [xid " + std::to_string(hdr.xid) +
"]";
143 auto res = this->
template dispatch1<P>(session, arg);
145 if (xdr_trace_server) {
146 std::string s =
"REPLY ";
148 s +=
" -> [xid " + std::to_string(hdr.xid) +
"]";
161 bool close_on_destruction_;
165 : s_(s), close_on_destruction_(close_on_destruction) {}
166 ~
srpc_server() {
if (close_on_destruction_) close(s_); }
169 template<
typename T,
typename Interface =
typename T::rpc_
interface_type>
178 template<
typename Session = void,
185 #endif // !_XDRPP_SRPC_H_HEADER_INCLUDED_ Structure that gets marshalled as an RPC success header.
std::tuple<> xdr_void
Placehoder type representing void values marshaled as 0 bytes.
void register_service(T &t)
Add objects implementing RPC program interfaces to the server.
Most of the xdrpp library is encapsulated in the xdr namespace.
Archive type for unmarshaling from a buffer.
msg_ptr xdr_to_msg(const Args &...args)
Marshal one or a series of XDR types into a newly allocated buffer referenced xdr::msg_ptr.
Attach RPC services to a single, connected stream socket.
Exceptions raised by RPC calls.
Generic class of XDR unmarshaling errors.
Optional data (represented with pointer notation in XDR source).
Classes for implementing RPC servers.
Trivial session allocator that just calls new and delete.
Synchronous file descriptor demultiplexer.
Abstract away the type of a socket (for windows).
void check_call_hdr(const rpc_msg &hdr)
Check that an RPC header precedes a result.
typename detail::wrap_transparent_ptr_helper< T >::type wrap_transparent_ptr
Wrap xdr::transparent_ptr around each type in a tuple to generate a new tuple type.
std::string xdr_to_string(const T &t, const char *name=nullptr, int indent=0)
Return a std::string containing a pretty-printed version an XDR data type.
typename T::template _xdr_client< synchronous_client_base > srpc_client
Create an RPC client from an interface type and connected stream socket.