|
Boost Users : |
Subject: Re: [Boost-users] Boost.Asio server application close get "This application has requested the Runtime to terminate it in an unusual way."
From: l.jay Yuan (pass86_at_[hidden])
Date: 2010-03-10 20:12:22
int main(int argc, char* argv[])
{
try
{
if (argc < 2)
{
std::cerr << "Usage: chat_server <port> [<port> ...]\n";
return 1;
}
boost::asio::io_service io_service;
chat_server_list servers;
for (int i = 1; i < argc; ++i)
{
using namespace std; // For atoi.
tcp::endpoint endpoint(tcp::v4(), atoi(argv[i]));
chat_server_ptr server(new chat_server(io_service, endpoint));
servers.push_back(server);
}
io_service.run();
/**************
just like this, so io_service.run(); is not needed.
boost::thread io_thread(boost::bind(&boost::asio::io_service::run,
&io_service));
std::string line;
while(getline(std::cin, line)) {
if (line == "exit") {
/* do what? now i am using io_service.stop(); */
break;
}
}
io_thread.join();
***************/
}
catch (std::exception& e)
{
std::cerr << "Exception: " << e.what() << "\n";
}
return 0;
}
2010/3/11 l.jay Yuan <pass86_at_[hidden]>:
> can you code the Boost.Asio chat server example for exit by a command?
> if you can, my problem solved.
>
> 2010/3/10 Igor R <boost.lists_at_[hidden]>:
>>> thanks everyone, i solved my problem.
>>> just use io_service.stop() instead of acceptor.close() and socket.close().
>>> maybe i must to research the implementation.
>>
>> It's not a solution but just a "dirty" workaround: by stopping
>> io_service you prevent the further invocation of handlers. I guess
>> some of your handlers used to get called after destruction of the
>> object they were bound to. You can avoid this situation by binding the
>> handlers to shared_from_this().
>> _______________________________________________
>> Boost-users mailing list
>> Boost-users_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>>
>
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