コード例 #1
0
ファイル: reactor.cpp プロジェクト: bacek/cocaine-core
void
reactor_t::on_message(const std::shared_ptr<channel<io::socket<tcp>>>& channel_,
                      const message_t& message)
{
    slot_map_t::const_iterator slot = m_slots.find(message.id());

    if(slot == m_slots.end()) {
        COCAINE_LOG_WARNING(m_log, "dropping an unknown type %d message", message.id());
        return;
    }

    std::string response;

    try {
        response = (*slot->second)(message.args());
    } catch(const std::exception& e) {
        COCAINE_LOG_ERROR(
            m_log,
            "unable to process type %d message - %s",
            message.id(),
            e.what()
        );

        return;
    }

    if(!response.empty()) {
        channel_->wr->stream()->write(response.data(), response.size());
    }
}