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 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)
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 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)
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 {
54 /// Total number of unencrypted bytes received
56 /// Total number of unencrypted bytes spared (received, but left in buffer)
58 /// Total number of unencrypted bytes transmitted
60 /// Total number of encrypted bytes received
62 /// Total number of encrypted bytes spared (received, but left in buffer)
64 /// Total number of encrypted bytes transmitted
66 /// Should always be initialized to FALSE; reserved by ~rsocket to set to TRUE
68 }; // -x- struct rsocket_io -x-
70}; // -x- namespace randolf -x-