|
Boost Users : |
Subject: Re: [Boost-users] asio - improving chat server example for my
From: Marat Abrarov (abrarov_at_[hidden])
Date: 2012-05-19 15:43:29
Hi, John.
> Many thanks for any help. I'm really enjoying Asio and other parts of Boost, but I still don't
> understand the framework completely.
Sorry, if I'm spamming you but feel free to read Asio examples at my project -
http://sourceforge.net/projects/asio-samples. May be it can help in some architecture decisions.
> 2- This might be way off, but I also wondered if I need to close all the sockets so that the thread group could join.
Yes, you need to close all sockets (and other instances of asio::basic_io_object) having pending asynchronous operations
(read/write for sockets, async_wait for timers, etc), related to the used instance of asio::io_service. Otherwise you
can call asio::io_service::stop().
> I added 2 member functions to help me:
>
> void chat_server::close()
> {
> ? room_.close();
> }
>
> void chat_room::close()
> {
> ? std::for_each( participants_.begin(), participants_.end(), boost::bind(&chat_room::leave, this, _1)
> );
> }
>
> I call this in my server app class's destructor before calling thread_group::join_all, but this has a
> crash. The crash occurs right after chat_room::close() completes. I'm not confident in the way I used
> bind(...), but I was able to see the function execute, and then the crash occurs later.
You need to implement chat_participant::close() like it is done at:
http://www.boost.org/doc/libs/1_49_0/doc/html/boost_asio/example/chat/chat_client.cpp
Regards,
Marat Abrarov.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net