本文整理汇总了C++中TSRMLS_FETCH_FROM_CTX函数的典型用法代码示例。如果您正苦于以下问题:C++ TSRMLS_FETCH_FROM_CTX函数的具体用法?C++ TSRMLS_FETCH_FROM_CTX怎么用?C++ TSRMLS_FETCH_FROM_CTX使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TSRMLS_FETCH_FROM_CTX函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: swoole_set_object
void swoole_set_object(zval *object, void *ptr)
{
#if PHP_MAJOR_VERSION < 7
TSRMLS_FETCH_FROM_CTX(sw_thread_ctx ? sw_thread_ctx : NULL);
zend_object_handle handle = Z_OBJ_HANDLE_P(object);
#else
int handle = (int) Z_OBJ_HANDLE(*object);
#endif
assert(handle < SWOOLE_OBJECT_MAX);
if (handle >= swoole_objects.size)
{
uint32_t old_size = swoole_objects.size;
uint32_t new_size = swoole_get_new_size(old_size, handle TSRMLS_CC);
void *old_ptr = swoole_objects.array;
void *new_ptr = NULL;
new_ptr = realloc(old_ptr, sizeof(void*) * new_size);
if (!new_ptr)
{
swoole_php_fatal_error(E_ERROR, "malloc(%d) failed.", (int )(new_size * sizeof(void *)));
return;
}
bzero(new_ptr + (old_size * sizeof(void*)), (new_size - old_size) * sizeof(void*));
swoole_objects.array = new_ptr;
swoole_objects.size = new_size;
}
swoole_objects.array[handle] = ptr;
}
示例2: aerospike_get_registered_udf_module_code
/*
******************************************************************************************************
Get the code of registered UDF module.
*
* @param aerospike_obj_p The C client's aerospike object.
* @param error_p The C client's as_error to be set to the encountered error.
* @param module_p The name of the UDF module to get from the
* server.
* @param module_len Length of UDF module name.
* @param udf_code_p Code of the UDF to be populated by this
* function.
* @param language The Aerospike::UDF_TYPE_* constant.
* @param options_p The optional policy.
*
* @return AEROSPIKE_OK if success. Otherwise AEROSPIKE_x.
******************************************************************************************************
*/
extern as_status
aerospike_get_registered_udf_module_code(Aerospike_object* aerospike_obj_p,
as_error* error_p, char* module_p, zval* udf_code_p,
long language, zval* options_p)
{
uint32_t init_udf_file = 0;
as_udf_file udf_file;
as_policy_info info_policy;
TSRMLS_FETCH_FROM_CTX(aerospike_obj_p->ts);
set_policy(&aerospike_obj_p->as_ref_p->as_p->config, NULL, NULL,
NULL, NULL, &info_policy, NULL, NULL, NULL, options_p,
error_p TSRMLS_CC);
if (AEROSPIKE_OK != (error_p->code)) {
DEBUG_PHP_EXT_DEBUG("Unable to set policy");
goto exit;
}
as_udf_file_init(&udf_file);
init_udf_file = 1;
if (AEROSPIKE_OK != aerospike_udf_get(aerospike_obj_p->as_ref_p->as_p,
error_p, &info_policy, module_p, language, &udf_file)) {
DEBUG_PHP_EXT_ERROR("%s", error_p->message);
goto exit;
}
ZVAL_STRINGL(udf_code_p, (char*) udf_file.content.bytes, udf_file.content.size, 1);
exit:
if (init_udf_file) {
as_udf_file_destroy(&udf_file);
}
return error_p->code;
}
示例3: mergeGlobal
static void mergeGlobal(zval * val, zval *zrequest, int type)
{
TSRMLS_FETCH_FROM_CTX(sw_thread_ctx ? sw_thread_ctx : NULL);
zval *http_server;
MAKE_STD_ZVAL(http_server);
object_init_ex(http_server, swoole_http_server_class_entry_ptr);
zval *http_request_ptr = zend_read_property(swoole_http_server_class_entry_ptr, http_server, ZEND_STRL("request"), 1 TSRMLS_CC);
int http_request = Z_LVAL_P(http_request_ptr);
switch (type) {
case HTTP_GLOBAL_GET:
ZEND_SET_SYMBOL(&EG(symbol_table), "_GET", val);
break;
case HTTP_GLOBAL_POST:
ZEND_SET_SYMBOL(&EG(symbol_table), "_POST", val);
break;
case HTTP_GLOBAL_COOKIE:
ZEND_SET_SYMBOL(&EG(symbol_table), "_COOKIE", val);
break;
}
if(http_request & type) {
zval *_request = zend_read_property(swoole_http_request_class_entry_ptr, zrequest, ZEND_STRL("request"), 1
TSRMLS_CC);
zend_hash_copy(Z_ARRVAL_P(_request), Z_ARRVAL_P(val), NULL, NULL, sizeof(zval));
}
}
示例4: php_swoole_event_onWrite
static int php_swoole_event_onWrite(swReactor *reactor, swEvent *event)
{
zval *retval;
zval **args[1];
php_reactor_fd *fd = event->socket->object;
#if PHP_MAJOR_VERSION < 7
TSRMLS_FETCH_FROM_CTX(sw_thread_ctx ? sw_thread_ctx : NULL);
#endif
if (!fd->cb_write)
{
return swReactor_onWrite(reactor, event);
}
args[0] = &fd->socket;
if (sw_call_user_function_ex(EG(function_table), NULL, fd->cb_write, &retval, 1, args, 0, NULL TSRMLS_CC) == FAILURE)
{
swoole_php_fatal_error(E_WARNING, "swoole_event: onWrite handler error");
SwooleG.main_reactor->del(SwooleG.main_reactor, event->fd);
return SW_ERR;
}
if (EG(exception))
{
zend_exception_error(EG(exception), E_ERROR TSRMLS_CC);
}
if (retval != NULL)
{
sw_zval_ptr_dtor(&retval);
}
return SW_OK;
}
示例5: php_swoole_onSignal
/**
* safe signal
*/
static void php_swoole_onSignal(int signo)
{
zval *retval;
zval **args[1];
zval *callback = signal_callback[signo];
#if PHP_MAJOR_VERSION < 7
TSRMLS_FETCH_FROM_CTX(sw_thread_ctx ? sw_thread_ctx : NULL);
#endif
zval *zsigno;
SW_MAKE_STD_ZVAL(zsigno);
ZVAL_LONG(zsigno, signo);
args[0] = &zsigno;
if (sw_call_user_function_ex(EG(function_table), NULL, callback, &retval, 1, args, 0, NULL TSRMLS_CC) == FAILURE)
{
php_error_docref(NULL TSRMLS_CC, E_WARNING, "user_signal handler error");
}
if (retval != NULL)
{
sw_zval_ptr_dtor(&retval);
}
sw_zval_ptr_dtor(&zsigno);
}
示例6: php_swoole_event_onError
static int php_swoole_event_onError(swReactor *reactor, swEvent *event)
{
#if PHP_MAJOR_VERSION < 7
TSRMLS_FETCH_FROM_CTX(sw_thread_ctx ? sw_thread_ctx : NULL);
#endif
int error;
socklen_t len = sizeof(error);
if (getsockopt(event->fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0)
{
swoole_php_fatal_error(E_WARNING, "swoole_event->onError[1]: getsockopt[sock=%d] failed. Error: %s[%d]", event->fd, strerror(errno), errno);
}
if (error != 0)
{
swoole_php_fatal_error(E_WARNING, "swoole_event->onError[1]: socket error. Error: %s [%d]", strerror(error), error);
}
efree(event->socket->object);
event->socket->active = 0;
SwooleG.main_reactor->del(SwooleG.main_reactor, event->fd);
return SW_OK;
}
示例7: swoole_websocket_onHandshake
int swoole_websocket_onHandshake(swListenPort *port, http_context *ctx)
{
#if PHP_MAJOR_VERSION < 7
TSRMLS_FETCH_FROM_CTX(sw_thread_ctx ? sw_thread_ctx : NULL);
#endif
int fd = ctx->fd;
int ret = websocket_handshake(port, ctx);
if (ret == SW_ERR)
{
swServer_tcp_close(SwooleG.serv, fd, 1);
}
else
{
swoole_websocket_onOpen(ctx);
}
//free client data
if (!ctx->end)
{
swoole_http_context_free(ctx TSRMLS_CC);
}
return SW_OK;
}
示例8: http_request_on_body
static int http_request_on_body(php_http_parser *parser, const char *at, size_t length)
{
TSRMLS_FETCH_FROM_CTX(sw_thread_ctx ? sw_thread_ctx : NULL);
http_client *client = parser->data;
char *body = estrndup(at, length);
if (client->request.post_form_urlencoded)
{
zval *post;
MAKE_STD_ZVAL(post);
array_init(post);
zend_update_property(swoole_http_request_class_entry_ptr, client->zrequest, ZEND_STRL("post"), post TSRMLS_CC);
sapi_module.treat_data(PARSE_STRING, body, post TSRMLS_CC);
mergeGlobal(post, client->zrequest, HTTP_GLOBAL_POST);
}
else
{
client->request.post_content = body;
client->request.post_length = length;
}
return 0;
}
示例9: http_request_on_body
static int http_request_on_body(php_http_parser *parser, const char *at, size_t length)
{
TSRMLS_FETCH_FROM_CTX(sw_thread_ctx ? sw_thread_ctx : NULL);
http_client *client = parser->data;
char *body = estrndup(at, length);
if (client->request.post_form_urlencoded)
{
zval *post;
MAKE_STD_ZVAL(post);
array_init(post);
zend_update_property(swoole_http_request_class_entry_ptr, client->zrequest, ZEND_STRL("post"), post TSRMLS_CC);
sapi_module.treat_data(PARSE_STRING, body, post TSRMLS_CC);
ZEND_SET_SYMBOL(&EG(symbol_table), "_POST", post);
zval *_request = zend_read_property(swoole_http_request_class_entry_ptr, client->zrequest, ZEND_STRL("request"), 1 TSRMLS_CC);
zend_hash_copy(Z_ARRVAL_P(_request), Z_ARRVAL_P(post), NULL, NULL, sizeof(zval));
}
else
{
client->request.post_content = body;
client->request.post_length = length;
}
return 0;
}
示例10: swoole_websocket_onHandshake
int swoole_websocket_onHandshake(swoole_http_client *client)
{
#if PHP_MAJOR_VERSION < 7
TSRMLS_FETCH_FROM_CTX(sw_thread_ctx ? sw_thread_ctx : NULL);
#endif
int fd = client->fd;
int ret = websocket_handshake(client);
if (ret == SW_ERR)
{
SwooleG.serv->factory.end(&SwooleG.serv->factory, fd);
}
else
{
swoole_websocket_onOpen(client);
}
//free client data
if (!client->end)
{
swoole_http_request_free(client TSRMLS_CC);
}
return SW_OK;
}
示例11: php_swoole_event_onDefer
static void php_swoole_event_onDefer(void *_cb)
{
php_defer_callback *defer = _cb;
#if PHP_MAJOR_VERSION < 7
TSRMLS_FETCH_FROM_CTX(sw_thread_ctx ? sw_thread_ctx : NULL);
#endif
zval *retval;
if (sw_call_user_function_ex(EG(function_table), NULL, defer->callback, &retval, 0, NULL, 0, NULL TSRMLS_CC) == FAILURE)
{
swoole_php_fatal_error(E_WARNING, "swoole_event: defer handler error");
return;
}
if (EG(exception))
{
zend_exception_error(EG(exception), E_ERROR TSRMLS_CC);
}
if (retval != NULL)
{
sw_zval_ptr_dtor(&retval);
}
sw_zval_ptr_dtor(&defer->callback);
efree(defer);
}
示例12: php_swoole_onTimeout
static void php_swoole_onTimeout(swTimer *timer, swTimer_node *event)
{
swTimer_callback *callback = event->data;
zval *retval = NULL;
#if PHP_MAJOR_VERSION < 7
TSRMLS_FETCH_FROM_CTX(sw_thread_ctx ? sw_thread_ctx : NULL);
#endif
zval **args[1];
int argc = 0;
if (callback->data)
{
args[0] = &callback->data;
argc = 1;
}
if (sw_call_user_function_ex(EG(function_table), NULL, callback->callback, &retval, argc, args, 0, NULL TSRMLS_CC) == FAILURE)
{
php_error_docref(NULL TSRMLS_CC, E_WARNING, "swoole_timer: onTimeout handler error");
return;
}
if (retval)
{
sw_zval_ptr_dtor(&retval);
}
callback = event->data;
if (callback)
{
if (callback->data)
{
sw_zval_ptr_dtor(&callback->data);
}
efree(callback);
}
}
示例13: _php_ibase_callback
static isc_callback _php_ibase_callback(ibase_event *event, /* {{{ */
unsigned short buffer_size, char *result_buf)
{
zval *res;
/* this function is called asynchronously by the Interbase client library. */
TSRMLS_FETCH_FROM_CTX(event->thread_ctx);
/**
* The callback function is called when the event is first registered and when the event
* is cancelled. I consider this is a bug. By clearing event->callback first and setting
* it to -1 later, we make sure nothing happens if no event was actually posted.
*/
switch (event->state) {
unsigned short i;
unsigned long occurred_event[15];
zval return_value, args[2];
default: /* == DEAD */
break;
case ACTIVE:
/* copy the updated results into the result buffer */
memcpy(event->result_buffer, result_buf, buffer_size);
res = zend_hash_index_find(&EG(regular_list), event->link_res_id);
ZVAL_RES(&args[1], Z_RES_P(res));
/* find out which event occurred */
isc_event_counts(occurred_event, buffer_size, event->event_buffer, event->result_buffer);
for (i = 0; i < event->event_count; ++i) {
if (occurred_event[i]) {
ZVAL_STRING(&args[0], event->events[i]);
efree(event->events[i]);
break;
}
}
/* call the callback provided by the user */
if (SUCCESS != call_user_function(EG(function_table), NULL,
&event->callback, &return_value, 2, args)) {
_php_ibase_module_error("Error calling callback %s", Z_STRVAL(event->callback));
break;
}
if (Z_TYPE(return_value) == IS_FALSE) {
event->state = DEAD;
break;
}
case NEW:
/* re-register the event */
if (isc_que_events(IB_STATUS, &event->link->handle, &event->event_id, buffer_size,
event->event_buffer,(isc_callback)_php_ibase_callback, (void *)event)) {
_php_ibase_error();
}
event->state = ACTIVE;
}
return 0;
}
示例14: http_client_free
static void http_client_free(http_client *client)
{
if (client->zrequest)
{
TSRMLS_FETCH_FROM_CTX(sw_thread_ctx ? sw_thread_ctx : NULL);
http_request_free(client TSRMLS_CC);
}
efree(client);
}
示例15: aerospike_udf_apply
/*
******************************************************************************************************
Applies a UDF to a record at the Aerospike DB.
*
* @param aerospike_obj_p The C client's aerospike object.
* @param as_key_p The C client's as_key that identifies the
* record on which UDF will be applied.
* @param error_p The C client's as_error to be set to the encountered error.
* @param module_p The name of the UDF module registered
* against the Aerospike DB.
* @param function_p The name of the function to be applied to
* the record.
* @param args_pp An array of arguments for the UDF.
* @param return_value_p It will contain result value of calling the
* UDF.
* @param options_p The optional policy.
*
* @return AEROSPIKE_OK if success. Otherwise AEROSPIKE_x.
******************************************************************************************************
*/
extern as_status
aerospike_udf_apply(Aerospike_object* aerospike_obj_p,
as_key* as_key_p, as_error* error_p, char* module_p, char* function_p,
zval** args_pp, zval* return_value_p, zval* options_p)
{
as_arraylist args_list;
as_arraylist* args_list_p = NULL;
as_static_pool udf_pool = {0};
as_val* udf_result_p = NULL;
foreach_callback_udata udf_result_callback_udata;
uint32_t serializer_policy = -1;
as_policy_apply apply_policy;
TSRMLS_FETCH_FROM_CTX(aerospike_obj_p->ts);
set_policy_udf_apply(&aerospike_obj_p->as_ref_p->as_p->config, &apply_policy, &serializer_policy,
options_p, error_p TSRMLS_CC);
if (AEROSPIKE_OK != (error_p->code)) {
DEBUG_PHP_EXT_DEBUG("Unable to set policy");
goto exit;
}
if ((*args_pp)) {
as_arraylist_inita(&args_list,
zend_hash_num_elements(Z_ARRVAL_PP(args_pp)));
args_list_p = &args_list;
AS_LIST_PUT(NULL, args_pp, args_list_p, &udf_pool, serializer_policy, error_p TSRMLS_CC);
}
if (AEROSPIKE_OK != (aerospike_key_apply(aerospike_obj_p->as_ref_p->as_p,
error_p, &apply_policy, as_key_p, module_p, function_p,
(as_list *) args_list_p, &udf_result_p))) {
DEBUG_PHP_EXT_DEBUG("%s", error_p->message);
goto exit;
}
if (return_value_p) {
udf_result_callback_udata.udata_p = return_value_p;
udf_result_callback_udata.error_p = error_p;
AS_DEFAULT_GET(NULL, udf_result_p, &udf_result_callback_udata);
}
exit:
if (udf_result_p) {
as_val_destroy(udf_result_p);
}
if (args_list_p) {
as_arraylist_destroy(args_list_p);
}
/* clean up the as_* objects that were initialised */
aerospike_helper_free_static_pool(&udf_pool);
return error_p->code;
}