Opened 10 years ago

Closed 9 years ago

#7962 closed Bugs (wontfix)

shared_ptr of chat_server.cpp

Reported by: Shiwei Weng <wengshiwei@…> Owned by: chris_kohlhoff
Milestone: Boost 1.53.0 Component: asio
Version: Boost 1.53.0 Severity: Problem
Keywords: Cc:

Description

In the example file "chat_server.cpp" http://www.boost.org/doc/libs/1_52_0/doc/html/boost_asio/example/chat/chat_server.cpp

In the for-loop in the main:

chat_server_ptr server(new chat_server(io_service, endpoint));

while

typedef boost::shared_ptr<chat_server> chat_server_ptr;

Since a shared_ptr is used to manage chat_server, class chat_server should inherit public boost::enable_shared_from_this<chat_server>, just as class chat_session does.

Or in the member function start_accept() of class chat_server:

acceptor_.async_accept(

new_session->socket(), boost::bind(&chat_server::handle_accept, this, new_session,

boost::asio::placeholders::error));

The appearance of "this" seems problematic.

Thanks for reading. Shiwei Weng

Change History (1)

comment:1 by chris_kohlhoff, 9 years ago

Resolution: wontfix
Status: newclosed

In this case, the chat server is only put in a shared_ptr so that it may be stored in a std::list. For example, in C++11 this may be eliminated in favour of using std::list::emplace_back. It's lifetime outlasts io_service::run() so there isn't a need to tie the lifetime to the asynchronous operations it performs.

Note: See TracTickets for help on using tickets.