Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / asio / detail / impl / resolver_service_base.ipp @ 2486

History | View | Annotate | Download (3.3 kB)

1
//
2
// detail/impl/resolver_service_base.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 BOOST_ASIO_DETAIL_IMPL_RESOLVER_SERVICE_BASE_IPP
12
#define BOOST_ASIO_DETAIL_IMPL_RESOLVER_SERVICE_BASE_IPP
13

    
14
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15
# pragma once
16
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17

    
18
#include <boost/asio/detail/config.hpp>
19
#include <boost/asio/detail/resolver_service_base.hpp>
20

    
21
#include <boost/asio/detail/push_options.hpp>
22

    
23
namespace boost {
24
namespace asio {
25
namespace detail {
26

    
27
class resolver_service_base::work_io_service_runner
28
{
29
public:
30
  work_io_service_runner(boost::asio::io_service& io_service)
31
    : io_service_(io_service) {}
32
  void operator()() { io_service_.run(); }
33
private:
34
  boost::asio::io_service& io_service_;
35
};
36

    
37
resolver_service_base::resolver_service_base(
38
    boost::asio::io_service& io_service)
39
  : io_service_impl_(boost::asio::use_service<io_service_impl>(io_service)),
40
    work_io_service_(new boost::asio::io_service),
41
    work_io_service_impl_(boost::asio::use_service<
42
        io_service_impl>(*work_io_service_)),
43
    work_(new boost::asio::io_service::work(*work_io_service_)),
44
    work_thread_(0)
45
{
46
}
47

    
48
resolver_service_base::~resolver_service_base()
49
{
50
  shutdown_service();
51
}
52

    
53
void resolver_service_base::shutdown_service()
54
{
55
  work_.reset();
56
  if (work_io_service_.get())
57
  {
58
    work_io_service_->stop();
59
    if (work_thread_.get())
60
    {
61
      work_thread_->join();
62
      work_thread_.reset();
63
    }
64
    work_io_service_.reset();
65
  }
66
}
67

    
68
void resolver_service_base::fork_service(
69
    boost::asio::io_service::fork_event fork_ev)
70
{
71
  if (work_thread_.get())
72
  {
73
    if (fork_ev == boost::asio::io_service::fork_prepare)
74
    {
75
      work_io_service_->stop();
76
      work_thread_->join();
77
    }
78
    else
79
    {
80
      work_io_service_->reset();
81
      work_thread_.reset(new boost::asio::detail::thread(
82
            work_io_service_runner(*work_io_service_)));
83
    }
84
  }
85
}
86

    
87
void resolver_service_base::construct(
88
    resolver_service_base::implementation_type& impl)
89
{
90
  impl.reset(static_cast<void*>(0), socket_ops::noop_deleter());
91
}
92

    
93
void resolver_service_base::destroy(
94
    resolver_service_base::implementation_type& impl)
95
{
96
  BOOST_ASIO_HANDLER_OPERATION(("resolver", &impl, "cancel"));
97

    
98
  impl.reset();
99
}
100

    
101
void resolver_service_base::cancel(
102
    resolver_service_base::implementation_type& impl)
103
{
104
  BOOST_ASIO_HANDLER_OPERATION(("resolver", &impl, "cancel"));
105

    
106
  impl.reset(static_cast<void*>(0), socket_ops::noop_deleter());
107
}
108

    
109
void resolver_service_base::start_resolve_op(operation* op)
110
{
111
  start_work_thread();
112
  io_service_impl_.work_started();
113
  work_io_service_impl_.post_immediate_completion(op, false);
114
}
115

    
116
void resolver_service_base::start_work_thread()
117
{
118
  boost::asio::detail::mutex::scoped_lock lock(mutex_);
119
  if (!work_thread_.get())
120
  {
121
    work_thread_.reset(new boost::asio::detail::thread(
122
          work_io_service_runner(*work_io_service_)));
123
  }
124
}
125

    
126
} // namespace detail
127
} // namespace asio
128
} // namespace boost
129

    
130
#include <boost/asio/detail/pop_options.hpp>
131

    
132
#endif // BOOST_ASIO_DETAIL_IMPL_RESOLVER_SERVICE_BASE_IPP