Chops Net IP
Loading...
Searching...
No Matches
error_delivery.hpp
Go to the documentation of this file.
1
16#ifndef ERROR_DELIVERY_HPP_INCLUDED
17#define ERROR_DELIVERY_HPP_INCLUDED
18
19#include <cstddef> // std::size_t
20#include <utility> // std::move
21
22#include <system_error>
23#include <ostream>
24#include <string>
25#include <chrono>
26
29
30#include "queue/wait_queue.hpp"
31
32
33namespace chops {
34namespace net {
35
48struct error_data {
49 std::chrono::steady_clock::time_point time_p;
50 const void* io_intf_ptr;
51 std::error_code err;
52
53 error_data(const void* iop, std::error_code e) :
54 time_p(std::chrono::steady_clock::now()), io_intf_ptr(iop), err(std::move(e)) { }
55};
56
60using err_wait_q = chops::wait_queue<error_data>;
61
65template <typename IOT>
67 return [&wq] (basic_io_interface<IOT> io, std::error_code e) {
68 wq.emplace_push(io.get_ptr(), e);
69 };
70}
71
88inline std::size_t ostream_error_sink_with_wait_queue (err_wait_q& wq, std::ostream& os) {
89 std::size_t cnt = 0;
90 while (true) {
91 auto elem = wq.wait_and_pop();
92 if (!elem) {
93 break;
94 }
95
96 auto t =
97 std::chrono::duration_cast<std::chrono::milliseconds>((*elem).time_p.time_since_epoch()).count();
98
99 os << '[' << t << "] io_addr: " << elem->io_intf_ptr << " err: " <<
100 elem->err << ", " << (*elem).err.message() << '\n';
101 ++cnt;
102 }
103 os.flush();
104 return cnt;
105}
106
107} // end net namespace
108} // end chops namespace
109
110#endif
111
basic_io_interface class template, providing start_io, stop_io, visit_socket, make_io_output and rela...
The basic_io_interface class template provides access to an underlying network IO handler (TCP or UDP...
Definition basic_io_interface.hpp:100
const void * get_ptr() const noexcept
Return a raw pointer to an associated IO handler.
Definition basic_io_interface.hpp:581
std::size_t ostream_error_sink_with_wait_queue(err_wait_q &wq, std::ostream &os)
A sink function that uses a wait_queue for error data and streams the data into an std::ostream.
Definition error_delivery.hpp:88
auto make_error_func_with_wait_queue(err_wait_q &wq)
Create an error function object that uses a wait_queue for error data.
Definition error_delivery.hpp:66
chops::wait_queue< error_data > err_wait_q
wait_queue declaration that provides error data.
Definition error_delivery.hpp:60
Error codes, exception class, and error category within Chops net_ip library.
Data provided through an error function callback.
Definition error_delivery.hpp:48