をクラッシュ私は現在、ブーストを使用して、サーバーアプリケーションを作成しようとしています:: ASIO 2つの単純なことを行います。ブースト:: ASIO - async_acceptハンドラ内async_waitは、アプリケーション
- たら、クライアントの着信接続
- を受け入れます
:クライアントは繰り返す#define BOOST_ASIO_ENABLE_HANDLER_TRACKING #include <WinSock2.h> #include <Mswsock.h> #include <boost/asio/io_service.hpp> #include <boost/asio/ip/tcp.hpp> #include <boost/bind.hpp> #include <boost/date_time/posix_time/posix_time.hpp> using namespace boost::asio; using namespace boost::asio::ip; void timerHandler(const boost::system::error_code& errorCode, deadline_timer* timer) { timer->expires_at(timer->expires_at() + boost::posix_time::seconds(1)); timer->async_wait(boost::bind(timerHandler, _1, timer)); } void acceptHandler(const boost::system::error_code &errorCode, io_service *ioService) { deadline_timer timer(*ioService, boost::posix_time::seconds(1)); timer.async_wait(boost::bind(timerHandler, _1, &timer)); } int main(int argc, char** argv) { io_service ioService; tcp::socket socket(ioService); tcp::acceptor acceptor{ ioService, tcp::endpoint{ tcp::v4(), 12345 } }; acceptor.listen(); acceptor.async_accept(socket, boost::bind(acceptHandler, _1, &ioService)); ioService.run(); return EXIT_SUCCESS; }
boost::asio::deadline_timer
が
次のコードは、私の現在の試みを示し始める、受け入れられてきました
問題:acceptHandler
で期待どおりに
タイマーは何とか動作しません。何とか2回取り消され、その上でエラーが発生し、最終的にアプリケーション全体がクラッシュします。
ハンドラのトラッキング出力:
@asio|1460922050.075890|0*1|[email protected]_accept
@asio|1460922051.153952|>1|ec=system:0
@asio|1460922051.153952|1*2|[email protected]_wait
@asio|1460922051.153952|1|[email protected]
@asio|1460922051.153952|<1|
@asio|1460922051.153952|>2|ec=system:995
@asio|1460922051.153952|2|[email protected]
質問:
acceptHandler
はハンドラトラッキング出力の4行目にdeadline_timerをキャンセルする原因は何?ハンドラートラッキング出力の6行目にエラー995がありますか?エラーメッセージは次のとおりです。I/O操作がスレッドの終了またはアプリケーションの要求ハンドラトラッキング出力の行7でdeadline_timerをキャンセルするtimerHandlerの原因は何
のいずれかで中止されましたか?
どのような愚かな間違い。ありがとうございました。ここではスニペットの簡潔さのためにエラーチェックをしました。私は通常、すべてのハンドラでスイッチケースを扱います。 – chrisp