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);
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章