[fuchsia] Use zx_port_cancel_key in Fuchsia event handling logic

This updates the IOHandle type in eventhandler_fuchsia to use
zx_port_cancel_key to cancel outstanding asynchronous waits instead of
the (older) zx_port_cancel. The cancel_key operation requires only the
key used to register the initial wait and not the originating handle.
This means that the IOHandle operation no longer has to store the
original handle or worry about its lifetime.

Tested: Patched locally in a test embedder using this logic
Change-Id: Iec0ec632a7dd438a34e482a12b5b298be56ce476
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/501840
Reviewed-by: Zijie He <zijiehe@google.com>
Auto-Submit: James Robinson <jamesr@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
James Robinson
2026-05-13 12:47:06 -07:00
committed by dart-scoped@luci-project-accounts.iam.gserviceaccount.com
parent 426137ba6a
commit b5a613c378
2 changed files with 4 additions and 8 deletions
+4 -6
View File
@@ -234,11 +234,10 @@ bool IOHandle::AsyncWaitLocked(zx_handle_t port,
port_ = port;
}
handle_ = handle;
wait_key_ = key;
LOG_INFO("zx_object_wait_async(fd = %ld, signals = %x)\n", fd_, signals);
zx_status_t status =
zx_object_wait_async(handle_, port_, key, signals, ZX_WAIT_ASYNC_ONCE);
zx_object_wait_async(handle, port_, key, signals, ZX_WAIT_ASYNC_ONCE);
if (status != ZX_OK) {
LOG_ERR("zx_object_wait_async failed: %s\n", zx_status_get_string(status));
return false;
@@ -256,13 +255,12 @@ void IOHandle::CancelWait(zx_handle_t port, uint64_t key) {
MutexLocker ml(&mutex_);
LOG_INFO("IOHandle::CancelWait: fd = %ld\n", fd_);
ASSERT(port != ZX_HANDLE_INVALID);
ASSERT(handle_ != ZX_HANDLE_INVALID);
if (key == 0) {
LOG_ERR("IOHandle::CancelWait calling zx_port_cancel with key == 0");
LOG_ERR("IOHandle::CancelWait calling zx_port_cancel_key with key == 0");
}
zx_status_t status = zx_port_cancel(port, handle_, key);
zx_status_t status = zx_port_cancel_key(port, 0u, key);
if ((status != ZX_OK) && (status != ZX_ERR_NOT_FOUND)) {
LOG_ERR("zx_port_cancel failed: %s\n", zx_status_get_string(status));
LOG_ERR("zx_port_cancel_key failed: %s\n", zx_status_get_string(status));
}
}
-2
View File
@@ -37,7 +37,6 @@ class IOHandle : public ReferenceCounted<IOHandle> {
read_events_enabled_(true),
close_events_enabled_(true),
fd_(fd),
handle_(ZX_HANDLE_INVALID),
wait_key_(0),
fdio_(fdio_unsafe_fd_to_io(fd)) {}
@@ -83,7 +82,6 @@ class IOHandle : public ReferenceCounted<IOHandle> {
// TODO(zra): Add flag to enable/disable peer closed signal?
intptr_t fd_;
zx_handle_t handle_;
zx_handle_t port_;
uint64_t wait_key_;
fdio_t* fdio_;