void operator()(const autoboost::system::error_code& ec, std::size_t bytes_transferred, int start = 0) { switch (start_ = start) { case 1: buffers_.prepare(this->check_for_completion(ec, total_transferred_)); for (;;) { device_.async_write_some_at( offset_ + total_transferred_, buffers_, AUTOBOOST_ASIO_MOVE_CAST(write_at_op)(*this)); return; default: total_transferred_ += bytes_transferred; buffers_.consume(bytes_transferred); buffers_.prepare(this->check_for_completion(ec, total_transferred_)); if ((!ec && bytes_transferred == 0) || buffers_.begin() == buffers_.end()) break; } handler_(ec, static_cast<const std::size_t&>(total_transferred_)); } }
void operator()(const asio::error_code& ec, std::size_t bytes_transferred, int start = 0) { std::size_t max_size, bytes_available; switch (start) { case 1: max_size = this->check_for_completion(ec, total_transferred_); bytes_available = read_size_helper(streambuf_, max_size); for (;;) { stream_.async_read_some(streambuf_.prepare(bytes_available), *this); return; default: total_transferred_ += bytes_transferred; streambuf_.commit(bytes_transferred); max_size = this->check_for_completion(ec, total_transferred_); bytes_available = read_size_helper(streambuf_, max_size); if ((!ec && bytes_transferred == 0) || bytes_available == 0) break; } handler_(ec, static_cast<const std::size_t&>(total_transferred_)); } }
void operator()(const asio::error_code& ec, std::size_t bytes_transferred, int start = 0) { std::size_t n = 0; switch (start) { case 1: n = this->check_for_completion(ec, total_transferred_); for (;;) { device_.async_read_some_at(offset_ + total_transferred_, asio::buffer(buffer_ + total_transferred_, n), ASIO_MOVE_CAST(read_at_op)(*this)); return; default: total_transferred_ += bytes_transferred; if ((!ec && bytes_transferred == 0) || (n = this->check_for_completion(ec, total_transferred_)) == 0 || total_transferred_ == asio::buffer_size(buffer_)) break; } handler_(ec, static_cast<const std::size_t&>(total_transferred_)); } }
void operator()(const boost::system::error_code& ec, std::size_t bytes_transferred, int start = 0) { std::size_t n = 0; switch (start_ = start) { case 1: n = this->check_for_completion(ec, total_transferred_); for (;;) { stream_.async_write_some( boost::asio::buffer(buffer_ + total_transferred_, n), BOOST_ASIO_MOVE_CAST(write_op)(*this)); return; default: total_transferred_ += bytes_transferred; if ((!ec && bytes_transferred == 0) || (n = this->check_for_completion(ec, total_transferred_)) == 0 || total_transferred_ == boost::asio::buffer_size(buffer_)) break; } handler_(ec, static_cast<const std::size_t&>(total_transferred_)); } }
void SignalThread::run_(const SignalSet& sigset) { // boost::asio has support for signals via signal_set. It does however not // accept a sigset_t and neither can a sigset_t nor a ba::signal_set be inspected. int sigfd = signalfd(-1, &sigset.sigset(), SFD_NONBLOCK); if (sigfd < 0) { LOG_ERROR("Failed to create signalfd: " << strerror(errno)); throw Exception("Failed to create signalfd"); } auto exit(make_scope_exit([&] { close(sigfd); })); std::function<void()> g; auto f([&](const bs::error_code& ec, std::size_t bytes) { VERIFY(bytes == 0); if (ec) { LOG_ERROR("error in signal handler: " << ec.message()); } else { signalfd_siginfo si; ssize_t ret = ::read(sigfd, &si, sizeof(si)); if (ret < 0) { if (ret != EAGAIN) { ret = errno; LOG_ERROR("failed to read siginfo from signalfd: " << strerror(ret) << " (" << ret << ")"); } g(); } else if (ret != sizeof(si)) { LOG_ERROR("read less (" << ret << " ) than expected (" << sizeof(si) << ") from signalfd"); } else { LOG_INFO("caught signal " << si.ssi_signo); handler_(si.ssi_signo); g(); } } }); ba::posix::stream_descriptor sigdesc(io_service_, sigfd); g = [&]() { sigdesc.async_read_some(ba::null_buffers(), f); }; g(); bs::error_code ec; io_service_.run(ec); if (ec) { LOG_ERROR("error running I/O service of signal thread: " << ec.message()); }; LOG_INFO("exiting signal handler thread"); }
virtual void handleError( const BaseError& e ) // from IProfileCallbackProxy { if( handler_ ) handler_(e); }
void on_fork_setup(PosixExecutor &e) const { handler_(e); }
void operator()() const { handler_(arg1_, arg2_, arg3_, arg4_, arg5_); }
void operator()(const Arg1& arg1) const { handler_(arg1); }
void operator()() { handler_(); }
void operator()(const clmdep_asio::error_code& ec, const std::size_t bytes_transferred) { storage_.resize(previous_size_ + bytes_transferred); handler_(ec, bytes_transferred); }
void operator()() const { handler_(context_); }
void operator()(const Arg1& arg1) const { handler_(context_, arg1); }
void operator()(const Arg1& arg1, const Arg2& arg2) { handler_(static_cast<const Context&>(context_), arg1, arg2); }
void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3, const Arg4& arg4, const Arg5& arg5) { handler_(static_cast<const Context&>(context_), arg1, arg2, arg3, arg4, arg5); }
void operator()() { handler_(static_cast<const Context&>(context_)); }
void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3, const Arg4& arg4) const { handler_(arg1, arg2, arg3, arg4); }
void operator()(const Arg1& arg1, const Arg2& arg2) const { handler_(arg1, arg2); }
void Wait::CallHandler(async_dispatcher_t* dispatcher, async_wait_t* wait, zx_status_t status, const zx_packet_signal_t* signal) { auto self = Dispatch<Wait>(wait); self->handler_(dispatcher, self, status, signal); }
void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3) const { handler_(context_, arg1, arg2, arg3); }
void operator()(const asio::error_code& ec, const std::size_t bytes_written) { storage_.consume(bytes_written); handler_(ec, bytes_written); }
void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3, const Arg4& arg4, const Arg5& arg5) const { handler_(context_, arg1, arg2, arg3, arg4, arg5); }
void operator()() const { handler_(); }
void operator()() const { handler_(arg1_); }
void on_exec_error(PosixExecutor &e) const { handler_(e); }
void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3) { handler_(arg1, arg2, arg3); }
void operator()() { handler_(static_cast<const Arg1&>(arg1_)); }
void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3, const Arg4& arg4, const Arg5& arg5) { handler_(arg1, arg2, arg3, arg4, arg5); }
void operator()(const boost::system::error_code& ec, const std::size_t bytes_transferred) { storage_.resize(previous_size_ + bytes_transferred); handler_(ec, bytes_transferred); }
void operator()(const boost::system::error_code& ec, std::size_t bytes_transferred, int start = 0) { const std::size_t not_found = (std::numeric_limits<std::size_t>::max)(); std::size_t bytes_to_read; switch (start_ = start) { case 1: for (;;) { { // Determine the range of the data to be searched. typedef typename boost::asio::basic_streambuf< Allocator>::const_buffers_type const_buffers_type; typedef boost::asio::buffers_iterator<const_buffers_type> iterator; const_buffers_type buffers = streambuf_.data(); iterator begin = iterator::begin(buffers); iterator start_pos = begin + search_position_; iterator end = iterator::end(buffers); // Look for a match. iterator iter = std::find(start_pos, end, delim_); if (iter != end) { // Found a match. We're done. search_position_ = iter - begin + 1; bytes_to_read = 0; } // No match yet. Check if buffer is full. else if (streambuf_.size() == streambuf_.max_size()) { search_position_ = not_found; bytes_to_read = 0; } // Need to read some more data. else { // Next search can start with the new data. search_position_ = end - begin; bytes_to_read = read_size_helper(streambuf_, 65536); } } // Check if we're done. if (!start && bytes_to_read == 0) break; // Start a new asynchronous read operation to obtain more data. stream_.async_read_some(streambuf_.prepare(bytes_to_read), BOOST_ASIO_MOVE_CAST(read_until_delim_op)(*this)); return; default: streambuf_.commit(bytes_transferred); if (ec || bytes_transferred == 0) break; } const boost::system::error_code result_ec = (search_position_ == not_found) ? error::not_found : ec; const std::size_t result_n = (ec || search_position_ == not_found) ? 0 : search_position_; handler_(result_ec, result_n); } }