Repository: ossrs/srs
File: trunk/src/app/srs_app_source.cpp (C++)

Code before:
    
    return err;
}

srs_error_t SrsOriginHub::create_backend_forwarders(bool& status)
{
    srs_error_t err = srs_success;

    // default not configure backend service
    status = false;

    SrsConfDirective* conf = _srs_config->get_forward_backend(req_->vhost);
    if (!conf || conf->arg0().empty()) {
        return err;
    }

    // configure backend service
    status = true;

    // only get first backend url
    std::string backend_url = conf->arg0();

    // get urls on forward backend
    std::vector<std::string> urls;
    if ((err = SrsHttpHooks::on_forward_backend(backend_url, req_, urls)) != srs_success) {
        return srs_error_wrap(err, "get forward backend failed");
    }

    // create forwarders by urls
    std::vector<std::string>::iterator it;
    for (it = urls.begin(); it != urls.end(); ++it) {
        std::string url = *it;

        // create temp Request by url
        SrsRequest* req = new SrsRequest();
        SrsAutoFree(SrsRequest, req);
        srs_parse_rtmp_url(url, req->tcUrl, req->stream);
        srs_discovery_tc_url(req->tcUrl, req->schema, req->host, req->vhost, req->app, req->stream, req->port, req->param);

        // create forwarder
        SrsForwarder* forwarder = new SrsForwarder(this);
        forwarders.push_back(forwarder);

        std::stringstream forward_server;
        forward_server << req->host << ":" << req->port;

        // initialize the forwarder with request.
        if ((err = forwarder->initialize(req, forward_server.str())) != srs_success) {
            return srs_error_wrap(err, "init forwarder");
        }


Review comment (bug):
```
return srs_error_wrap(err, "get forward backend failed, backend=%s", backend_url.c_str());
```

Code after:
        if ((err = forwarder->on_publish()) != srs_success) {
            return srs_error_wrap(err, "start forwarder failed, vhost=%s, app=%s, stream=%s, forward-to=%s",
                req_->vhost.c_str(), req_->app.c_str(), req_->stream.c_str(), forward_server.c_str());
        }
    }
    
    return err;
}

srs_error_t SrsOriginHub::create_backend_forwarders(bool& applied)
{
    srs_error_t err = srs_success;

    // default not configure backend service
    applied = false;

    SrsConfDirective* conf = _srs_config->get_forward_backend(req_->vhost);
    if (!conf || conf->arg0().empty()) {
        return err;
    }

    // configure backend service
    applied = true;

    // only get first backend url
    std::string backend_url = conf->arg0();

    // get urls on forward backend
    std::vector<std::string> urls;
    if ((err = SrsHttpHooks::on_forward_backend(backend_url, req_, urls)) != srs_success) {
        return srs_error_wrap(err, "get forward backend failed, backend=%s", backend_url.c_str());
    }

    // create forwarders by urls
    std::vector<std::string>::iterator it;
    for (it = urls.begin(); it != urls.end(); ++it) {
        std::string url = *it;

        // create temp Request by url
        SrsRequest* req = new SrsRequest();
        SrsAutoFree(SrsRequest, req);
        srs_parse_rtmp_url(url, req->tcUrl, req->stream);
        srs_discovery_tc_url(req->tcUrl, req->schema, req->host, req->vhost, req->app, req->stream, req->port, req->param);

        // create forwarder
        SrsForwarder* forwarder = new SrsForwarder(this);
        forwarders.push_back(forwarder);

        std::stringstream forward_server;
        forward_server << req->host << ":" << req->port;