xdrpp
RFC4506 XDR compiler and message library
exception.h
Go to the documentation of this file.
1 
2 // -*- C++ -*-
3 
4 /** \file exception.h Exceptions raised by RPC calls. These depend on
5  * the RPC message format. Other exceptions may be found in \c
6  * types.h.*/
7 
8 #ifndef _XDRPP_EXCEPTION_H_HEADER_INCLUDED_
9 #define _XDRPP_EXCEPTION_H_HEADER_INCLUDED_ 1
10 
11 #include <xdrpp/rpc_msg.hh>
12 #include <cerrno>
13 #include <cstring>
14 
15 namespace xdr {
16 
17 //! Translate one of the conditions in
18 //! [RFC5531](https://tools.ietf.org/html/rfc5531) for an unexecuted
19 //! call into a string.
20 const char *rpc_errmsg(accept_stat ev);
21 //! Translate one of the conditions in
22 //! [RFC5531](https://tools.ietf.org/html/rfc5531) for an unexecuted
23 //! call into a string.
24 const char *rpc_errmsg(auth_stat ev);
25 
26 //! Structure encoding all the various reasons a server can decline to
27 //! process an RPC call it received.
28 struct rpc_call_stat {
29  enum stat_type {
30  ACCEPT_STAT,
31  AUTH_STAT,
32  RPCVERS_MISMATCH,
33  GARBAGE_RES,
34  NETWORK_ERROR,
35  BAD_ALLOC,
36  };
37  stat_type type_;
38  union {
39  accept_stat accept_;
40  auth_stat auth_;
41  };
42  Constexpr rpc_call_stat() : type_(ACCEPT_STAT), accept_(SUCCESS) {}
43  Constexpr rpc_call_stat(accept_stat s) : type_(ACCEPT_STAT), accept_(s) {}
44  Constexpr rpc_call_stat(auth_stat s) : type_(AUTH_STAT), auth_(s) {}
45  Constexpr rpc_call_stat(stat_type type) : type_(type), accept_(SUCCESS) {}
46  rpc_call_stat(const rpc_msg &hdr);
47  const char *message() const;
48  explicit operator bool() const {
49  return type_ == ACCEPT_STAT && accept_ == SUCCESS;
50  }
51 };
52 
53 //! This is the exception raised in an RPC client when it reaches the
54 //! server and transmits a call, with no connection or communication
55 //! errors, but the server replies with an RPC-level message header
56 //! refusing to execute the call.
58  rpc_call_stat stat_;
59  xdr_call_error(rpc_call_stat s) : xdr_runtime_error(s.message()), stat_(s) {}
60 };
61 
62 //! Check that an RPC header precedes a result. \throws
63 //! xdr_call_error if the reply does not contain a response.
64 void check_call_hdr(const rpc_msg &hdr);
65 
66 //! This exception represents a system error encountered while
67 //! attempting to send RPC messages over a socket.
69  xdr_system_error(const char *what, int no = errno)
70  : xdr_runtime_error(std::string(what) + ": " + xdr_strerror(no)) {}
71 };
72 
73 }
74 
75 #endif // !_XDRPP_EXCEPTION_H_HEADER_INCLUDED_
Most of the xdrpp library is encapsulated in the xdr namespace.
Definition: arpc.cc:4
Generic class of XDR unmarshaling errors.
Definition: types.h:41
This exception represents a system error encountered while attempting to send RPC messages over a soc...
Definition: exception.h:68
const char * rpc_errmsg(accept_stat ev)
Translate one of the conditions in RFC5531 for an unexecuted call into a string.
Definition: rpc_msg.cc:10
Structure encoding all the various reasons a server can decline to process an RPC call it received...
Definition: exception.h:28
void check_call_hdr(const rpc_msg &hdr)
Check that an RPC header precedes a result.
Definition: rpc_msg.cc:115
This is the exception raised in an RPC client when it reaches the server and transmits a call...
Definition: exception.h:57