Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-02-06 22:46:21


Giovanni P. Deretta wrote:
>
> The problem is that a socket is *conceptually* not copyable. Even if
> you have multiple handles to it, they all refer to the same underlying
> stream. Standard streams are not copyable for the same reason. If you
> want different objects to *share* a socket you use a shared_ptr and
> dynamically allocate it.

In principle, it is true that a stream or a socket a conceptually not
copyable. In practice, a stream or a socket is much easier to use
(correctly) if it is copyable with reference semantics (and thread safe too,
but that's a different story :-) ) - as ordinary C FILE*s and sockets are
(although they have to be closed manually, of course.)

I'm not really arguing that an asio socket has to be copyable and
refcounted... yet, because I don't have the experience to determine how
often I'd need to allocate it on the heap in real code. But the tutorial
does allocate its sockets on the heap. :-)


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk