
Marat,
Thanks for your informative response. Your answers helped to confirm my suspicions about Asio and Threads.
As you recall, I am using boost/Threads to execute io_service::run() to allow my server to have a main-thread application loop. The use of threads have complicated my application design by giving me problems to join the thread_group upon shutdown.
I just had the thought, maybe I can tickle the io_service each frame of my main-thread loop instead of using Threads? Is that the motivation for io_service::poll() ? Maybe using io_service.poll() will allow me to avoid the need for threads, at least while I'm proving the concept. What do you think?
Maybe I can contribute a more interesting TCP server example if this works. :) Ideally, it would also show clean shutdown when using threads to run the io_service, but I'm not there yet.
Also, I began looking at your code. Thank you for making it available. I'm a little worried it will take me as long to learn your framework as it will to learn the Asio framework. I will keep trying, as it is likely the only example use of Asio that I know of other than the simple examples on Asio's documentation.
Many thanks,
John
________________________________
From: Marat Abrarov
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_c... Regards, Marat Abrarov. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users