Resource get_context_resource(Object obj) { auto res = obj->o_realProp(s_context, ObjectData::RealPropUnchecked, s_zmqcontext.get()); if (!res || !res->isResource()) { return null_resource; } return res->toResource(); }
bool Object::equal(CObjRef v2) const { if (m_px == v2.get()) return true; if (!m_px || !v2.get()) return false; if (isResource() || v2.isResource()) return false; return (v2.get()->o_isClass(m_px->o_getClassName()) && toArray().equal(v2.toArray())); }
bool Object::equal(CObjRef v2) const { if (m_px == v2.get()) { check_collection_compare(m_px); return true; } if (!m_px || !v2.get()) { return false; } check_collection_compare(m_px, v2.get()); if (isResource() || v2.isResource()) { return false; } return (v2.get()->o_isClass(m_px->o_getClassName()) && toArray().equal(v2.toArray())); }
bool Object::equal(CObjRef v2) const { if (m_px == v2.get()) { return true; } if (!m_px || !v2.get()) { return false; } if (isResource() || v2.isResource()) { return false; } if (v2.get()->getVMClass() != m_px->getVMClass()) { return false; } if (m_px->isCollection()) { return collectionEquals(m_px, v2.get()); } return toArray().equal(v2.toArray()); }
static NumberFormatter *Get(Object obj) { if (obj.isNull()) { raise_error("NULL object passed"); return nullptr; } auto res = obj->o_get(s_resdata, false, s_NumberFormatter.get()); if (!res.isResource()) { return nullptr; } auto ret = res.toResource().getTyped<NumberFormatter>(false, false); if (!ret) { return nullptr; } if (!ret->formatter()) { ret->setError(U_ILLEGAL_ARGUMENT_ERROR, "Found unconstructed NumberFormatter"); return nullptr; } return ret; }
req::ptr<File> open(const String& filename, const String& /*mode*/, int /*options*/, const req::ptr<StreamContext>& /*context*/) override { static const char cz[] = "phar://"; if (strncmp(filename.data(), cz, sizeof(cz) - 1)) { return nullptr; } static Func* f = SystemLib::s_PharClass->lookupMethod(s_openPhar.get()); auto ret = Variant::attach( g_context->invokeFunc(f, make_packed_array(filename), nullptr, SystemLib::s_PharClass) ); if (!ret.isResource()) { return nullptr; } return dyn_cast_or_null<File>(ret.asResRef()); }
Variant sockopen_impl(const HostURL &hosturl, VRefParam errnum, VRefParam errstr, double timeout, bool persistent) { errnum = 0; errstr = empty_string(); std::string key; if (persistent) { key = hosturl.getHostURL() + ":" + folly::to<std::string>(hosturl.getPort()); auto sockItr = s_sockets.find(key); if (sockItr != s_sockets.end()) { auto sock = makeSmartPtr<Socket>(sockItr->second); if (sock->getError() == 0 && sock->checkLiveness()) { return Variant(sock); } // socket had an error earlier, we need to close it, remove it from // persistent storage, and create a new one (in that order) sock->close(); s_sockets.erase(sockItr); } } if (timeout < 0) { timeout = ThreadInfo::s_threadInfo.getNoCheck()-> m_reqInjectionData.getSocketDefaultTimeout(); } auto socket = new_socket_connect(hosturl, timeout, errnum, errstr); if (!socket.isResource()) { return false; } if (persistent) { assert(!key.empty()); s_sockets[key] = cast<Socket>(socket)->getData(); assert(s_sockets[key]); } return socket; }
Variant sockopen_impl(const HostURL &hosturl, VRefParam errnum, VRefParam errstr, double timeout, bool persistent) { errnum = 0; errstr = empty_string(); std::string key; if (persistent) { key = hosturl.getHostURL() + ":" + folly::to<std::string>(hosturl.getPort()); Socket *sock = dynamic_cast<Socket*>(g_persistentResources->get("socket", key.c_str())); if (sock) { if (sock->getError() == 0 && sock->checkLiveness()) { return Resource(sock); } // socket had an error earlier, we need to close it, remove it from // persistent storage, and create a new one (in that order) sock->close(); g_persistentResources->remove("socket", key.c_str()); } } if (timeout < 0) { timeout = ThreadInfo::s_threadInfo.getNoCheck()-> m_reqInjectionData.getSocketDefaultTimeout(); } auto socket = new_socket_connect(hosturl, timeout, errnum, errstr); if (!socket.isResource()) { return false; } Resource ret = socket.toResource(); if (persistent) { assert(!key.empty()); g_persistentResources->set("socket", key.c_str(), ret.getTyped<Socket>()); } return ret; }
Variant Object::toKey() const { return m_px ? (isResource() ? m_px->o_toInt64() : m_px->t___tostring()) : String(); }