Skip to content

Refactoring libboostasio (part 6)#566

Open
paolopas wants to merge 28 commits intoCopernicaMarketingSoftware:masterfrom
paolopas:boosted-cld-6
Open

Refactoring libboostasio (part 6)#566
paolopas wants to merge 28 commits intoCopernicaMarketingSoftware:masterfrom
paolopas:boosted-cld-6

Conversation

@paolopas
Copy link
Copy Markdown

@paolopas paolopas commented Dec 23, 2025

Note

This is the sixth and last child, the code is branched from #562 (fifth child), so this one accumulate the changes.

Each commit has been checked for regressions.

  • 1870a70 finally, complete liberation from the useless shared_ptr is achieved, 23 commits ago, I never thought I'd see this... Now not only does the Watcher no longer have to inherit from enable_shared_from_this, but more importantly, the make_handler avoids creating another pair of weak/shared ptr to guard this (which previously was done at every callback invocation, i.e. every time the socket becomes readable or writable, even just to receive 1 byte!) But make_handler is now smarter for another reason too: in case of errors from boost it exits immediately without calling the callback at all. As I already explained, this, together with the cancellation of the callbacks by the destructor, allows you not to have to worry too much about the dangling of the this. Finally, the handler now stores children using unique_ptrs instead of shared_ptrs. Simple pointers could have been used, but I preferred to stay aligned with the other handlers. Now, when you erase the child in the map, the object is certainly destroyed. There are no delays of any kind, and no need to be careful to avoid releasing sockets too late. In short, everything works as expected, with no surprises. This is the greatest benefit for anyone who reads or maintains the code. This and a certain amount of appropriate comments added where needed.
  • 1c11cd9 given that callback methods are never called when boost reports an error, it is clear that they do not need to have the error as a parameter.
  • b1355f1 I replaced the pointer to the parent in the watchers with a reference to the strand, after all they don't ask much else from their parent.

As usual, for the more impatient among you, I'm leaving this latest version below. If the one that existed before I started working on it was in production, well, then this one can go to Mars.

replaces get_dispatch_wrapper,
switched from boost:: to std::bind and std::function
…re#464)

appended LibBoostAsioHandler ctor parameter (with default value)
uint16_t connection_timeout = 60
slow down the heartbeat emission if the client has
already sent data within the negotiated timeout,
a similar improvement was suggested for LivEvHandler in CopernicaMarketingSoftware#550
race condition due to *_pending flags no more possible,
updated footnote with important information for handler's user
called by destructor to prevent deadlocks,
relaxed assert in monitor to allow early realeses,
final notes update
method events renamed to set_event_mask
to the parent and no longer need the managed pointers for the strand
predictable watcher death,
smarter make_callback method
that no longer have to handle boost errors
reference, simplified constructor
as rw handlers have to be cancelled before
any change in _read/_write flag may occur

This reverts commit 060348c.
@paolopas
Copy link
Copy Markdown
Author

#547 fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant