Skip to content

Commit a74b2b8

Browse files
committed
poll: introduce BackendUnavailableException
1 parent b553541 commit a74b2b8

File tree

5 files changed

+34
-4
lines changed

5 files changed

+34
-4
lines changed

ext/standard/io_poll.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ static zend_class_entry *php_io_poll_watcher_class_entry;
2929
static zend_class_entry *php_io_poll_handle_class_entry;
3030
static zend_class_entry *php_io_exception_class_entry;
3131
static zend_class_entry *php_io_poll_exception_class_entry;
32+
static zend_class_entry *php_io_poll_failed_backend_unavailable_class_entry;
3233
static zend_class_entry *php_io_poll_failed_operation_class_entry;
3334
static zend_class_entry *php_io_poll_failed_context_init_class_entry;
3435
static zend_class_entry *php_io_poll_failed_handle_add_class_entry;
@@ -662,7 +663,9 @@ PHP_METHOD(Io_Poll_Context, __construct)
662663
intern->ctx = php_poll_create(backend_type, 0);
663664

664665
if (!intern->ctx) {
665-
zend_argument_value_error(1, "must be available backend");
666+
zend_throw_exception_ex(
667+
php_io_poll_failed_backend_unavailable_class_entry, 0, "Backend %s not available",
668+
php_io_poll_backend_type_to_name(backend_type));
666669
RETURN_THROWS();
667670
}
668671

@@ -893,6 +896,9 @@ PHP_MINIT_FUNCTION(poll)
893896
php_io_poll_failed_wait_class_entry = register_class_Io_Poll_FailedPollWaitException(
894897
php_io_poll_failed_operation_class_entry);
895898

899+
php_io_poll_failed_backend_unavailable_class_entry = register_class_Io_Poll_BackendUnavailableException(
900+
php_io_poll_exception_class_entry);
901+
896902
php_io_poll_inactive_watcher_class_entry = register_class_Io_Poll_InactiveWatcherException(
897903
php_io_poll_exception_class_entry);
898904

ext/standard/io_poll.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ class FailedWatcherModificationException extends FailedPollOperationException {}
128128

129129
class FailedPollWaitException extends FailedPollOperationException {}
130130

131+
class BackendUnavailableException extends PollException {}
132+
131133
class InactiveWatcherException extends PollException {}
132134

133135
class HandleAlreadyWatchedException extends PollException {}

ext/standard/io_poll_arginfo.h

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/standard/tests/poll/poll_stream_backend_name_unix.phpt renamed to ext/standard/tests/poll/poll_ctx_backend_unix.phpt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Poll stream - backend name
2+
Poll context - backend on Unix
33
--SKIPIF--
44
<?php
55
if (substr(PHP_OS, 0, 3) == 'WIN') {
@@ -16,7 +16,13 @@ var_dump($poll_ctx->getBackend());
1616
$poll_ctx = new Io\Poll\Context(Io\Poll\Backend::Poll);
1717
$backend = $poll_ctx->getBackend();
1818
var_dump($backend->name);
19+
try {
20+
new Io\Poll\Context(Io\Poll\Backend::WSAPoll);
21+
} catch (\Io\Poll\BackendUnavailableException $e) {
22+
var_dump($e->getMessage());
23+
}
1924
?>
2025
--EXPECTF--
2126
enum(Io\Poll\Backend::%s)
2227
string(4) "Poll"
28+
string(29) "Backend WSAPoll not available"

ext/standard/tests/poll/poll_stream_backend_name_windows.phpt renamed to ext/standard/tests/poll/poll_ctx_backend_windows.phpt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Poll stream - backend name on Windows
2+
Poll context - backend on Windows
33
--SKIPIF--
44
<?php
55
if (substr(PHP_OS, 0, 3) != 'WIN') {
@@ -16,7 +16,13 @@ var_dump($poll_ctx->getBackend());
1616
$poll_ctx = new Io\Poll\Context(Io\Poll\Backend::WSAPoll);
1717
$backend = $poll_ctx->getBackend();
1818
var_dump($backend->name);
19+
try {
20+
new Io\Poll\Context(Io\Poll\Backend::Epoll);
21+
} catch (\Io\Poll\BackendUnavailableException $e) {
22+
var_dump($e->getMessage());
23+
}
1924
?>
2025
--EXPECTF--
2126
enum(Io\Poll\Backend::%s)
2227
string(7) "WSAPoll"
28+
string(27) "Backend Epoll not available"

0 commit comments

Comments
 (0)