randolf.ca  1.00
Randolf Richardson's C++ classes
Loading...
Searching...
No Matches
rsocket_io
1#pragma once
2
3#include <mutex> // std::mutex
4
5namespace randolf {
6
7 /*======================================================================*//**
8 @brief
9 Structure of socket I/O statistics tracked by rsocket.
10 The reason this is a subclass of @c std::mutex is to ensure a thread-safe
11 operation for the @c rsocket::~rsocket destructor when making a final copy of
12 the internally-tracked I/O statistics using the pointer to this structure (if
13 specified with the @ref rsocket::net_io_final() method).
14
15 @note
16 To find out the total overall bytes received/transmitted, the sum of @ref
17 bytes_rx and @ref crypt_rx , and the sum of @ref bytes_tx and @ref crypt_tx
18 will provide this statistical information:
19 @code{.cpp}
20 #include <randolf/rsocket>
21
22 std::shared_ptr<randolf::rsocket_io> io = r.net_io();
23 __uint128_t total_rx = io->bytes_rx // Bytes received (unencrypted)
24 + io->crypt_rx; // Bytes received (encrypted)
25 __uint128_t total_tx = io->bytes_tx // Bytes transmitted (unencrypted)
26 + io->crypt_tx; // Bytes transmitted (encrypted)
27 @endcode
28 When data is buffered (buffering is triggered by the @ref rsocket::recvline()
29 method), there may be occasions where data is spared (left behind), which is
30 tracked in the @ref bytes_sx and @ref crypt_sx values. These values can be
31 subtracted from the totals, if need be, as follows:
32 @code{.cpp}
33 #include <randolf/rsocket>
34
35 std::shared_ptr<randolf::rsocket_io> io = r.net_io();
36 __uint128_t total_rx = io->bytes_rx // Bytes received (unencrypted)
37 - io->bytes_sx // Bytes received (unencrypted spare)
38 + io->crypt_rx // Bytes received (encrypted)
39 - io->bytes_sx; // Bytes received (encrypted spare)
40 __uint128_t total_tx = io->bytes_tx // Bytes transmitted (unencrypted)
41 + io->crypt_tx; // Bytes transmitted (encrypted)
42 @endcode
43 Spare bytes are only applicable to received data statistics because buffering
44 is only used to receive data.
45
46 This statistical data is typically used in logging, and also in applications
47 that keep track of I/O on a per-user basis.
48 @see rsocket::net_io()
49 @see rsocket::net_io(const char*, size_t, rsocket_io*)
50 @see rsocket::net_io_final()
51 @see rsocket::net_io_update()
52 *///=========================================================================
53 struct rsocket_io : public std::mutex {
54
55 /*======================================================================*//**
56 @brief
57 Total number of unencrypted bytes received.
58 *///=========================================================================
59 __uint128_t bytes_rx;
60
61 /*======================================================================*//**
62 @brief
63 Total number of unencrypted bytes spared (received, and remains in buffer).
64 *///=========================================================================
65 __uint128_t bytes_sx;
66
67 /*======================================================================*//**
68 @brief
69 Total number of unencrypted bytes transmitted.
70 *///=========================================================================
71 __uint128_t bytes_tx;
72
73 /*======================================================================*//**
74 @brief
75 Total number of encrypted bytes received.
76 *///=========================================================================
77 __uint128_t crypt_rx;
78
79 /*======================================================================*//**
80 @brief
81 Total number of encrypted bytes spared (received, and remains in buffer).
82 *///=========================================================================
83 __uint128_t crypt_sx;
84
85 /*======================================================================*//**
86 @brief
87 Total number of encrypted bytes transmitted.
88 *///=========================================================================
89 __uint128_t crypt_tx;
90
91 /*======================================================================*//**
92 @brief
93 Should always be initialized to FALSE; reserved for the @c rsocket::~rsocket
94 destructor to set to TRUE.
95 @see rsocket::~rsocket()
96 *///=========================================================================
97 bool is_final;
98
99 }; // -x- struct rsocket_io -x-
100
101}; // -x- namespace randolf -x-