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 ulong total_rx = io->bytes_rx // Bytes received (unencrypted)
24 + io->crypt_rx; // Bytes received (encrypted)
25 ulong 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 ulong 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 ulong 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 /// Total number of unencrypted bytes received
55 ulong bytes_rx;
56 /// Total number of unencrypted bytes spared (received, but left in buffer)
57 ulong bytes_sx;
58 /// Total number of unencrypted bytes transmitted
59 ulong bytes_tx;
60 /// Total number of encrypted bytes received
61 ulong crypt_rx;
62 /// Total number of encrypted bytes spared (received, but left in buffer)
63 ulong crypt_sx;
64 /// Total number of encrypted bytes transmitted
65 ulong crypt_tx;
66 /// Should always be initialized to FALSE; reserved by ~rsocket to set to TRUE
67 bool is_final;
68 }; // -x- struct rsocket_io -x-
69
70}; // -x- namespace randolf -x-