Enable watching of Connection state

Authored by ahartmetz on Dec 9 2018, 11:48 PM.

Description

Enable watching of Connection state

Most of this commit is changing I/O notification to enable proper
error handling. The IConnectionStateListener added here, besides
being useful for API clients, is needed for upcoming IServer tests
and probably other future tests.

Some difficult decisions had to be made for this, so in case
this area needs to be revisited, here goes the rationale:

I/O readiness is passed through a call stack from the event poller
(implementing IEventPoller) through possibly several
IIoEventListener - IIoEventSource pairs (convenience class:
IIoEventForwarder) to a final IIoEventListener. The final
IIoEventListener is an ITtransport or IServer. The ITransport
talks to an ITransportListener, which is usually a
ConnectionPrivate, which talks to an IMessageReceiver.
Why go through this chain every time instead of taking a shortcut,
e.g. from IIoEventSource to ITransport?
The reason is safety of invoking event handling callbacks.
I have taken care to always call callbacks last in every method,
so that no (at that point possibly freed inside the callback)
member variables need to be touched after the callback returns.
So that is safe.
The other reason is simplicity (really) in implementating this
safe callback scheme - if there was a more direct connection
for the non-error path (plain I/O notification), and one of the
classes skipped in that direct connection approach had to be
notified about errors, there'd have to be another code path
and data structure for that kind of notification, and it would be
less exercised. A recipe for latent bugs that only trigger in the
already rare error cases. It would also need more code overall due
to the two paths.
So, by passing I/O events through this whole call stack, natural
and relatively safe points to handle errors are introduced. The
somewhat complicated and difficult code path is also the one
regulary used and exercised.
Overhead should be minimal, which is unintuitive, but the syscall
overhead for I/O really is much greater than the overhead of a few
virtual method calls.

Details

Committed
ahartmetzAug 5 2019, 8:17 PM
Parents
R738:405adbffd6bc: Use member default initalization for ConnectionPrivate
Branches
Unknown
Tags
Unknown