void init(const Array& options, const String& pid) { mc::McrouterOptions opts; parseOptions(opts, options); mcr::McrouterInstance* router; if (pid.empty()) { m_transientRouter = mcr::McrouterInstance::create(opts.clone()); router = m_transientRouter.get(); } else { router = mcr::McrouterInstance::init(pid.toCppString(), opts); } if (!router) { throw mcr_getException("Unable to initialize MCRouter instance"); } m_client = router->createClient( {onReply,onCancel,nullptr}, this, 0); if (!m_client) { throw mcr_getException("Unable to initilize MCRouterClient instance"); } }
static String HHVM_STATIC_METHOD(MCRouter, getResultName, int64_t res) { auto name = mc_res_to_string((mc_res_t)res); if (!name) { std::string msg = "Unknown mc_res_* value: "; msg += res; throw mcr_getException(msg, mc_op_unknown, (mc_res_t)res); } return name; }
static String HHVM_STATIC_METHOD(MCRouter, getOpName, int64_t op) { auto name = mc_op_to_string((mc_op_t)op); if (!name) { std::string msg = "Unknown mc_op_* value: "; msg += op; throw mcr_getException(msg, (mc_op_t)op); } return name; }
void unserialize(Cell& c) override { if (!m_exception.empty()) { throw mcr_getException(m_exception, m_op, m_replyCode, m_key); } if ((m_result.m_type == KindOfString) && !m_result.m_data.pstr) { // Deferred string init, see below m_result.m_data.pstr = StringData::Make( m_stringResult.c_str(), m_stringResult.size(), CopyString); m_result.m_data.pstr->setRefCount(1); m_stringResult.clear(); } cellDup(m_result, c); }
/* Unserialize happens in the request thread where we can allocate smart pointers * Use this opportunity to marshal the saved data from persistent data structures * into per-request data. */ void unserialize(Cell& c) override { if (!m_exception.empty()) { throw mcr_getException(m_exception, m_op, m_replyCode, m_key); } if ((m_result.m_type == KindOfString) && !m_result.m_data.pstr) { // Deferred string init, see below m_result.m_data.pstr = StringData::Make( m_stringResult.c_str(), m_stringResult.size(), CopyString); m_stringResult.clear(); } else if ((m_result.m_type == KindOfArray) && !m_result.m_data.parr) { // Deferred string value and cas, see below Array ret = Array::Create(); ret.set(s_value, String(m_stringResult.c_str(), m_stringResult.size(), CopyString)); ret.set(s_cas, (int64_t)m_cas); ret.set(s_flags, (int64_t)m_flags); m_result.m_data.parr = ret.detach(); m_stringResult.clear(); } cellDup(m_result, c); }