boost::optional<std::pair<const_buffers_type, bool>> get(error_code& ec) { ec.assign(0, ec.category()); return {{const_buffers_type{ body_.data(), body_.size()}, false}}; }
std::size_t put(ConstBufferSequence const& buffers, error_code& ec) { using boost::asio::buffer_copy; using boost::asio::buffer_size; auto const n = buffer_size(buffers); if(body_.size() > body_.max_size() - n) { ec = error::buffer_overflow; return 0; } boost::optional<typename DynamicBuffer::mutable_buffers_type> b; try { b.emplace(body_.prepare((std::min)(n, body_.max_size() - body_.size()))); } catch(std::length_error const&) { ec = error::buffer_overflow; return 0; } ec.assign(0, ec.category()); auto const bytes_transferred = buffer_copy(*b, buffers); body_.commit(bytes_transferred); return bytes_transferred; }
bool equivalent (error_code const& code, int condition ) const noexcept override { return *this == code.category() && code.value() == condition; }
void on_error(error_code const& code) { if (code) { if // usually, by on_receive ((code.category() == error::misc_category && code.value () == error::eof) || // and these - by on_send (code.category() == error::system_category && code.value () == error::connection_reset) || (code.category() == error::system_category && code.value () == error::broken_pipe )) { on_discon_(code); } else on_error_(code); } }
void init(boost::optional< std::uint64_t> const& length, error_code& ec) { if(length && *length > body_.size()) { ec = error::buffer_overflow; return; } ec.assign(0, ec.category()); }
void HttpProxy::response_error( error_code const & ec, response_type const & resp) { HttpResponseHead & head = response_.head(); error_code ec1; if (ec.category() == http_error::get_category()) { ec1 = ec; } else if (ec.category() == boost::asio::error::get_system_category() || ec.category() == boost::asio::error::get_netdb_category() || ec.category() == boost::asio::error::get_addrinfo_category() || ec.category() == boost::asio::error::get_misc_category()) { ec1 = http_error::service_unavailable; } else { ec1 = http_error::internal_server_error; } head.err_code = ec1.value(); head.err_msg = ec1.message(); if (!head.content_length.is_initialized()) head.content_length.reset(0); response_.head().connection = http_field::Connection::close; async_write(response_.head(), boost::bind(resp, _1, _2)); }
std::size_t put(ConstBufferSequence const& buffers, error_code& ec) { using boost::asio::buffer_size; using boost::asio::buffer_copy; auto const n = buffer_size(buffers); auto const len = body_.size(); if(n > len) { ec = error::buffer_overflow; return 0; } ec.assign(0, ec.category()); buffer_copy(boost::asio::buffer( body_.data(), n), buffers); body_ = value_type{ body_.data() + n, body_.size() - n}; return n; }
std::size_t put(ConstBufferSequence const& buffers, error_code& ec) { using boost::asio::buffer_size; using boost::asio::buffer_copy; auto const n = buffer_size(buffers); auto const len = body_.size(); try { body_.resize(len + n); } catch(std::exception const&) { ec = error::buffer_overflow; return 0; } ec.assign(0, ec.category()); return buffer_copy(boost::asio::buffer( &body_[0] + len, n), buffers); }
void read_and_print_body( std::ostream& os, SyncReadStream& stream, DynamicBuffer& buffer, error_code& ec) { parser<isRequest, buffer_body> p; read_header(stream, buffer, p, ec); if(ec) return; while(! p.is_done()) { char buf[512]; p.get().body.data = buf; p.get().body.size = sizeof(buf); read(stream, buffer, p, ec); if(ec == error::need_buffer) ec.assign(0, ec.category()); if(ec) return; os.write(buf, sizeof(buf) - p.get().body.size); } }
void init(boost::optional< std::uint64_t> const& length, error_code& ec) { if(length) { if(static_cast<std::size_t>(*length) != *length) { ec = error::buffer_overflow; return; } try { body_.reserve( static_cast<std::size_t>(*length)); } catch(std::exception const&) { ec = error::buffer_overflow; return; } } ec.assign(0, ec.category()); }
QString StaticHelpers::translateLibTorrentError(error_code const& ec) { #if LIBTORRENT_VERSION_NUM >= 10000 if (ec.category() == get_libtorrent_category()) { return translateSessionError(ec); } if (ec.category() == get_bdecode_category()) { return translateBEncodeError(ec); } if (ec.category() == get_gzip_category()) { return translateGzipError(ec); } if (ec.category() == get_i2p_category()) { return translateI2PError(ec); } if (ec.category() == get_socks_category()) { return translateSocksError(ec); } if (ec.category() == get_upnp_category()) { return translateUpnpError(ec); } #endif return QString::fromLocal8Bit(ec.message().c_str()); }
std::vector<lcos::future<T> > wait_all(lcos::future<T> f0 , lcos::future<T> f1 , lcos::future<T> f2, error_code& ec = throws) { typedef std::vector<lcos::future<T> > result_type; lcos::future<result_type> f = when_all( f0 , f1 , f2); if (!f.valid()) { { if (&ec == &hpx::throws) { HPX_THROW_EXCEPTION( uninitialized_value, "lcos::wait_all", "lcos::when_all didn't return a valid future"); } else { ec = make_error_code(static_cast<hpx::error>( uninitialized_value), "lcos::when_all didn't return a valid future", "lcos::wait_all", "D:/Devel\\hpx\\hpx\\lcos\\wait_all.hpp", 435, (ec.category() == hpx::get_lightweight_hpx_category()) ? hpx::lightweight : hpx::plain); } }; return result_type(); } return f.get(ec); }
void operator()(error_code& ec, ConstBufferSequence const& buffer) const { ec.assign(0, ec.category()); std::cout << buffers(buffer); sr.consume(boost::asio::buffer_size(buffer)); }
inline std::size_t hash_value( const error_code & ec ) { return static_cast<std::size_t>(ec.value()) + reinterpret_cast<std::size_t>(&ec.category()); }
inline bool error_category::equivalent( const error_code & code, int condition ) const { return *this == code.category() && code.value() == condition; }
void init(error_code& ec) { ec.assign(0, ec.category()); }
inline bool operator==( const error_condition & condition, const error_code & code ) { return condition.category().equivalent( code, condition.value() ) || code.category().equivalent( code.value(), condition ); }
bool deflate( DeflateStream& zo, boost::asio::mutable_buffer& out, buffers_suffix<ConstBufferSequence>& cb, bool fin, std::size_t& total_in, error_code& ec) { using boost::asio::buffer; BOOST_ASSERT(out.size() >= 6); zlib::z_params zs; zs.avail_in = 0; zs.next_in = nullptr; zs.avail_out = out.size(); zs.next_out = out.data(); for(auto in : beast::detail::buffers_range(cb)) { zs.avail_in = in.size(); if(zs.avail_in == 0) continue; zs.next_in = in.data(); zo.write(zs, zlib::Flush::none, ec); if(ec) { if(ec != zlib::error::need_buffers) return false; BOOST_ASSERT(zs.avail_out == 0); BOOST_ASSERT(zs.total_out == out.size()); ec.assign(0, ec.category()); break; } if(zs.avail_out == 0) { BOOST_ASSERT(zs.total_out == out.size()); break; } BOOST_ASSERT(zs.avail_in == 0); } total_in = zs.total_in; cb.consume(zs.total_in); if(zs.avail_out > 0 && fin) { auto const remain = boost::asio::buffer_size(cb); if(remain == 0) { // Inspired by Mark Adler // https://github.com/madler/zlib/issues/149 // // VFALCO We could do this flush twice depending // on how much space is in the output. zo.write(zs, zlib::Flush::block, ec); BOOST_ASSERT(! ec || ec == zlib::error::need_buffers); if(ec == zlib::error::need_buffers) ec.assign(0, ec.category()); if(ec) return false; if(zs.avail_out >= 6) { zo.write(zs, zlib::Flush::full, ec); BOOST_ASSERT(! ec); // remove flush marker zs.total_out -= 4; out = buffer(out.data(), zs.total_out); return false; } } } ec.assign(0, ec.category()); out = buffer(out.data(), zs.total_out); return true; }
void finish(error_code& ec) { ec.assign(0, ec.category()); }
void init(boost::optional< std::uint64_t> const&, error_code& ec) { ec.assign(0, ec.category()); }
std::vector<HPX_STD_TUPLE<int, lcos::future<T> > > wait_n(std::size_t n, lcos::future<T> f0, error_code& ec = throws) { typedef std::vector<HPX_STD_TUPLE<int, lcos::future<T> > > result_type; lcos::future<result_type> f = when_n( f0); if (!f.valid()) { { if (&ec == &hpx::throws) { HPX_THROW_EXCEPTION( uninitialized_value, "lcos::wait_n", "lcos::when_n didn't return a valid future"); } else { ec = make_error_code(static_cast<hpx::error>( uninitialized_value), "lcos::when_n didn't return a valid future", "lcos::wait_n", "D:/Devel\\hpx\\hpx\\lcos\\wait_n.hpp", 386, (ec.category() == hpx::get_lightweight_hpx_category()) ? hpx::lightweight : hpx::plain); } }; return result_type(); } return f.get(ec); }
bool equivalent(error_code const& error, int ev) const noexcept override { return error.value() == ev && &error.category() == this; }
void print_chunked_body( std::ostream& os, SyncReadStream& stream, DynamicBuffer& buffer, error_code& ec) { // Declare the parser with an empty body since // we plan on capturing the chunks ourselves. parser<isRequest, empty_body> p; // First read the complete header read_header(stream, buffer, p, ec); if(ec) return; // This container will hold the extensions for each chunk chunk_extensions ce; // This string will hold the body of each chunk std::string chunk; // Declare our chunk header callback This is invoked // after each chunk header and also after the last chunk. auto header_cb = [&](std::uint64_t size, // Size of the chunk, or zero for the last chunk string_view extensions, // The raw chunk-extensions string. Already validated. error_code& ev) // We can set this to indicate an error { // Parse the chunk extensions so we can access them easily ce.parse(extensions, ev); if(ev) return; // See if the chunk is too big if(size > (std::numeric_limits<std::size_t>::max)()) { ev = error::body_limit; return; } // Make sure we have enough storage, and // reset the container for the upcoming chunk chunk.reserve(static_cast<std::size_t>(size)); chunk.clear(); }; // Set the callback. The function requires a non-const reference so we // use a local variable, since temporaries can only bind to const refs. p.on_chunk_header(header_cb); // Declare the chunk body callback. This is called one or // more times for each piece of a chunk body. auto body_cb = [&](std::uint64_t remain, // The number of bytes left in this chunk string_view body, // A buffer holding chunk body data error_code& ec) // We can set this to indicate an error { // If this is the last piece of the chunk body, // set the error so that the call to `read` returns // and we can process the chunk. if(remain == body.size()) ec = error::end_of_chunk; // Append this piece to our container chunk.append(body.data(), body.size()); // The return value informs the parser of how much of the body we // consumed. We will indicate that we consumed everything passed in. return body.size(); }; p.on_chunk_body(body_cb); while(! p.is_done()) { // Read as much as we can. When we reach the end of the chunk, the chunk // body callback will make the read return with the end_of_chunk error. read(stream, buffer, p, ec); if(! ec) continue; else if(ec != error::end_of_chunk) return; else ec.assign(0, ec.category()); // We got a whole chunk, print the extensions: for(auto const& extension : ce) { os << "Extension: " << extension.first; if(! extension.second.empty()) os << " = " << extension.second << std::endl; else os << std::endl; } // Now print the chunk body os << "Chunk Body: " << chunk << std::endl; } // Get a reference to the parsed message, this is for convenience auto const& msg = p.get(); // Check each field promised in the "Trailer" header and output it for(auto const& name : token_list{msg[field::trailer]}) { // Find the trailer field auto it = msg.find(name); if(it == msg.end()) { // Oops! They promised the field but failed to deliver it os << "Missing Trailer: " << name << std::endl; continue; } os << it->name() << ": " << it->value() << std::endl; } }
boost::optional<std::pair<const_buffers_type, bool>> get(error_code& ec) { ec.assign(0, ec.category()); return boost::none; }