Exemple #1
0
  async_read_some(const MutableBufferSequence& buffers, Handler handler)
  {
#if (BOOST_VERSION >= 105400)
    typedef typename asio::handler_type<Handler,
      void (asio::error_code, std::size_t)>::type real_handler_type;
    real_handler_type real_handler(handler);
    asio::async_result<real_handler_type> result(real_handler);
#else // (BOOST_VERSION >= 105400)
    Handler real_handler(handler);
#endif // (BOOST_VERSION >= 105400)

    switch (protocol_)
    {
    case file:
      file_.async_read_some(buffers, real_handler);
      break;
    case http:
      http_.async_read_some(buffers, real_handler);
      break;
#if !defined(URDL_DISABLE_SSL)
    case https:
      https_.async_read_some(buffers, real_handler);
      break;
#endif // !defined(URDL_DISABLE_SSL)
    default:
      asio::error_code ec
        = asio::error::operation_not_supported;
      io_service_.post(asio::detail::bind_handler(real_handler, ec, 0));
      break;
    }

#if (BOOST_VERSION >= 105400)
    return result.get();
#endif // (BOOST_VERSION >= 105400)
  }
Exemple #2
0
  async_open(const url& u, Handler handler)
  {
#if (BOOST_VERSION >= 105400)
    typedef typename asio::handler_type<Handler,
      void (asio::error_code)>::type real_handler_type;
    real_handler_type real_handler(handler);
    asio::async_result<real_handler_type> result(real_handler);
#else // (BOOST_VERSION >= 105400)
    typedef Handler real_handler_type;
    Handler real_handler(handler);
#endif // (BOOST_VERSION >= 105400)

    open_coro<real_handler_type>(this, u, real_handler)(
        asio::error_code());

#if (BOOST_VERSION >= 105400)
    return result.get();
#endif // (BOOST_VERSION >= 105400)
  }
Exemple #3
0
  async_open(const url& u, Handler handler)
  {
    typedef typename asio::handler_type<Handler,
      void (asio::error_code)>::type real_handler_type;
    real_handler_type real_handler(handler);
    asio::async_result<real_handler_type> result(real_handler);

    open_coro<real_handler_type>(this, u, real_handler)(
        asio::error_code());

    return result.get();
  }
      async_write(const std::string &data, Handler &&handler) {
    BUNSAN_ASIO_INITFN_BEGIN(Handler, handler, void(boost::system::error_code),
                             real_handler, result)

    std::ostringstream header_stream;
    const header size = data.size();
    header_stream << std::setw(HEADER_SIZE) << std::hex << size;
    if (!header_stream || header_stream.str().size() != HEADER_SIZE) {
      boost::system::error_code error(boost::asio::error::invalid_argument);
      get_io_service().post(std::bind(real_handler, error));
    }
    m_outbound_header = header_stream.str();

    std::vector<boost::asio::const_buffer> buffers = {
        boost::asio::buffer(m_outbound_header), boost::asio::buffer(data)};
    boost::asio::async_write(
        m_connection, buffers,
        [real_handler](const boost::system::error_code &ec,
                       const std::size_t) mutable { real_handler(ec); });

    BUNSAN_ASIO_INITFN_END(result)
  }