Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-02-08 08:29:20


Christopher Kohlhoff wrote:

>> boost::asio::socket_acceptor tcp_acceptor(demuxer,
>> boost::asio::ipv4::tcp::endpoint(13));
>>
>> boost::asio::stream_socket* tcp_socket
>> = new boost::asio::stream_socket(demuxer);
>>
>> tcp_acceptor.async_accept(*tcp_socket,
>> boost::bind(handle_tcp_accept, &tcp_acceptor, tcp_socket,
>> boost::asio::placeholders::error));
>>
>> For example, what happens here if async_accept fails, perhaps
>> because of insufficient memory? Does it throw bad_alloc?
>
> It could.
>
>> Is the handler executed?
>
> No (according to above rules).

Not good. If you want the library to support this low-level style, the above
snippet should be exception-safe; this could be accomplished by calling the
handler with an appropriate asio error code.

This aside, why would one need shared_from_this?

     boost::asio::socket_acceptor tcp_acceptor(demuxer,
         boost::asio::ipv4::tcp::endpoint(13));

     boost::shared_ptr<boost::asio::stream_socket> tcp_socket(
       new boost::asio::stream_socket(demuxer) );

     tcp_acceptor.async_accept(*tcp_socket,
         boost::bind(handle_tcp_accept, &tcp_acceptor, tcp_socket,
           boost::asio::placeholders::error));


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