本文整理汇总了C++中AsioSession类的典型用法代码示例。如果您正苦于以下问题:C++ AsioSession类的具体用法?C++ AsioSession怎么用?C++ AsioSession使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AsioSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assert
void c_ContinuationWaitHandle::Create(c_Continuation* continuation) {
assert(continuation);
assert(continuation->m_waitHandle.isNull());
AsioSession* session = AsioSession::Get();
uint16_t depth = session->getCurrentWaitHandleDepth();
if (UNLIKELY(depth >= MAX_DEPTH)) {
Object e(SystemLib::AllocInvalidOperationExceptionObject(
"Asio stack overflow"));
throw e;
}
if (UNLIKELY(continuation->started())) {
Object e(SystemLib::AllocInvalidOperationExceptionObject(
continuation->running()
? "Encountered an attempt to start currently running continuation"
: "Encountered an attempt to start tainted continuation"));
throw e;
}
continuation->m_waitHandle = NEWOBJ(c_ContinuationWaitHandle)();
continuation->m_waitHandle->initialize(continuation, depth + 1);
// needs to be called after continuation->m_waitHandle is set
if (UNLIKELY(session->hasOnContinuationCreateCallback())) {
session->onContinuationCreate(continuation->m_waitHandle.get());
}
}
示例2: e
Object c_GenMapWaitHandle::ti_create(const Variant& dependencies) {
if (UNLIKELY(!dependencies.isObject() ||
dependencies.getObjectData()->getCollectionType() !=
Collection::MapType)) {
Object e(SystemLib::AllocInvalidArgumentExceptionObject(
"Expected dependencies to be an instance of Map"));
throw e;
}
assert(dependencies.getObjectData()->instanceof(c_Map::classof()));
auto deps = p_Map::attach(c_Map::Clone(dependencies.getObjectData()));
for (ssize_t iter_pos = deps->iter_begin();
deps->iter_valid(iter_pos);
iter_pos = deps->iter_next(iter_pos)) {
auto* current = tvAssertCell(deps->iter_value(iter_pos));
if (UNLIKELY(!c_WaitHandle::fromCell(current))) {
Object e(SystemLib::AllocInvalidArgumentExceptionObject(
"Expected dependencies to be a map of WaitHandle instances"));
throw e;
}
}
Object exception;
for (ssize_t iter_pos = deps->iter_begin();
deps->iter_valid(iter_pos);
iter_pos = deps->iter_next(iter_pos)) {
auto* current = tvAssertCell(deps->iter_value(iter_pos));
assert(current->m_type == KindOfObject);
assert(current->m_data.pobj->instanceof(c_WaitHandle::classof()));
auto child = static_cast<c_WaitHandle*>(current->m_data.pobj);
if (child->isSucceeded()) {
auto k = deps->iter_key(iter_pos);
deps->set(k.asCell(), &child->getResult());
} else if (child->isFailed()) {
putException(exception, child->getException());
} else {
assert(child->instanceof(c_WaitableWaitHandle::classof()));
auto child_wh = static_cast<c_WaitableWaitHandle*>(child);
p_GenMapWaitHandle my_wh = NEWOBJ(c_GenMapWaitHandle)();
my_wh->initialize(exception, deps.get(), iter_pos, child_wh);
AsioSession* session = AsioSession::Get();
if (UNLIKELY(session->hasOnGenMapCreateCallback())) {
session->onGenMapCreate(my_wh.get(), dependencies);
}
return my_wh;
}
}
if (exception.isNull()) {
return Object::attach(c_StaticWaitHandle::CreateSucceeded(
make_tv<KindOfObject>(deps.detach())));
} else {
return Object::attach(c_StaticWaitHandle::CreateFailed(exception.detach()));
}
}
示例3: markAsSucceeded
void c_AsyncFunctionWaitHandle::markAsSucceeded() {
AsioSession* session = AsioSession::Get();
if (UNLIKELY(session->hasOnAsyncFunctionSuccessCallback())) {
session->onAsyncFunctionSuccess(this, cellAsCVarRef(m_resultOrException));
}
done();
}
示例4: markAsFailed
void c_AsyncFunctionWaitHandle::markAsFailed(const Object& exception) {
AsioSession* session = AsioSession::Get();
if (UNLIKELY(session->hasOnAsyncFunctionFailCallback())) {
session->onAsyncFunctionFail(this, exception);
}
setState(STATE_FAILED);
tvWriteObject(exception.get(), &m_resultOrException);
done();
}
示例5: e
Object c_GenVectorWaitHandle::ti_create(const Variant& dependencies) {
if (UNLIKELY(!dependencies.isObject() ||
dependencies.getObjectData()->getCollectionType() !=
Collection::VectorType)) {
Object e(SystemLib::AllocInvalidArgumentExceptionObject(
"Expected dependencies to be an instance of Vector"));
throw e;
}
assert(dependencies.getObjectData()->instanceof(c_Vector::classof()));
auto deps = SmartObject<c_Vector>::attach(
c_Vector::Clone(dependencies.getObjectData()));
for (int64_t iter_pos = 0; iter_pos < deps->size(); ++iter_pos) {
Cell* current = deps->at(iter_pos);
if (UNLIKELY(!c_WaitHandle::fromCell(current))) {
Object e(SystemLib::AllocInvalidArgumentExceptionObject(
"Expected dependencies to be a vector of WaitHandle instances"));
throw e;
}
}
Object exception;
for (int64_t iter_pos = 0; iter_pos < deps->size(); ++iter_pos) {
auto current = tvAssertCell(deps->at(iter_pos));
assert(current->m_type == KindOfObject);
assert(current->m_data.pobj->instanceof(c_WaitHandle::classof()));
auto child = static_cast<c_WaitHandle*>(current->m_data.pobj);
if (child->isSucceeded()) {
auto result = child->getResult();
deps->set(iter_pos, &result);
} else if (child->isFailed()) {
putException(exception, child->getException());
} else {
assert(child->instanceof(c_WaitableWaitHandle::classof()));
auto child_wh = static_cast<c_WaitableWaitHandle*>(child);
SmartObject<c_GenVectorWaitHandle> my_wh(newobj<c_GenVectorWaitHandle>());
my_wh->initialize(exception, deps.get(), iter_pos, child_wh);
AsioSession* session = AsioSession::Get();
if (UNLIKELY(session->hasOnGenVectorCreateCallback())) {
session->onGenVectorCreate(my_wh.get(), dependencies);
}
return my_wh;
}
}
if (exception.isNull()) {
return Object::attach(c_StaticWaitHandle::CreateSucceeded(
make_tv<KindOfObject>(deps.detach())));
} else {
return Object::attach(c_StaticWaitHandle::CreateFailed(exception.detach()));
}
}
示例6: markAsFailed
void c_ContinuationWaitHandle::markAsFailed(CObjRef exception) {
AsioSession* session = AsioSession::Get();
session->onFailed(exception);
if (UNLIKELY(session->hasOnContinuationFailCallback())) {
session->onContinuationFail(this, exception);
}
setException(exception.get());
m_continuation = nullptr;
m_child = nullptr;
}
示例7: markAsSucceeded
void c_ContinuationWaitHandle::markAsSucceeded(const TypedValue* result) {
AsioSession* session = AsioSession::Get();
if (UNLIKELY(session->hasOnContinuationSuccessCallback())) {
session->onContinuationSuccess(this, tvAsCVarRef(result));
}
setResult(result);
// free m_continuation / m_child later, result may be stored there
m_continuation = nullptr;
m_child = nullptr;
}
示例8: fail
void c_AsyncFunctionWaitHandle::fail(ObjectData* exception) {
AsioSession* session = AsioSession::Get();
if (UNLIKELY(session->hasOnAsyncFunctionFailCallback())) {
session->onAsyncFunctionFail(this, exception);
}
auto const parentChain = getFirstParent();
setState(STATE_FAILED);
tvWriteObject(exception, &m_resultOrException);
UnblockChain(parentChain);
decRefObj(this);
}
示例9: fail
void c_AsyncGeneratorWaitHandle::fail(ObjectData* exception) {
AsioSession* session = AsioSession::Get();
if (UNLIKELY(session->hasOnResumableFailCallback())) {
session->onResumableFail(this, exception);
}
auto parentChain = getParentChain();
setState(STATE_FAILED);
cellCopy(make_tv<KindOfObject>(exception), m_resultOrException);
parentChain.unblock();
decRefObj(m_generator);
decRefObj(this);
}
示例10: e
Object c_GenVectorWaitHandle::ti_create(CVarRef dependencies) {
if (UNLIKELY(!dependencies.instanceof(c_Vector::s_cls))) {
Object e(SystemLib::AllocInvalidArgumentExceptionObject(
"Expected dependencies to be an instance of Vector"));
throw e;
}
assert(dynamic_cast<c_Vector*>(dependencies.getObjectData()));
p_Vector deps = static_cast<c_Vector*>(dependencies.getObjectData())->clone();
for (int64_t iter_pos = 0; iter_pos < deps->size(); ++iter_pos) {
Cell* current = deps->at(iter_pos);
if (UNLIKELY(!c_WaitHandle::fromCell(current))) {
Object e(SystemLib::AllocInvalidArgumentExceptionObject(
"Expected dependencies to be a vector of WaitHandle instances"));
throw e;
}
}
Object exception;
for (int64_t iter_pos = 0; iter_pos < deps->size(); ++iter_pos) {
Cell* current = tvAssertCell(deps->at(iter_pos));
assert(current->m_type == KindOfObject);
assert(dynamic_cast<c_WaitHandle*>(current->m_data.pobj));
auto child = static_cast<c_WaitHandle*>(current->m_data.pobj);
if (child->isSucceeded()) {
cellSet(child->getResult(), *current);
} else if (child->isFailed()) {
putException(exception, child->getException());
} else {
assert(dynamic_cast<c_WaitableWaitHandle*>(child));
auto child_wh = static_cast<c_WaitableWaitHandle*>(child);
p_GenVectorWaitHandle my_wh = NEWOBJ(c_GenVectorWaitHandle)();
my_wh->initialize(exception, deps.get(), iter_pos, child_wh);
AsioSession* session = AsioSession::Get();
if (UNLIKELY(session->hasOnGenVectorCreateCallback())) {
session->onGenVectorCreate(my_wh.get(), dependencies);
}
return my_wh;
}
}
if (exception.isNull()) {
return c_StaticResultWaitHandle::Create(make_tv<KindOfObject>(deps.get()));
} else {
return c_StaticExceptionWaitHandle::Create(exception.get());
}
}
示例11: assert
/**
* Mark the wait handle as failed due to PHP exception.
*
* - consumes reference of the given Exception object
*/
void c_AsyncFunctionWaitHandle::fail(ObjectData* exception) {
assert(isRunning());
assert(exception);
assert(exception->instanceof(SystemLib::s_ExceptionClass));
AsioSession* session = AsioSession::Get();
if (UNLIKELY(session->hasOnResumableFailCallback())) {
session->onResumableFail(this, exception);
}
auto const parentChain = getFirstParent();
setState(STATE_FAILED);
cellCopy(make_tv<KindOfObject>(exception), m_resultOrException);
UnblockChain(parentChain);
decRefObj(this);
}
示例12: tvSet
Object c_SetResultToRefWaitHandle::ti_create(CObjRef wait_handle, VRefParam ref) {
TypedValue* var_or_cell = ref->asTypedValue();
if (wait_handle.isNull()) {
tvSet(make_tv<KindOfNull>(), *var_or_cell);
return wait_handle;
}
if (!wait_handle.get()->instanceof(c_WaitHandle::classof())) {
Object e(SystemLib::AllocInvalidArgumentExceptionObject(
"Expected wait_handle to be an instance of WaitHandle or null"));
throw e;
}
c_WaitHandle* wh = static_cast<c_WaitHandle*>(wait_handle.get());
// succeeded? set result to ref and give back succeeded wait handle
if (wh->isSucceeded()) {
tvSet(wh->getResult(), *var_or_cell);
return wh;
}
// failed? reset ref and give back failed wait handle
if (wh->isFailed()) {
tvSet(make_tv<KindOfNull>(), *var_or_cell);
return wh;
}
// it's still running so it must be WaitableWaitHandle
c_WaitableWaitHandle* child_wh = static_cast<c_WaitableWaitHandle*>(wh);
// make sure the reference is properly boxed so that we can store cell pointer
if (UNLIKELY(var_or_cell->m_type != KindOfRef)) {
tvBox(var_or_cell);
}
p_SetResultToRefWaitHandle my_wh = NEWOBJ(c_SetResultToRefWaitHandle)();
my_wh->initialize(child_wh, var_or_cell->m_data.pref);
AsioSession* session = AsioSession::Get();
if (UNLIKELY(session->hasOnSetResultToRefCreateCallback())) {
session->onSetResultToRefCreate(my_wh.get(), child_wh);
}
return my_wh;
}
示例13: assert
/**
* Mark the wait handle as failed due to PHP exception.
*
* - consumes reference of the given Exception object
*/
void c_AsyncFunctionWaitHandle::fail(ObjectData* exception) {
assert(isRunning());
assert(exception);
assert(exception->instanceof(SystemLib::s_ThrowableClass));
AsioSession* session = AsioSession::Get();
if (UNLIKELY(session->hasOnResumableFail())) {
try {
session->onResumableFail(this, Object{exception});
} catch (...) {
// TODO(#4557954) Make unwinder able to deal with new exceptions better.
handle_destructor_exception("AsyncFunctionWaitHandle fail callback");
}
}
auto parentChain = getParentChain();
setState(STATE_FAILED);
cellCopy(make_tv<KindOfObject>(exception), m_resultOrException);
parentChain.unblock();
}
示例14: assert
void c_AsyncFunctionWaitHandle::Create(c_Continuation* continuation) {
assert(continuation);
assert(continuation->m_label > 0);
assert(continuation->m_waitHandle.isNull());
AsioSession* session = AsioSession::Get();
uint16_t depth = session->getCurrentWaitHandleDepth();
if (UNLIKELY(depth >= MAX_DEPTH)) {
Object e(SystemLib::AllocInvalidOperationExceptionObject(
"Asio stack overflow"));
throw e;
}
Cell* value = tvAssertCell(continuation->m_value.asTypedValue());
assert(dynamic_cast<c_WaitableWaitHandle*>(c_WaitHandle::fromCell(value)));
auto child = static_cast<c_WaitableWaitHandle*>(value->m_data.pobj);
assert(!child->isFinished());
// import child into the current context, detect cross-context cycles
if (session->isInContext()) {
child->enterContext(session->getCurrentContextIdx());
}
continuation->m_waitHandle = NEWOBJ(c_AsyncFunctionWaitHandle)();
continuation->m_waitHandle->initialize(continuation, child, depth + 1);
// needs to be called after continuation->m_waitHandle is set
if (UNLIKELY(session->hasOnAsyncFunctionCreateCallback())) {
session->onAsyncFunctionCreate(continuation->m_waitHandle.get());
}
}
示例15: vmfp
// throws on context depth level overflows and cross-context cycles
void c_WaitableWaitHandle::join() {
EagerVMRegAnchor _;
auto const savedFP = vmfp();
assert(!isFinished());
AsioSession* session = AsioSession::Get();
if (UNLIKELY(session->hasOnJoinCallback())) {
session->onJoin(this);
}
// enter new asio context and set up guard that will exit once we are done
session->enterContext(savedFP);
auto exit_guard = folly::makeGuard([&] { session->exitContext(); });
// import this wait handle to the newly created context
// throws if cross-context cycle found
enterContext(session->getCurrentContextIdx());
// run queues until we are finished
session->getCurrentContext()->runUntil(this);
assert(isFinished());
}