summaryrefslogtreecommitdiff
path: root/src/libstddjb/iopause_poll.c
blob: f189974b304ca4d1df432db4fbf7924b50829dcf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/* ISC license. */

#include <errno.h>
#include <poll.h>

#include <skalibs/tai.h>
#include <skalibs/iopause.h>

int iopause_poll (iopause_fd *x, unsigned int len, tain const *deadline, tain const *stamp)
{
  int r ;
  int millisecs = 0 ;
  if (!deadline) millisecs = -1 ;
  else if (tain_less(stamp, deadline))
  {
    tain t ;
    tain_sub(&t, deadline, stamp) ;
    millisecs = tain_to_millisecs(&t) ;
  }
  r = poll(x, len, millisecs) ;
  if (r > 0)
    for (unsigned int i = 0 ; i < len ; i++)
      if (x[i].revents & IOPAUSE_EXCEPT)
        x[i].revents |= x[i].events ;
  return r ;
}