2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
|
2022-06-12 15:15:09 +02:00
|
|
|
#include <bits/pthread_cancel.h>
|
2019-01-23 07:27:41 +01:00
|
|
|
#include <errno.h>
|
2019-06-07 11:49:03 +02:00
|
|
|
#include <poll.h>
|
2020-06-22 11:41:51 -04:00
|
|
|
#include <sys/time.h>
|
2021-02-05 12:16:30 +01:00
|
|
|
#include <syscall.h>
|
2019-01-23 07:27:41 +01:00
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
|
2021-12-20 01:26:27 -08:00
|
|
|
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/poll.html
|
2020-06-22 11:41:51 -04:00
|
|
|
int poll(pollfd* fds, nfds_t nfds, int timeout_ms)
|
2019-01-23 07:27:41 +01:00
|
|
|
{
|
2022-06-12 15:15:09 +02:00
|
|
|
__pthread_maybe_cancel();
|
|
|
|
|
|
2020-06-22 11:41:51 -04:00
|
|
|
timespec timeout;
|
|
|
|
|
timespec* timeout_ts = &timeout;
|
|
|
|
|
if (timeout_ms < 0)
|
|
|
|
|
timeout_ts = nullptr;
|
|
|
|
|
else
|
|
|
|
|
timeout = { timeout_ms / 1000, (timeout_ms % 1000) * 1'000'000 };
|
|
|
|
|
return ppoll(fds, nfds, timeout_ts, nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
int ppoll(pollfd* fds, nfds_t nfds, timespec const* timeout, sigset_t const* sigmask)
|
2020-06-22 11:41:51 -04:00
|
|
|
{
|
|
|
|
|
Syscall::SC_poll_params params { fds, nfds, timeout, sigmask };
|
|
|
|
|
int rc = syscall(SC_poll, ¶ms);
|
2019-01-23 07:27:41 +01:00
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
|
}
|
|
|
|
|
}
|