Chops Net IP
Loading...
Searching...
No Matches
var_len_hdr.hpp
Go to the documentation of this file.
1
16#ifndef VAR_LEN_HDR_HPP_INCLUDED
17#define VAR_LEN_HDR_HPP_INCLUDED
18
19#include <cstddef> // std::size_t, std::byte
20#include <cstdint> // std::int32_t
21
22#include <cassert>
23#include <limits>
24
25namespace chops {
26namespace example {
27
28inline std::size_t decode_variable_len_msg_hdr(const std::byte* buf_ptr, std::size_t sz) {
29 // code to be filled in
30}
31
32template <typename IOT>
33struct msg_hdlr {
34 using endp_type = typename IOT::endpoint_type;
35 using const_buf = asio::const_buffer;
36
37 bool reply;
38 test_counter& cnt;
39
40 msg_hdlr(bool rep, test_counter& c) : reply(rep), cnt(c) { }
41
42 bool operator()(const_buf buf, chops::net::basic_io_interface<IOT> io_intf, endp_type endp) {
43 chops::const_shared_buffer sh_buf(buf.data(), buf.size());
44 if (sh_buf.size() > 2) { // not a shutdown message
45 ++cnt;
46 if (reply) {
47 io_intf.send(sh_buf, endp);
48 }
49 return true;
50 }
51 if (reply) {
52 // may not make it back to sender, depending on TCP connection or UDP reliability
53 io_intf.send(sh_buf, endp);
54 }
55 return false;
56 }
57
58};
59
62
63constexpr int udp_max_buf_size = 65507;
64
65asio::net::ip::udp::endpoint make_udp_endpoint(const char* addr, int port_num) {
66 return asio::net::ip::udp::endpoint(asio::net::ip::make_address(addr),
67 static_cast<unsigned short>(port_num));
68}
69
70
71} // end namespace example
72} // end namespace chops
73
74#endif
75
The basic_io_interface class template provides access to an underlying network IO handler (TCP or UDP...
Definition basic_io_interface.hpp:100
Definition var_len_hdr.hpp:33