1// 2// impl/io_service.ipp 3// ~~~~~~~~~~~~~~~~~~~ 4// 5// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) 6// 7// Distributed under the Boost Software License, Version 1.0. (See accompanying 8// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 9// 10 11#ifndef ASIO_IMPL_IO_SERVICE_IPP 12#define ASIO_IMPL_IO_SERVICE_IPP 13 14 15#include "asio/detail/config.hpp" 16#include "asio/io_service.hpp" 17#include "asio/detail/limits.hpp" 18#include "asio/detail/scoped_ptr.hpp" 19#include "asio/detail/service_registry.hpp" 20#include "asio/detail/throw_error.hpp" 21 22# include "asio/detail/task_io_service.hpp" 23 24#include "asio/detail/push_options.hpp" 25 26namespace asio { 27 28io_service::io_service() 29 : service_registry_(new asio::detail::service_registry( 30 *this, static_cast<impl_type*>(0), 31 (std::numeric_limits<std::size_t>::max)())), 32 impl_(service_registry_->first_service<impl_type>()) 33{ 34} 35 36io_service::io_service(std::size_t concurrency_hint) 37 : service_registry_(new asio::detail::service_registry( 38 *this, static_cast<impl_type*>(0), concurrency_hint)), 39 impl_(service_registry_->first_service<impl_type>()) 40{ 41} 42 43io_service::~io_service() 44{ 45 delete service_registry_; 46} 47 48std::size_t io_service::run() 49{ 50 asio::error_code ec; 51 std::size_t s = impl_.run(ec); 52 asio::detail::throw_error(ec); 53 return s; 54} 55 56std::size_t io_service::run(asio::error_code& ec) 57{ 58 return impl_.run(ec); 59} 60 61std::size_t io_service::run_one() 62{ 63 asio::error_code ec; 64 std::size_t s = impl_.run_one(ec); 65 asio::detail::throw_error(ec); 66 return s; 67} 68 69std::size_t io_service::run_one(asio::error_code& ec) 70{ 71 return impl_.run_one(ec); 72} 73 74std::size_t io_service::poll() 75{ 76 asio::error_code ec; 77 std::size_t s = impl_.poll(ec); 78 asio::detail::throw_error(ec); 79 return s; 80} 81 82std::size_t io_service::poll(asio::error_code& ec) 83{ 84 return impl_.poll(ec); 85} 86 87std::size_t io_service::poll_one() 88{ 89 asio::error_code ec; 90 std::size_t s = impl_.poll_one(ec); 91 asio::detail::throw_error(ec); 92 return s; 93} 94 95std::size_t io_service::poll_one(asio::error_code& ec) 96{ 97 return impl_.poll_one(ec); 98} 99 100void io_service::stop() 101{ 102 impl_.stop(); 103} 104 105bool io_service::stopped() const 106{ 107 return impl_.stopped(); 108} 109 110void io_service::reset() 111{ 112 impl_.reset(); 113} 114 115void io_service::notify_fork(asio::io_service::fork_event event) 116{ 117 service_registry_->notify_fork(event); 118} 119 120io_service::service::service(asio::io_service& owner) 121 : owner_(owner), 122 next_(0) 123{ 124} 125 126io_service::service::~service() 127{ 128} 129 130void io_service::service::fork_service(asio::io_service::fork_event) 131{ 132} 133 134service_already_exists::service_already_exists() 135 : std::logic_error("Service already exists.") 136{ 137} 138 139invalid_service_owner::invalid_service_owner() 140 : std::logic_error("Invalid service owner.") 141{ 142} 143 144} // namespace asio 145 146#include "asio/detail/pop_options.hpp" 147 148#endif // ASIO_IMPL_IO_SERVICE_IPP 149