Updated CRT library, test process, EventLoopGroup API updates (#16)

* Updated to latest aws-crt-ffi, updated EventLoopGroup/options init

* Removed test-ci target, just use test for everything now

* Added event_loop_group API to CRT/stubs

* Removed headers (all generated) from format-check

* Added the ability to force extension vs FFI

* make test will now trigger composer run test/phpunit, and force tests with both FFI and extension

* Updated builder version, removed redundant php7 test run

* Removed type annotations that anger php5, limited backends on php5
This commit is contained in:
Justin Boswell
2021-03-12 11:47:55 -08:00
committed by GitHub
parent ec7900afb5
commit 9171857448
13 changed files with 237 additions and 175 deletions
+50 -13
View File
@@ -20,15 +20,30 @@ final class CRT {
function __construct() {
if (is_null(self::$impl)) {
try {
self::$impl = new Extension();
} catch (RuntimeException $rex) {
try {
self::$impl = new FFI();
} catch (RuntimeException $frex) {
throw new RuntimeException('Unable to initialize AWS CRT via extension or FFI', -1, $frex);
// Figure out what backends are/should be available
$backends = ['Extension'];
if (version_compare(PHP_VERSION, '7.0.0') >= 0) {
$backends = ['Extension', 'FFI'];
if (getenv('AWS_CRT_PHP_EXTENSION')) {
$backends = ['Extension'];
} else if (getenv('AWS_CRT_PHP_FFI')) {
$backends = ['FFI'];
}
}
// Try to load each backend, give up if none succeed
$exceptions = [];
foreach ($backends as $backend) {
try {
$backend = 'AWS\\CRT\\Internal\\' . $backend;
self::$impl = new $backend();
} catch (RuntimeException $rex) {
array_push($exceptions, $rex);
}
}
if (is_null(self::$impl)) {
throw new RuntimeException('Unable to initialize AWS CRT via ' . join(', ', $backends) . ": \n" . join("\n", $exceptions), -1);
}
}
++self::$refcount;
}
@@ -42,7 +57,7 @@ final class CRT {
/**
* @return integer last error code reported within the CRT
*/
public static function last_error(): int {
public static function last_error() {
return self::$impl->aws_crt_last_error();
}
@@ -50,7 +65,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(int $error) : string {
public static function error_str($error) {
return self::$impl->aws_crt_error_str((int) $error);
}
@@ -58,16 +73,38 @@ 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(int $error) : string {
public static function error_name($error) {
return self::$impl->aws_crt_error_name((int) $error);
}
/**
* @param integer $num_threads Maximum threads to use in the event loop group
* @return object Pointer to native event_loop_group_options
*/
function event_loop_group_options_new() {
return self::$impl->aws_crt_event_loop_group_options_new();
}
/**
* @param object $elg_options Pointer to native event_loop_group_options
*/
function event_loop_group_options_release($elg_options) {
self::$impl->aws_crt_event_loop_group_options_release($elg_options);
}
/**
* @param object $elg_options Pointer to native event_loop_group_options
* @param integer $max_threads Maximum number of threads to allow the event loop group to use, default: 0/1 per CPU core
*/
function event_loop_group_options_set_max_threads($elg_options, $max_threads) {
self::$impl->aws_crt_event_loop_group_options_set_max_threads($elg_options, (int)$max_threads);
}
/**
* @param object Pointer to event_loop_group_options, {@see event_loop_group_options_new}
* @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);
function event_loop_group_new($options) {
return self::$impl->aws_crt_event_loop_group_new($options);
}
/**
+5 -2
View File
@@ -15,7 +15,7 @@ final class EventLoopGroup extends NativeResource {
static function defaults() {
return array(
'num_threads' => 0,
'max_threads' => 0,
);
}
@@ -24,7 +24,10 @@ final class EventLoopGroup extends NativeResource {
if (count($options) == 0) {
$options = self::defaults();
}
$this->acquire(self::$crt->event_loop_group_new($options['num_threads']));
$elg_options = self::$crt->event_loop_group_options_new();
self::$crt->event_loop_group_options_set_max_threads($elg_options, $options['max_threads']);
$this->acquire(self::$crt->event_loop_group_new($elg_options));
self::$crt->event_loop_group_options_release($elg_options);
}
function __destruct() {
+1 -1
View File
@@ -20,7 +20,7 @@ final class Extension {
* same name with the supplied arguments. Argument type hinting and checking
* occurs at the CRT wrapper.
*/
function __call(string $name, $args) {
function __call($name, $args) {
return call_user_func_array($name, $args);
}
}