Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasi: apply wasm_runtime_begin_blocking_op to poll as well #3080

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "ssp_config.h"
#include "blocking_op.h"
#include "libc_errno.h"

__wasi_errno_t
blocking_op_close(wasm_exec_env_t exec_env, os_file_handle handle,
Expand Down Expand Up @@ -170,3 +171,23 @@ blocking_op_openat(wasm_exec_env_t exec_env, os_file_handle handle,
wasm_runtime_end_blocking_op(exec_env);
return error;
}

#ifndef BH_PLATFORM_WINDOWS
/* REVISIT: apply the os_file_handle style abstraction for pollfd? */
__wasi_errno_t
blocking_op_poll(wasm_exec_env_t exec_env, struct pollfd *pfds, nfds_t nfds,
int timeout_ms, int *retp)
{
int ret;
if (!wasm_runtime_begin_blocking_op(exec_env)) {
return __WASI_EINTR;
}
ret = poll(pfds, nfds, timeout_ms);
wasm_runtime_end_blocking_op(exec_env);
if (ret == -1) {
return convert_errno(errno);
}
*retp = ret;
return 0;
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,10 @@ __wasi_errno_t
blocking_op_openat(wasm_exec_env_t exec_env, os_file_handle handle,
const char *path, __wasi_oflags_t oflags,
__wasi_fdflags_t fd_flags, __wasi_lookupflags_t lookup_flags,
wasi_libc_file_access_mode access_mode, os_file_handle *out);
wasi_libc_file_access_mode access_mode, os_file_handle *out);

#ifndef BH_PLATFORM_WINDOWS
__wasi_errno_t
blocking_op_poll(wasm_exec_env_t exec_env, struct pollfd *pfds, nfds_t nfds,
int timeout, int *retp);
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -2230,11 +2230,10 @@ wasmtime_ssp_poll_oneoff(wasm_exec_env_t exec_env, struct fd_table *curfds,
timeout = -1;
}

int ret = poll(pfds, nsubscriptions, timeout);

__wasi_errno_t error = 0;
if (ret == -1) {
error = convert_errno(errno);
int ret;
int error = blocking_op_poll(exec_env, pfds, nsubscriptions, timeout, &ret);
if (error != 0) {
/* got an error */
}
else if (ret == 0 && *nevents == 0 && clock_subscription != NULL) {
// No events triggered. Trigger the clock event.
Expand Down
Loading