Beispiel #1
0
    void
    operator()(const ioremap::swarm::url_fetcher::response& reply,
               const std::string& data,
               const boost::system::error_code& error) {
        const int code = reply.code();
        const bool success = (!error && (code < 400 || code >= 600));

        if (!success) {
            if (code == 0) {
                // Socket-only error, no valid http response
                const std::string &message = cocaine::format("Unable to download %s, error %s",
                                                             reply.request().url().to_string(),
                                                             error.message());
                //deferred.abort(error.value(), message);
                deferred.abort(asio::error::operation_aborted, message);
                return;
            }
        }
        callback(deferred, code, data);
    }
Beispiel #2
0
    void
    on_spool(const std::error_code& ec, const std::string& what) {
        if (ec) {
            const auto reason = what.empty() ? ec.message() : what;

            COCAINE_LOG_ERROR(log, "unable to spool app - [%d] %s", ec.value(), reason);

            loop->dispatch(std::bind(&app_state_t::cancel, shared_from_this(), reason));

            // Attempt to finish node service's request.
            try {
                deferred.abort(ec, reason);
            } catch (const std::exception&) {
                // Ignore if the client has been disconnected.
            }
        } else {
            // Dispatch the completion handler to be sure it will be called in a I/O thread to
            // avoid possible deadlocks (which ones?).
            loop->dispatch(std::bind(&app_state_t::publish, shared_from_this()));
        }
    }