Commit 1715196c authored by Chris Friedt's avatar Chris Friedt Committed by Henrik Brix Andersen
Browse files

posix: device_io: implement pselect()



Implement pselect() as it's required by POSIX_DEVICE_IO

Signed-off-by: default avatarChris Friedt <cfriedt@tenstorrent.com>
parent b3d3d4ff
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -51,9 +51,12 @@ typedef struct zvfs_fd_set zsock_fd_set;
static inline int zsock_select(int nfds, zsock_fd_set *readfds, zsock_fd_set *writefds,
			       zsock_fd_set *exceptfds, struct zsock_timeval *timeout)
{
	struct timeval;
	struct timespec to = {
		.tv_sec = (timeout == NULL) ? 0 : timeout->tv_sec,
		.tv_nsec = (long)((timeout == NULL) ? 0 : timeout->tv_usec * NSEC_PER_USEC)};

	return zvfs_select(nfds, readfds, writefds, exceptfds, (struct timeval *)timeout);
	return zvfs_select(nfds, readfds, writefds, exceptfds, (timeout == NULL) ? NULL : &to,
			   NULL);
}

/** Number of file descriptors which can be added to zsock_fd_set */
+2 −0
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ extern "C" {

struct timeval;

int pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
	    const struct timespec *timeout, const void *sigmask);
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *timeout);
void FD_CLR(int fd, fd_set *fdset);
int FD_ISSET(int fd, fd_set *fdset);
+1 −1
Original line number Diff line number Diff line
@@ -223,7 +223,7 @@ void ZVFS_FD_ZERO(struct zvfs_fd_set *fdset);
__syscall int zvfs_select(int nfds, struct zvfs_fd_set *ZRESTRICT readfds,
			  struct zvfs_fd_set *ZRESTRICT writefds,
			  struct zvfs_fd_set *ZRESTRICT errorfds,
			  const struct timeval *ZRESTRICT timeout);
			  const struct timespec *ZRESTRICT timeout, const void *ZRESTRICT sigmask);

/**
 * Request codes for fd_op_vtable.ioctl().
+7 −5
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ void ZVFS_FD_SET(int fd, struct zvfs_fd_set *set)
int z_impl_zvfs_select(int nfds, struct zvfs_fd_set *ZRESTRICT readfds,
		       struct zvfs_fd_set *ZRESTRICT writefds,
		       struct zvfs_fd_set *ZRESTRICT exceptfds,
		       const struct timeval *ZRESTRICT timeout)
		       const struct timespec *ZRESTRICT timeout, const void *ZRESTRICT sigmask)
{
	struct zvfs_pollfd pfds[CONFIG_ZVFS_POLL_MAX];
	k_timeout_t poll_timeout;
@@ -140,7 +140,8 @@ int z_impl_zvfs_select(int nfds, struct zvfs_fd_set *ZRESTRICT readfds,
	if (timeout == NULL) {
		poll_timeout = K_FOREVER;
	} else {
		poll_timeout = K_USEC(timeout->tv_sec * USEC_PER_SEC + timeout->tv_usec);
		poll_timeout =
			K_USEC(timeout->tv_sec * USEC_PER_SEC + timeout->tv_nsec / NSEC_PER_USEC);
	}

	res = zvfs_poll_internal(pfds, num_pfds, poll_timeout);
@@ -218,10 +219,11 @@ int z_impl_zvfs_select(int nfds, struct zvfs_fd_set *ZRESTRICT readfds,
static int z_vrfy_zvfs_select(int nfds, struct zvfs_fd_set *ZRESTRICT readfds,
			      struct zvfs_fd_set *ZRESTRICT writefds,
			      struct zvfs_fd_set *ZRESTRICT exceptfds,
			      const struct timeval *ZRESTRICT timeout)
			      const struct timespec *ZRESTRICT timeout,
			      const void *ZRESTRICT sigmask)
{
	struct zvfs_fd_set *readfds_copy = NULL, *writefds_copy = NULL, *exceptfds_copy = NULL;
	struct timeval *to = NULL;
	struct timespec *to = NULL;
	int ret = -1;

	if (readfds) {
@@ -259,7 +261,7 @@ static int z_vrfy_zvfs_select(int nfds, struct zvfs_fd_set *ZRESTRICT readfds,
		}
	}

	ret = z_impl_zvfs_select(nfds, readfds_copy, writefds_copy, exceptfds_copy, to);
	ret = z_impl_zvfs_select(nfds, readfds_copy, writefds_copy, exceptfds_copy, to, sigmask);

	if (ret >= 0) {
		if (readfds_copy) {
+12 −1
Original line number Diff line number Diff line
@@ -71,6 +71,12 @@ ssize_t pread(int fd, void *buf, size_t count, off_t offset)
	return zvfs_read(fd, buf, count, (size_t *)&off);
}

int pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
	    const struct timespec *timeout, const void *sigmask)
{
	return zvfs_select(nfds, readfds, writefds, exceptfds, timeout, sigmask);
}

ssize_t pwrite(int fd, void *buf, size_t count, off_t offset)
{
	size_t off = (size_t)offset;
@@ -93,7 +99,12 @@ FUNC_ALIAS(read, _read, ssize_t);

int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
{
	return zvfs_select(nfds, readfds, writefds, exceptfds, timeout);
	struct timespec to = {
		.tv_sec = (timeout == NULL) ? 0 : timeout->tv_sec,
		.tv_nsec = (long)((timeout == NULL) ? 0 : timeout->tv_usec * NSEC_PER_USEC)};

	return zvfs_select(nfds, readfds, writefds, exceptfds, (timeout == NULL) ? NULL : &to,
			   NULL);
}

ssize_t write(int fd, const void *buf, size_t sz)
Loading