2 * Copyright 2013 Sveriges Television AB http://casparcg.com/
4 * This file is part of CasparCG (www.casparcg.com).
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * CasparCG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
19 * Author: Helge Norberg, helge.norberg@svt.se
22 #include "../StdAfx.h"
24 #include "io_service_manager.h"
28 #include <boost/asio/io_service.hpp>
29 #include <boost/thread/thread.hpp>
31 #include <common/exception/win32_exception.h>
33 namespace caspar { namespace protocol { namespace asio {
35 struct io_service_manager::impl
37 boost::asio::io_service service_;
38 // To keep the io_service::run() running although no pending async
39 // operations are posted.
40 std::unique_ptr<boost::asio::io_service::work> work_;
41 boost::thread thread_;
44 : work_(new boost::asio::io_service::work(service_))
45 , thread_([this] { run(); })
51 win32_exception::ensure_handler_installed_for_thread("asio-thread");
64 io_service_manager::io_service_manager()
69 io_service_manager::~io_service_manager()
73 boost::asio::io_service& io_service_manager::service()
75 return impl_->service_;