From 8e8b0719bf58e2d875c06698f86377189da87e16 Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Wed, 22 Mar 2017 17:59:08 +0100 Subject: Improve and centralize socket engine event counters. The write counters were close to useless because they were only incremented on a write "event" which is only triggered when writing would block. Read handling was a little more useful in that all reads must happen through the socket engine, so these were happening at the correct time, but we can clean this up by doing it in the SE itself rather than each platform port. This means that both read and write events are now easily and usefully defined as "a syscall of either read or write was attempted". We also count empty read and write events as being an event, because they still were an attempt to poll a socket in some way. This may help to identify "bad" code which is repeatedly trying to read a socket for some reason. Lastly, we check for failed read/write calls, and log them as an error event. A lot of the time, this is how sockets are determined as being disconnected (ie. at read/write time). While we're at it, split Update() in two to make the calls more self-describing. This has no real impact since only one call is made at a time anyway. --- include/socketengine.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/socketengine.h b/include/socketengine.h index c0026bfc6..b00643952 100644 --- a/include/socketengine.h +++ b/include/socketengine.h @@ -244,11 +244,19 @@ class CoreExport SocketEngine */ Statistics() : lastempty(0), TotalEvents(0), ReadEvents(0), WriteEvents(0), ErrorEvents(0) { } - /** Increase the counters for bytes sent/received in this second. - * @param len_in Bytes received, 0 if updating number of bytes written. - * @param len_out Bytes sent, 0 if updating number of bytes read. + /** Update counters for network data received. + * This should be called after every read-type syscall. + * @param len_in Number of bytes received, or -1 for error, as typically + * returned by a read-style syscall. */ - void Update(size_t len_in, size_t len_out); + void UpdateReadCounters(int len_in); + + /** Update counters for network data sent. + * This should be called after every write-type syscall. + * @param len_out Number of bytes sent, or -1 for error, as typically + * returned by a read-style syscall. + */ + void UpdateWriteCounters(int len_out); /** Get data transfer statistics. * @param kbitspersec_in Filled with incoming traffic in this second in kbit/s. -- cgit v1.2.3