예제 #1
0
    void async_wait(implementation_type &impl, pid_type pid, Handler handler)
    {
#if defined(BOOST_POSIX_API)
        boost::unique_lock<boost::mutex> lock(work_thread_mutex_);
        if (++pids_ == 1)
        {
            work_.reset(new boost::asio::io_service::work(
                this->get_io_service()));
            work_thread_ = boost::thread(
                &basic_status_service<StatusImplementation>::work_thread,
                this);
        }
        impl->async_wait(pid, this->get_io_service().wrap(handler));
#elif defined(BOOST_WINDOWS_API)
        HANDLE handle = OpenProcess(SYNCHRONIZE | PROCESS_QUERY_INFORMATION,
            FALSE, pid);
        if (handle == NULL)
            BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("OpenProcess() failed");
        boost::unique_lock<boost::mutex> lock(work_thread_mutex_);
        if (!work_)
            work_.reset(new boost::asio::io_service::work(
                this->get_io_service()));
        interrupt_work_thread();
        work_thread_cond_.wait(work_thread_mutex_);
        handles_.push_back(handle);
        impl->async_wait(handle, this->get_io_service().wrap(handler));
        work_thread_cond_.notify_all();
#endif
    }
예제 #2
0
 message send(implementation_type& impl,
     message& m,
     const Duration& timeout)
 {
   if(timeout == Duration::zero()) {
     //TODO this can return false if it failed
     impl.send(m);
     return message();
   } else {
     return impl.send_with_reply_and_block(m,
       chrono::milliseconds(timeout).count());
   }
 }
예제 #3
0
    void destroy(implementation_type &impl)
    {
        boost::unique_lock<boost::mutex> lock(work_thread_mutex_);
        typename std::vector<implementation_type>::iterator it =
            std::find(impls_.begin(), impls_.end(), impl);
        if (it != impls_.end())
            impls_.erase(it);
#if defined(BOOST_WINDOWS_API)
        interrupt_work_thread();
        work_thread_cond_.wait(work_thread_mutex_);
        impl->clear(handles_);
        work_thread_cond_.notify_all();
#endif
        impl.reset();
    }
예제 #4
0
  void open(implementation_type& impl,
      const int bus = bus::system)
  {
    io_service& io = this->get_io_service();

    impl.open(io, bus);
  }
예제 #5
0
 void destroy(
     implementation_type & impl)
 {
     error_code ec;
     cancel(impl, ec);
     impl.reset();
 }
예제 #6
0
    int wait(implementation_type &impl, pid_type pid)
    {
        boost::system::error_code ec;
        int status = impl->wait(pid, ec);
#if defined(BOOST_POSIX_API)
        if (ec.value() == ECHILD)
        {
            boost::unique_lock<boost::mutex> lock(work_thread_mutex_);
            boost::unordered_map<pid_t, int>::iterator it = statuses_.find(pid);
            if (it == statuses_.end())
            {
                work_thread_cond_.wait(work_thread_mutex_);
                it = statuses_.find(pid);
            }
            if (it != statuses_.end())
            {
                status = it->second;
                statuses_.erase(it);
                ec.clear();
            }
        }
#endif
        boost::asio::detail::throw_error(ec);
        return status;
    }
    void async_wait(
        implementation_type& impl,
        NotificationHandler handler)
      {
      basic_signal_callback h = handler;
      
      if (is_process_thread())
        {
        impl->async_wait(h);

        return;
        }

      apoa::get_process_io_service().post(
        std::bind(
          &signal_handler_base_impl::async_wait, impl.get(),
          h));
      }
 void
 async_resolve (
     implementation_type &impl,
     const string & domain,
     const net::dns::type_t rrtype,
     CallbackHandler handler )
 {
   net::dns::question question(domain, rrtype);
   impl->async_resolve(question, handler);
 }
예제 #9
0
      async_accept(implementation_type& impl,
                   basic_socket<Protocol1, SocketService>& peer,
                   endpoint_type* peer_endpoint,
                   BOOST_ASIO_MOVE_ARG(AcceptHandler) handler,
                   typename enable_if<
                       is_convertible<Protocol, Protocol1>::value>::type* = 0) {
    boost::asio::detail::async_result_init<AcceptHandler,
                                           void(boost::system::error_code)>
                                           init(BOOST_ASIO_MOVE_CAST(AcceptHandler)(handler));
    
    {
      boost::recursive_mutex::scoped_lock lock_state(impl->state_mutex);
      if (impl->closed) {
        auto handler_to_post = [init]() mutable {
          init.handler(
            boost::system::error_code(ssf::error::not_connected,
            ssf::error::get_ssf_category()));
        };
        this->get_io_service().post(handler_to_post);

        return init.result.get();
      }
    }

    boost::system::error_code ec;

    auto fiber_impl = peer.native_handle();
    fiber_impl->p_fib_demux = impl->p_fib_demux;
    fiber_impl->id.set_local_port(impl->id.local_port());

    BOOST_LOG_TRIVIAL(debug) << "fiber acceptor: local port set " << impl->id.local_port();

    typedef detail::pending_accept_operation<
        AcceptHandler, typename Protocol::socket_type> op;
    typename op::ptr p = {
        boost::asio::detail::addressof(init.handler),
        boost_asio_handler_alloc_helpers::allocate(sizeof(op), init.handler),
        0};

    p.p = new (p.v)
        op(peer.native_handle(), &(peer.native_handle()->id), init.handler);
    {
      boost::recursive_mutex::scoped_lock lock(impl->accept_op_queue_mutex);
      impl->accept_op_queue.push(p.p);
    }
    p.v = p.p = 0;
    impl->a_queues_handler();

    return init.result.get();
  }
 void
 add_nameserver ( implementation_type &impl, ip::address addr )
 {
   impl->add_nameserver(addr);
 }
 void
 async_resolve ( implementation_type &impl, const net::dns::question & question, CallbackHandler handler )
 {
   impl->async_resolve(question, handler);
 }
 rr_list_t
 resolve ( implementation_type &impl, const string & domain, const net::dns::type_t rrtype )
 {
   return impl->resolve(domain, rrtype);
 }
 void
 destroy ( implementation_type &impl )
 {
   impl->destroy();
   impl.reset();
 }
 void
 construct ( implementation_type &impl )
 {
   impl.reset(new DnsResolverImplementation(this->get_io_service()));
 }
예제 #15
0
 /// Cancel all asynchronous operations associated with the stream fiber.
 boost::system::error_code cancel(implementation_type& impl,
                                  boost::system::error_code& ec)
 {
   impl->cancel_operations();
   return ec;
 }
예제 #16
0
 message send(implementation_type& impl,
     message& m)
 {
   return impl.send_with_reply_and_block(m);
 }
 rr_list_t
 resolve ( implementation_type &impl, const net::dns::question & question )
 {
   return impl->resolve(question);
 }
예제 #18
0
 void construct(
     implementation_type & impl)
 {
     impl.reset(new ResolveTask);
 }