Add on started callback to AsioSession

The PHP code using Awaitable interface will need this.
Esse commit está contido em:
Alex Suhan
2013-03-19 14:24:42 -07:00
commit de Sara Golemon
commit 1742a79189
10 arquivos alterados com 129 adições e 3 exclusões
+17
Ver Arquivo
@@ -145,6 +145,23 @@ DefineFunction(
),
));
DefineFunction(
array(
'name' => "asio_set_on_started_callback",
'desc' => "Set callback to be called when a continuation is started",
'flags' => HasDocComment,
'return' => array(
'type' => null,
),
'args' => array(
array(
'name' => "on_started_cb",
'type' => Object,
'desc' => "A Closure to be called when wait handle is started",
),
),
));
///////////////////////////////////////////////////////////////////////////////
// Classes
+23 -1
Ver Arquivo
@@ -32,7 +32,8 @@ void AsioSession::Init() {
s_current.set(new AsioSession());
}
AsioSession::AsioSession() : m_contexts(), m_onFailedCallback(nullptr) {
AsioSession::AsioSession()
: m_contexts(), m_onFailedCallback(nullptr), m_onStartedCallback(nullptr) {
}
void AsioSession::enterContext() {
@@ -89,5 +90,26 @@ void AsioSession::onFailed(CObjRef exception) {
}
}
void AsioSession::setOnStartedCallback(ObjectData* on_started_callback) {
if (on_started_callback) {
on_started_callback->incRefCount();
}
if (m_onStartedCallback) {
decRefObj(m_onStartedCallback);
}
m_onStartedCallback = on_started_callback;
}
void AsioSession::onStarted(CObjRef wait_handle) {
assert(m_onStartedCallback);
try {
f_call_user_func_array(m_onStartedCallback, Array::Create(wait_handle));
} catch (Object callback_exception) {
raise_warning("[asio] Ignoring exception thrown by onStarted callback");
}
}
///////////////////////////////////////////////////////////////////////////////
}
+6
Ver Arquivo
@@ -68,6 +68,11 @@ class AsioSession {
void setOnFailedCallback(ObjectData* on_failed_callback);
void onFailed(CObjRef exception);
// callback: on started
void setOnStartedCallback(ObjectData* on_started_callback);
void onStarted(CObjRef wait_handle);
bool hasOnStartedCallback() { return m_onStartedCallback; }
private:
static DECLARE_THREAD_LOCAL_PROXY(AsioSession, false, s_current);
@@ -75,6 +80,7 @@ class AsioSession {
smart::vector<AsioContext*> m_contexts;
ObjectData* m_onFailedCallback;
ObjectData* m_onStartedCallback;
};
///////////////////////////////////////////////////////////////////////////////
@@ -77,8 +77,11 @@ Object c_ContinuationWaitHandle::ti_start(const char* cls, CObjRef continuation,
return cont->m_waitHandle;
}
c_ContinuationWaitHandle* wh = NEWOBJ(c_ContinuationWaitHandle)();
p_ContinuationWaitHandle wh = NEWOBJ(c_ContinuationWaitHandle)();
wh->start(cont, static_cast<uint32_t>(prio), depth + 1);
if (UNLIKELY(session->hasOnStartedCallback())) {
session->onStarted(wh);
}
return wh;
}
+10
Ver Arquivo
@@ -73,5 +73,15 @@ void f_asio_set_on_failed_callback(CObjRef on_failed_cb) {
AsioSession::Get()->setOnFailedCallback(on_failed_cb.get());
}
void f_asio_set_on_started_callback(CObjRef on_started_cb) {
if (!on_started_cb.isNull() && !on_started_cb.instanceof(c_Closure::s_cls)) {
Object e(SystemLib::AllocInvalidArgumentExceptionObject(
"Unable to set asio on started callback: on_started_cb not a closure"));
throw e;
}
AsioSession::Get()->setOnStartedCallback(on_started_cb.get());
}
///////////////////////////////////////////////////////////////////////////////
}
+50
Ver Arquivo
@@ -290,6 +290,56 @@ TypedValue* fg_asio_set_on_failed_callback(HPHP::VM::ActRec *ar) {
/*
void HPHP::f_asio_set_on_started_callback(HPHP::Object const&)
_ZN4HPHP30f_asio_set_on_started_callbackERKNS_6ObjectE
on_started_cb => rdi
*/
void fh_asio_set_on_started_callback(Value* on_started_cb) asm("_ZN4HPHP30f_asio_set_on_started_callbackERKNS_6ObjectE");
TypedValue * fg1_asio_set_on_started_callback(TypedValue* rv, HPHP::VM::ActRec* ar, int64_t count) __attribute__((noinline,cold));
TypedValue * fg1_asio_set_on_started_callback(TypedValue* rv, HPHP::VM::ActRec* ar, int64_t count) {
TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
rv->m_data.num = 0LL;
rv->m_type = KindOfNull;
tvCastToObjectInPlace(args-0);
fh_asio_set_on_started_callback((Value*)(args-0));
return rv;
}
TypedValue* fg_asio_set_on_started_callback(HPHP::VM::ActRec *ar) {
TypedValue rv;
int64_t count = ar->numArgs();
TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
if (count == 1LL) {
if ((args-0)->m_type == KindOfObject) {
rv.m_data.num = 0LL;
rv.m_type = KindOfNull;
fh_asio_set_on_started_callback((Value*)(args-0));
frame_free_locals_no_this_inl(ar, 1);
memcpy(&ar->m_r, &rv, sizeof(TypedValue));
return &ar->m_r;
} else {
fg1_asio_set_on_started_callback(&rv, ar, count);
frame_free_locals_no_this_inl(ar, 1);
memcpy(&ar->m_r, &rv, sizeof(TypedValue));
return &ar->m_r;
}
} else {
throw_wrong_arguments_nr("asio_set_on_started_callback", count, 1, 1, 1);
}
rv.m_data.num = 0LL;
rv.m_type = KindOfNull;
frame_free_locals_no_this_inl(ar, 1);
memcpy(&ar->m_r, &rv, sizeof(TypedValue));
return &ar->m_r;
return &ar->m_r;
}
} // !HPHP
+9
Ver Arquivo
@@ -81,6 +81,15 @@ on_failed_cb => rdi
void fh_asio_set_on_failed_callback(Value* on_failed_cb) asm("_ZN4HPHP29f_asio_set_on_failed_callbackERKNS_6ObjectE");
/*
void HPHP::f_asio_set_on_started_callback(HPHP::Object const&)
_ZN4HPHP30f_asio_set_on_started_callbackERKNS_6ObjectE
on_started_cb => rdi
*/
void fh_asio_set_on_started_callback(Value* on_started_cb) asm("_ZN4HPHP30f_asio_set_on_started_callbackERKNS_6ObjectE");
} // !HPHP
+1
Ver Arquivo
@@ -31,6 +31,7 @@ Object f_asio_get_running_in_context(int ctx_idx);
Object f_asio_get_running();
Object f_asio_get_current();
void f_asio_set_on_failed_callback(CObjRef on_failed_cb);
void f_asio_set_on_started_callback(CObjRef on_failed_cb);
///////////////////////////////////////////////////////////////////////////////
// class WaitHandle
+3 -1
Ver Arquivo
@@ -151,6 +151,7 @@ TypedValue* fg_asio_get_running_in_context(VM::ActRec *ar);
TypedValue* fg_asio_get_running(VM::ActRec *ar);
TypedValue* fg_asio_get_current(VM::ActRec *ar);
TypedValue* fg_asio_set_on_failed_callback(VM::ActRec *ar);
TypedValue* fg_asio_set_on_started_callback(VM::ActRec *ar);
TypedValue* fg_bcscale(VM::ActRec *ar);
TypedValue* fg_bcadd(VM::ActRec *ar);
TypedValue* fg_bcsub(VM::ActRec *ar);
@@ -3022,7 +3023,7 @@ TypedValue* tg_9XMLWriter_endDTD(VM::ActRec *ar);
TypedValue* tg_9XMLWriter_flush(VM::ActRec *ar);
TypedValue* tg_9XMLWriter_outputMemory(VM::ActRec *ar);
const long long hhbc_ext_funcs_count = 2208;
const long long hhbc_ext_funcs_count = 2209;
const HhbcExtFuncInfo hhbc_ext_funcs[] = {
{ "apache_note", fg_apache_note, (void *)&fh_apache_note },
{ "apache_request_headers", fg_apache_request_headers, (void *)&fh_apache_request_headers },
@@ -3152,6 +3153,7 @@ const HhbcExtFuncInfo hhbc_ext_funcs[] = {
{ "asio_get_running", fg_asio_get_running, (void *)&fh_asio_get_running },
{ "asio_get_current", fg_asio_get_current, (void *)&fh_asio_get_current },
{ "asio_set_on_failed_callback", fg_asio_set_on_failed_callback, (void *)&fh_asio_set_on_failed_callback },
{ "asio_set_on_started_callback", fg_asio_set_on_started_callback, (void *)&fh_asio_set_on_started_callback },
{ "bcscale", fg_bcscale, (void *)&fh_bcscale },
{ "bcadd", fg_bcadd, (void *)&fh_bcadd },
{ "bcsub", fg_bcsub, (void *)&fh_bcsub },
+6
Ver Arquivo
@@ -7524,6 +7524,12 @@ const char *g_class_map[] = {
NULL,
NULL,
NULL,
(const char *)0x10006040, "asio_set_on_started_callback", "", (const char*)0, (const char*)0,
"/**\n * ( excerpt from\n * http://php.net/manual/en/function.asio-set-on-started-callback.php )\n *\n * Set callback to be called when a continuation is started\n *\n * @on_started_cb\n * object A Closure to be called when wait handle is started\n */",
(const char *)-1, (const char *)0x2000, "on_started_cb", "", (const char *)0x40, "", "", NULL,
NULL,
NULL,
NULL,
(const char *)0x10006040, "iconv_mime_encode", "", (const char*)0, (const char*)0,
"/**\n * ( excerpt from http://php.net/manual/en/function.iconv-mime-encode.php )\n *\n * Composes and returns a string that represents a valid MIME header\n * field, which looks like the following: Subject:\n * =\?ISO-8859-1\?Q\?Pr=FCfung_f=FCr\?= Entwerfen von einer MIME kopfzeile In\n * the above example, \"Subject\" is the field name and the portion that\n * begins with \"=\?ISO-8859-1\?...\" is the field value.\n *\n * @field_name string The field name.\n * @field_value\n * string The field value.\n * @preferences\n * mixed You can control the behaviour of iconv_mime_encode()\n * by specifying an associative array that contains\n * configuration items to the optional third parameter\n * preferences. The items supported by\n * iconv_mime_encode() are listed below. Note that item\n * names are treated case-sensitive. Configuration\n * items supported by iconv_mime_encode() Item Type\n * Description Default value Example scheme string\n * Specifies the method to encode a field value by. The\n * value of this item may be either \"B\" or \"Q\", where\n * \"B\" stands for base64 encoding scheme and \"Q\" stands\n * for quoted-printable encoding scheme. B B\n * input-charset string Specifies the character set in\n * which the first parameter field_name and the second\n * parameter field_value are presented. If not given,\n * iconv_mime_encode() assumes those parameters are\n * presented to it in the iconv.internal_encoding ini\n * setting. iconv.internal_encoding ISO-8859-1\n * output-charset string Specifies the character set to\n * use to compose the MIME header. If not given, the\n * same value as input-charset will be used.\n * iconv.internal_encoding UTF-8 line-length integer\n * Specifies the maximum length of the header lines.\n * The resulting header is \"folded\" to a set of\n * multiple lines in case the resulting header field\n * would be longer than the value of this parameter,\n * according to \273 RFC2822 - Internet Message Format. If\n * not given, the length will be limited to 76\n * characters. 76 996 line-break-chars string Specifies\n * the sequence of characters to append to each line as\n * an end-of-line sign when \"folding\" is performed on a\n * long header field. If not given, this defaults to\n * \"\\r\\n\" (CR LF). Note that this parameter is always\n * treated as an ASCII string regardless of the value\n * of input-charset. \\r\\n \\n\n *\n * @return mixed Returns an encoded MIME field on success, or FALSE\n * if an error occurs during the encoding.\n */",
(const char *)0xffffffff, (const char *)0x2000, "field_name", "", (const char *)0x14, "", "", NULL,