pselect

pselect比select多了个信号屏蔽的功能
如果在select运行的时候不想被程序中未知的信号打断出现错误,就需要在SELECT的时候屏蔽不需要的信号

int pselect(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
	    const struct timespec *timeout, const sigset_t *sigmask) {
  int ret;
  struct timeval tv, *ptv;
  sigset_t oldsigs;

  if (timeout != NULL) {
    tv.tv_sec = timeout->tv_sec;
    tv.tv_usec = timeout->tv_nsec / 1000000;
    ptv = &tv;
  } else
    ptv = NULL;

  if (sigmask != NULL)
    sigprocmask(SIG_SETMASK, sigmask, &oldsigs);
  ret = select(n, readfds, writefds, exceptfds, ptv);
  if (sigmask != NULL)
    sigprocmask(SIG_SETMASK, &oldsigs, NULL);
  return (ret);
}

你可能感兴趣的:(struct,null)