Select

#include <sys/select.h>
#include <sys/time.h>

int select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
           const struct timeval *timeout);

/* Returns: positive count of ready descriptors, 0 on timeout, –1 on error */

The timeout argument

struct timeval  {
  long   tv_sec;          /* seconds */
  long   tv_usec;         /* microseconds */
};
  1. Wait forever: 널포인터가 인자로 들어간경우 영원히 기다림
  2. Wait up to a fixed amount of time: 특정시간이 지정된 경우 그 시간만큼만 기다림
  3. Do not wait at all:시간이 0인 경우, 보통 반복문을 사용하여 polling 할때 사용

특정 파일디스크립터의 read, write, except중 체크할 경우 지정.

void FD_ZERO(fd_set *fdset);         /* clear all bits in fdset */
void FD_SET(int fd, fd_set *fdset);  /* turn on the bit for fd in fdset */
void FD_CLR(int fd, fd_set *fdset);  /* turn off the bit for fd in fdset */
int FD_ISSET(int fd, fd_set *fdset); /* is the bit for fd on in fdset ? */

The maxfdp1

return

socket fd + event(read, write)