Skip to content

Commit

Permalink
fixup! posix_select: initial import of select() function
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Dec 17, 2019
1 parent e4f53dc commit f3196eb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
15 changes: 14 additions & 1 deletion sys/posix/include/sys/select.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,19 @@
#define SYS_SELECT_H

#include <string.h>
#ifdef MODULE_NEWLIB /* prevent cyclic dependency with newlib's `sys/types.h` */
/* prevent cyclic dependency with newlib's `sys/types.h` */
#if defined(MODULE_NEWLIB) && !defined(CPU_ESP32) && !defined(CPU_ESP8266)
#include <sys/_timeval.h>
#else
#include <sys/time.h>
#endif

#include "bitfield.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @addtogroup config_posix
* @{
Expand All @@ -55,6 +60,8 @@

#define POSIX_SELECT_THREAD_FLAG (1U << 3)

/* ESP's newlib has this already defined in `sys/types.h` */
#if !defined(CPU_ESP32) && !defined(CPU_ESP8266)
/**
* @brief Maximum number of file descriptors in an `fd_set` structure.
*
Expand Down Expand Up @@ -116,6 +123,7 @@ static inline void FD_ZERO(fd_set *fdsetp)
{
memset(fdsetp->fds, 0, sizeof(fdsetp->fds));
}
#endif /* !defined(CPU_ESP32) && !defined(CPU_ESP8266) */

/**
* @brief Examines the given file descriptor sets if they are ready for their
Expand Down Expand Up @@ -148,4 +156,9 @@ static inline void FD_ZERO(fd_set *fdsetp)
int select(int nfds, fd_set *restrict readfds, fd_set *restrict writefds,
fd_set *restrict errorfds, struct timeval *restrict timeout);

#ifdef __cplusplus
}
#endif

#endif /* SYS_SELECT_H */
/** @} */
3 changes: 2 additions & 1 deletion sys/posix/select/posix_select.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ static inline void posix_socket_select(int fd)
int select(int nfds, fd_set *restrict readfds, fd_set *restrict writefds,
fd_set *restrict errorfds, struct timeval *restrict timeout)
{
fd_set ret_readfds = { .fds = { 0U } };
fd_set ret_readfds;
xtimer_t timeout_timer;
int fds_set = 0;
bool wait = true;

FD_ZERO(&ret_readfds);
/* TODO ignored for now since there is no point for them with sockets */
if (timeout != NULL) {
uint64_t t = ((uint64_t)(timeout->tv_sec * US_PER_SEC) +
Expand Down

0 comments on commit f3196eb

Please sign in to comment.