mirror of
https://github.com/awslabs/aws-crt-php.git
synced 2026-08-18 01:57:13 +00:00
Added EventLoopGroup API to native extension (#15)
This commit is contained in:
+8
-8
@@ -37,15 +37,15 @@ extension: ext/crt.lo
|
||||
# Force the crt object target to depend on the CRT static library
|
||||
ext/crt.lo: $(BUILD_DIR)/aws-crt-ffi-static/libaws-crt-ffi.a ext/api.h ext/awscrt_arginfo.h
|
||||
|
||||
ifeq ($(AT_LEAST_PHP7),1)
|
||||
GEN_STUB=build/gen_stub.php
|
||||
# generate awscrt_arginfo.h
|
||||
ext/awscrt_arginfo.h: ext/awscrt.stub.php $(GEN_STUB)
|
||||
php $(GEN_STUB) ext/awscrt.stub.php
|
||||
# borrow the gen_stub script from PHP's build process
|
||||
GEN_STUB=build/gen_stub.php
|
||||
$(GEN_STUB):
|
||||
curl -o $(GEN_STUB) -sSL https://raw.githubusercontent.com/php/php-src/bbb86ba7e2fe8ae365294d1834c6a392570a9dcd/build/gen_stub.php
|
||||
|
||||
# borrow the gen_stub script from PHP's build process
|
||||
$(GEN_STUB):
|
||||
curl -o $(GEN_STUB) -sSL https://raw.githubusercontent.com/php/php-src/bbb86ba7e2fe8ae365294d1834c6a392570a9dcd/build/gen_stub.php
|
||||
ext/awscrt_arginfo.h: ext/awscrt.stub.php $(GEN_STUB)
|
||||
ifeq ($(AT_LEAST_PHP7),1)
|
||||
# generate awscrt_arginfo.h
|
||||
php $(GEN_STUB) ext/awscrt.stub.php
|
||||
endif
|
||||
|
||||
# transform/install api.h from FFI lib
|
||||
|
||||
Generated
+2
-2
@@ -1343,7 +1343,7 @@
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-ctype",
|
||||
"version": "v1.22.0",
|
||||
"version": "v1.22.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-ctype.git",
|
||||
@@ -1402,7 +1402,7 @@
|
||||
"portable"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/polyfill-ctype/tree/v1.22.0"
|
||||
"source": "https://github.com/symfony/polyfill-ctype/tree/v1.22.1"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
||||
@@ -9,3 +9,7 @@ function aws_crt_error_name(int $error_code): string {}
|
||||
function aws_crt_error_str(int $error_code): string {}
|
||||
|
||||
function aws_crt_error_debug_str(int $error_code): string {}
|
||||
|
||||
function aws_crt_event_loop_group_new(int $max_threads): int {}
|
||||
|
||||
function aws_crt_event_loop_group_release(int $event_loop_group): void {}
|
||||
|
||||
+13
-1
@@ -1,5 +1,5 @@
|
||||
/* This is a generated file, edit the .stub.php file instead.
|
||||
* Stub hash: a629a07df494f8ae6563949b2819c833e9d73f9a */
|
||||
* Stub hash: 04ff04fec5e4293918658ac98394d98387fa977b */
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_last_error, 0, 0, IS_LONG, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
@@ -12,11 +12,21 @@ ZEND_END_ARG_INFO()
|
||||
|
||||
#define arginfo_aws_crt_error_debug_str arginfo_aws_crt_error_name
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_event_loop_group_new, 0, 1, IS_LONG, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, max_threads, IS_LONG, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_event_loop_group_release, 0, 1, IS_VOID, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, event_loop_group, IS_LONG, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
|
||||
ZEND_FUNCTION(aws_crt_last_error);
|
||||
ZEND_FUNCTION(aws_crt_error_name);
|
||||
ZEND_FUNCTION(aws_crt_error_str);
|
||||
ZEND_FUNCTION(aws_crt_error_debug_str);
|
||||
ZEND_FUNCTION(aws_crt_event_loop_group_new);
|
||||
ZEND_FUNCTION(aws_crt_event_loop_group_release);
|
||||
|
||||
|
||||
static const zend_function_entry ext_functions[] = {
|
||||
@@ -24,5 +34,7 @@ static const zend_function_entry ext_functions[] = {
|
||||
ZEND_FE(aws_crt_error_name, arginfo_aws_crt_error_name)
|
||||
ZEND_FE(aws_crt_error_str, arginfo_aws_crt_error_str)
|
||||
ZEND_FE(aws_crt_error_debug_str, arginfo_aws_crt_error_debug_str)
|
||||
ZEND_FE(aws_crt_event_loop_group_new, arginfo_aws_crt_event_loop_group_new)
|
||||
ZEND_FE(aws_crt_event_loop_group_release, arginfo_aws_crt_event_loop_group_release)
|
||||
ZEND_FE_END
|
||||
};
|
||||
|
||||
@@ -81,6 +81,28 @@ PHP_FUNCTION(aws_crt_error_debug_str) {
|
||||
AWS_RETURN_STRING(aws_crt_error_debug_str(error_code));
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_event_loop_group_new) {
|
||||
zend_ulong num_threads = 0;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &num_threads) == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
struct aws_event_loop_group *elg = aws_crt_event_loop_group_new(num_threads);
|
||||
RETURN_LONG((zend_ulong)elg);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(aws_crt_event_loop_group_release) {
|
||||
zend_ulong php_elg = 0;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &php_elg) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct aws_event_loop_group *elg = (void *)php_elg;
|
||||
aws_crt_event_loop_group_release(elg);
|
||||
}
|
||||
|
||||
zend_module_entry awscrt_module_entry = {
|
||||
STANDARD_MODULE_HEADER,
|
||||
"awscrt",
|
||||
|
||||
+11
-4
@@ -42,7 +42,7 @@ final class CRT {
|
||||
/**
|
||||
* @return integer last error code reported within the CRT
|
||||
*/
|
||||
public static function last_error() {
|
||||
public static function last_error(): int {
|
||||
return self::$impl->aws_crt_last_error();
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ final class CRT {
|
||||
* @param integer $error Error code from the CRT, usually delivered via callback or {@see last_error}
|
||||
* @return string Human-readable description of the provided error code
|
||||
*/
|
||||
public static function error_str($error) {
|
||||
public static function error_str(int $error) : string {
|
||||
return self::$impl->aws_crt_error_str((int) $error);
|
||||
}
|
||||
|
||||
@@ -58,14 +58,21 @@ final class CRT {
|
||||
* @param integer $error Error code from the CRT, usually delivered via callback or {@see last_error}
|
||||
* @return string Name/enum identifier for the provided error code
|
||||
*/
|
||||
public static function error_name($error) {
|
||||
public static function error_name(int $error) : string {
|
||||
return self::$impl->aws_crt_error_name((int) $error);
|
||||
}
|
||||
|
||||
function event_loop_group_new($num_threads) {
|
||||
/**
|
||||
* @param integer $num_threads Maximum threads to use in the event loop group
|
||||
* @return object Pointer to the new event loop group
|
||||
*/
|
||||
function event_loop_group_new(int $num_threads) {
|
||||
return self::$impl->aws_crt_event_loop_group_new($num_threads);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object $elg Pointer to the event loop group to release
|
||||
*/
|
||||
function event_loop_group_release($elg) {
|
||||
return self::$impl->aws_crt_event_loop_group_release($elg);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
--TEST--
|
||||
aws_crt_event_loop_group
|
||||
--SKIPIF--
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . '/skipif.inc');
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . '/common.inc');
|
||||
|
||||
$elg = aws_crt_event_loop_group_new(1);
|
||||
var_dump($elg);
|
||||
aws_crt_event_loop_group_release($elg);
|
||||
?>
|
||||
--EXPECTREGEX--
|
||||
int\(\d+\)
|
||||
Reference in New Issue
Block a user