aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs6/ftrigr_wait_and.c
blob: 24e722f4032d7aec600a6e6f957e414a78b13ee6 (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
27
28
29
/* ISC license. */

#include <sys/uio.h>
#include <errno.h>

#include <skalibs/iopause.h>

#include <s6/ftrigr.h>

int ftrigr_wait_and (ftrigr *a, uint32_t const *list, unsigned int n, tain const *deadline, tain *stamp)
{
  iopause_fd x = { .fd = ftrigr_fd(a), .events = IOPAUSE_READ } ;
  for (unsigned int i = 0 ; i < n ; i++)
  {
    for (;;)
    {
      struct iovec v ;
      int r = ftrigr_peek(a, list[i], &v) ;
      if (r == -1) return -1 ;
      if (r) break ;
      r = iopause_stamp(&x, 1, deadline, stamp) ;
      if (r == -1) return -1 ;
      if (!r) return (errno = ETIMEDOUT, -1) ;
      if (ftrigr_update(a) == -1) return -1 ;
    }
    ftrigr_ack(a, list[i]) ;
  }
  return 0 ;
}