Select API#

Modules#

fd_set

Typedefs#

typedef long int

A type representing a set of file descriptors.

Functions#

int
select(int nfds, fd_set *restrict readfds, fd_set *restrict writefds, fd_set *restrict exceptfds, struct timeval *restrict timeout)

Monitor multiple file descriptors for readiness.

void

Check the read socket file descriptor set.

void

Check the write socket file descriptor set.

void

Initialize the select system.

Macros#

#define
FD_CLR (d, set)

Clear the bit for the file descriptor d in the fd_set.

#define
FD_ELT (d)

Calculate the index in the fds_bits array for the file descriptor d.

#define
FD_ISSET (d, set)

Check whether the bit for the file descriptor d is set in the fd_set.

#define
FD_MASK (d)

Create a mask for the bit position within an fd_mask for the file descriptor d.

#define
FD_SET (d, set)

Set the bit for the file descriptor d in the fd_set.

#define
FD_SETSIZE 64

Maximum number of file descriptors in ‘fd_set’.

#define
FD_ZERO (set)

Clear all bits in the fd_set.

#define
NFDBITS (8 * (int) sizeof (fd_mask))

The number of bits in an fd_mask.

Typedef Documentation#

fd_mask#

typedef long int fd_mask

A type representing a set of file descriptors.


Function Documentation#

select#

int select (int nfds, fd_set *restrict readfds, fd_set *restrict writefds, fd_set *restrict exceptfds, struct timeval *restrict timeout)

Monitor multiple file descriptors for readiness.

Parameters
TypeDirectionArgument NameDescription
int[in]nfds

The highest-numbered file descriptor in any of the three sets, plus 1.

fd_set *restrict[inout]readfds

An optional pointer to a set of file descriptors to be checked for readability.

fd_set *restrict[inout]writefds

An optional pointer to a set of file descriptors to be checked for writability.

fd_set *restrict[inout]exceptfds

An optional pointer to a set of file descriptors to be checked for exceptions.

struct timeval *restrict[in]timeout

An optional timeout. If NULL, select() blocks indefinitely. To specify a non-blocking poll, set the timeout to zero.

Returns

  • On success, returns the total number of bits set in readfds, writefds. If the time limit expires, select() returns zero. On error, -1 is returned, and errno is set appropriately.

This function monitors multiple file descriptors, waiting until one or more of the file descriptors are ready for an I/O operation.

Note

  • This implementation does not handle exceptfds.


sl_wisun_check_read_sockfd_set#

void sl_wisun_check_read_sockfd_set (void )

Check the read socket file descriptor set.

Parameters
TypeDirectionArgument NameDescription
voidN/A

This function notifies select to check the read socket file descriptor set. The function should be called in response to the reception of SL_WISUN_MSG_SOCKET_DATA_AVAILABLE_IND_ID. It notifies select to check the read socket file descriptor set for any ready socket to read.

Usage:

// Application indication handler
void sl_wisun_on_event(void) {
  // Application code here...
  switch (evt->header.id) {
    // When SL_WISUN_MSG_SOCKET_DATA_AVAILABLE_IND_ID is received
    case SL_WISUN_MSG_SOCKET_DATA_AVAILABLE_IND_ID:
      // Call the function to check the read socket file descriptor set
      sl_wisun_check_read_sockfd_set();
      break;
  }
  // Application code here...
}

sl_wisun_check_write_sockfd_set#

void sl_wisun_check_write_sockfd_set (void )

Check the write socket file descriptor set.

Parameters
TypeDirectionArgument NameDescription
voidN/A

This function notifies select to check the write socket file descriptor set. The function should be called in response to the reception of SL_WISUN_MSG_SOCKET_DATA_SENT_IND_ID. It notifies select to check the write socket file descriptor set for any ready socket to write.

Usage:

void sl_wisun_on_event(void) {
  // Your code here...
  switch (evt->header.id) {
    // When SL_WISUN_MSG_SOCKET_DATA_SENT_IND_ID is received
    case SL_WISUN_MSG_SOCKET_DATA_SENT_IND_ID:
      // Call the function to check the write socket file descriptor set
      sl_wisun_check_write_sockfd_set();
      break;
  }
  // Your code here...
}

sl_wisun_select_init#

void sl_wisun_select_init (void )

Initialize the select system.

Parameters
TypeDirectionArgument NameDescription
voidN/A

This function initializes the select system by creating a new event flag with the specified attributes. The event flag is used to indicate when a file descriptor set is ready to be checked for I/O operations.