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
|
|
|
*/
|
|
|
|
|
|
2019-01-17 01:41:13 +01:00
|
|
|
#include <errno.h>
|
|
|
|
|
#include <stdio.h>
|
2019-06-07 11:49:03 +02:00
|
|
|
#include <sys/select.h>
|
2020-06-21 13:54:41 -04:00
|
|
|
#include <sys/time.h>
|
2021-02-05 12:16:30 +01:00
|
|
|
#include <syscall.h>
|
2019-01-17 01:41:13 +01:00
|
|
|
|
2019-01-23 06:53:01 +01:00
|
|
|
extern "C" {
|
|
|
|
|
|
2020-06-21 13:54:41 -04:00
|
|
|
int select(int nfds, fd_set* readfds, fd_set* writefds, fd_set* exceptfds, timeval* timeout_tv)
|
2019-01-17 01:41:13 +01:00
|
|
|
{
|
2020-06-21 13:54:41 -04:00
|
|
|
timespec* timeout_ts = nullptr;
|
|
|
|
|
timespec timeout;
|
|
|
|
|
if (timeout_tv) {
|
|
|
|
|
timeout_ts = &timeout;
|
|
|
|
|
TIMEVAL_TO_TIMESPEC(timeout_tv, timeout_ts);
|
|
|
|
|
}
|
|
|
|
|
return pselect(nfds, readfds, writefds, exceptfds, timeout_ts, nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int pselect(int nfds, fd_set* readfds, fd_set* writefds, fd_set* exceptfds, const timespec* timeout, const sigset_t* sigmask)
|
|
|
|
|
{
|
|
|
|
|
Syscall::SC_select_params params { nfds, readfds, writefds, exceptfds, timeout, sigmask };
|
2019-01-17 01:41:13 +01:00
|
|
|
int rc = syscall(SC_select, ¶ms);
|
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
|
}
|
2019-01-23 06:53:01 +01:00
|
|
|
}
|