Subordination
A framework for distributed programming
kernelbuf.hh
1 #ifndef SUBORDINATION_KERNEL_KERNELBUF_HH
2 #define SUBORDINATION_KERNEL_KERNELBUF_HH
3 
4 #include <type_traits>
5 
6 #include <unistdx/base/packetbuf>
7 #include <unistdx/net/byte_order>
8 
9 namespace sbn {
10 
11  template<class Base>
12  class basic_kernelbuf: public Base {
13 
14  public:
15  typedef Base base_type;
16  using typename base_type::traits_type;
17  using typename base_type::char_type;
18  typedef uint32_t portable_size_type;
19 
20  typedef sys::basic_packetbuf<char_type,traits_type> good_base_type;
21  static_assert(
23  "bad base class"
24  );
25 
26  private:
27  typedef sys::bytes<portable_size_type, char_type> bytes_type;
28 
29  public:
30  basic_kernelbuf() = default;
31  virtual ~basic_kernelbuf() = default;
32 
33  basic_kernelbuf(basic_kernelbuf&&) = delete;
34  basic_kernelbuf(const basic_kernelbuf&) = delete;
35  basic_kernelbuf& operator=(basic_kernelbuf&&) = delete;
36  basic_kernelbuf& operator=(const basic_kernelbuf&) = delete;
37 
38  private:
39 
40  bool
41  xgetheader(std::streamsize& hs, std::streamsize& payload_size) override {
42  bool success = false;
43  if (this->egptr() - this->gptr() >= this->header_size()) {
44  bytes_type size(this->gptr(), this->header_size());
45  size.to_host_format();
46  hs = this->header_size();
47  payload_size = size.value() - this->header_size();
48  success = true;
49  }
50  return success;
51  }
52 
53  void
54  put_header() override {
55  this->pbump(this->header_size());
56  }
57 
59  overwrite_header(std::streamsize s) override {
60  bytes_type hdr(s);
61  hdr.to_network_format();
62  traits_type::copy(this->opacket_begin(), hdr.begin(), hdr.size());
63  return this->header_size();
64  }
65 
66  static constexpr std::streamsize
67  header_size() {
68  return sizeof(portable_size_type);
69  }
70 
71  };
72 
73 }
74 
75 #endif // vim:filetype=cpp
Definition: kernelbuf.hh:12