Boost logo

Boost :

From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2021-09-21 14:34:02

Hi Everyone,
I am looking at an example implementation of an asynchronous TCP echo
server in Boost.ASIO library:

It uses a shared_ptr in the implementation to store the things related to
session: socket handle, data buffers. I tried to modify it in a number of
ways to avoid the usage of shared_ptr (and any form of shared ownership),
but they all failed. It looks like I have to use a shared_pointer (or
equivalent) when I use ASIO sockets.

But conceptually, there is never a point in time where two tasks have to
access members of this `session` concurrently: they are always sequenced.
So, at least conceptually, there should be a way to do this with a session
type that is only movable, with unique ownership: a task does its job with
the session and then moves it to the subsequent task. So is this necessity
to use a shared pointer an unnecessary and suboptimal design choice? Or is
there something fundamental that prevents the unique ownership of buffers
and socket handles? Or maybe is there a way to do it in ASIO that I

I am not trying to solve any specific problem. It just strikes me that a
shared_ptr is used in a demo example for the library. I was always of the
opinion that a shared_ptr is often abused as a way of doing an ad-hoc GC.


Boost list run by bdawes at, gregod at, cpdaniel at, john at