3#include <mutex> // std::mutex
7 /*======================================================================*//**
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).
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:
20 #include <randolf/rsocket>
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)
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:
33 #include <randolf/rsocket>
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)
43 Spare bytes are only applicable to received data statistics because buffering
44 is only used to receive data.
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 {
55 /*======================================================================*//**
57 Total number of unencrypted bytes received.
58 *///=========================================================================
61 /*======================================================================*//**
63 Total number of unencrypted bytes spared (received, and remains in buffer).
64 *///=========================================================================
67 /*======================================================================*//**
69 Total number of unencrypted bytes transmitted.
70 *///=========================================================================
73 /*======================================================================*//**
75 Total number of encrypted bytes received.
76 *///=========================================================================
79 /*======================================================================*//**
81 Total number of encrypted bytes spared (received, and remains in buffer).
82 *///=========================================================================
85 /*======================================================================*//**
87 Total number of encrypted bytes transmitted.
88 *///=========================================================================
91 /*======================================================================*//**
93 Should always be initialized to FALSE; reserved for the @c rsocket::~rsocket
94 destructor to set to TRUE.
95 @see rsocket::~rsocket()
96 *///=========================================================================
99 }; // -x- struct rsocket_io -x-
101}; // -x- namespace randolf -x-