6 #ifndef _XDRPP_MSGSOCK_H_INCLUDED_ 7 #define _XDRPP_MSGSOCK_H_INCLUDED_ 1 29 static constexpr std::size_t default_maxmsglen = 0x100000;
30 using rcb_t = std::function<void(msg_ptr)>;
33 size_t maxmsglen = default_maxmsglen)
34 : ps_(ps), s_(s), maxmsglen_(maxmsglen), rcb_(std::forward<T>(rcb)) {
41 template<
typename T>
void setrcb(T &&rcb) {
42 rcb_ = std::forward<T>(rcb);
46 size_t wsize()
const {
return wsize_; }
47 void putmsg(msg_ptr &b);
48 void putmsg(msg_ptr &&b) { putmsg(b); }
51 std::shared_ptr<const bool>
destroyed_ptr()
const {
return destroyed_; }
52 pollset &get_pollset() {
return ps_; }
60 const size_t maxmsglen_;
61 std::shared_ptr<bool> destroyed_{std::make_shared<bool>(
false)};
68 std::deque<msg_ptr> wqueue_;
73 static constexpr
bool eagain(
int err) {
74 return err == EAGAIN || err == EWOULDBLOCK || err == EINTR;
76 char *nextlenp() {
return reinterpret_cast<char *
>(&nextlen_); }
77 uint32_t nextlen()
const {
return swap32le(nextlen_); }
82 void pop_wbytes(
size_t n);
83 void output(
bool cbset);
94 std::unordered_map<uint32_t, msg_sock::rcb_t> calls_;
96 void abort_all_calls();
97 void recv_msg(msg_ptr b);
98 void recv_call(msg_ptr);
100 std::unique_ptr<msg_sock> ms_;
101 using rcb_t = msg_sock::rcb_t;
106 size_t maxmsglen = msg_sock::default_maxmsglen)
108 std::bind(&rpc_sock::recv_msg,
this,
109 std::placeholders::_1),
111 servcb_(std::forward<T>(t)) {}
114 template<
typename T>
void set_servcb(T &&scb) {
115 servcb_ = std::forward<T>(scb);
119 while (calls_.find(++xid_) != calls_.end() && xid_ != 0)
124 void send_call(msg_ptr &b, rcb_t cb);
125 void send_call(msg_ptr &&b, rcb_t cb) { send_call(b, cb); }
126 void send_reply(msg_ptr &&b) { ms_->putmsg(std::move(b)); }
136 void operator()(msg_ptr b)
const { ms_->send_reply(std::move(b)); }
141 #endif // !_XDRPP_MSGSOCK_H_INCLUDED_ Most of the xdrpp library is encapsulated in the xdr namespace.
Constexpr std::uint32_t swap32le(std::uint32_t v)
Byteswap 32-bit value only on little-endian machines, identity function on big-endian machines...
Asynchronous I/O and event harness.
Structure to poll for a set of file descriptors and timeouts.
Message buffer with space for marshaled length.
A wrapper around xdr::msg_sock that separates calls from replies.
Send and receive a series of delimited messages on a stream socket.
Abstract away the type of a socket (for windows).
Functor wrapper around rpc_sock::send_reply.
std::shared_ptr< const bool > destroyed_ptr() const
Returns pointer to a bool that becomes true once the msg_sock has been deleted.
sock_t get_sock() const
Returns the socket, but do not do IO on it.