コード例 #1
0
ファイル: timed_ancil_fds_recv.c プロジェクト: djbtao/skalibs
int timed_ancil_fds_recv (int fdsocket, int *fds, unsigned int n, struct taia const *deadline, struct taia *stamp)
{
  iopause_fd x = { fdsocket, IOPAUSE_READ, 0 } ;
  for (;;)
  {
    register int r = iopause_stamp(&x, 1, deadline, stamp) ;
    if (r < 0) return 0 ;
    else if (!r) return (errno = ETIMEDOUT, 0) ;
    else if (x.revents & IOPAUSE_READ)
    {
      r = sanitize_read(ancil_recv_fds(fdsocket, fds, n)) ;
      if (r < 0) return 0 ;
      else if (r > 0) break ;
    }
  }
  return 1 ;
}
コード例 #2
0
int timed_buffer_flush (buffer_ref b, struct taia const *deadline, struct taia *stamp)
{
  iopause_fd x = { b->fd, IOPAUSE_WRITE, 0 } ;
  while (buffer_len(b))
  {
    register int r = iopause_stamp(&x, 1, deadline, stamp) ;
    if (r < 0) return 0 ;
    else if (!r) return (errno = ETIMEDOUT, 0) ;
    else if (x.revents & IOPAUSE_WRITE)
    {
      if ((buffer_flush(b) < 0) && !error_isagain(errno)) return 0 ;
    }
    else if (x.revents & IOPAUSE_EXCEPT)
    {
      buffer_flush(b) ; /* sets errno */
      return 0 ;
    }
  }
  return 1 ;
}
コード例 #3
0
int s6lock_wait_or (s6lock_t_ref a, uint16 const *idlist, unsigned int n, struct taia const *deadline, struct taia *stamp)
{
  iopause_fd x = { -1, IOPAUSE_READ | IOPAUSE_EXCEPT, 0 } ;
  x.fd = s6lock_fd(a) ;
  if (x.fd < 0) return -1 ;
  for (;;)
  {
    register unsigned int i = 0 ;
    register int r ;
    for (; i < n ; i++)
    {
      r = s6lock_check(a, idlist[i]) ;
      if (r < 0) return r ;
      else if (r) return i ;
    }
    r = iopause_stamp(&x, 1, deadline, stamp) ;
    if (r < 0) return 0 ;
    else if (!r) return (errno = ETIMEDOUT, -1) ;
    else if (s6lock_update(a) < 0) return -1 ;
  }
  return (errno = EPROTO, -1) ; /* can't happen */
}
コード例 #4
0
unsigned int timed_buffer_get (buffer_ref b, char *s, unsigned int len, struct taia const *deadline, struct taia *stamp)
{
  iopause_fd x = { -1, IOPAUSE_READ, 0 } ;
  unsigned int w = 0 ;
  unsigned int n = buffer_getnofill(b, s, len) ;
  s += n ; len -= n ;
  if (!len) return n ;
  x.fd = buffer_fd(b) ;
  for (;;)
  {
    register int r = iopause_stamp(&x, 1, deadline, stamp) ;
    if (r < 0) return n+w ;
    else if (!r) return (errno = ETIMEDOUT, n+w) ;
    else if (x.revents & (IOPAUSE_READ | IOPAUSE_EXCEPT))
    {
      r = buffer_getall(b, s, len, &w) ;
      if (r < 0) return n+w ;
      else if (r) break ;
    }
  }
  return n+len ;
}
コード例 #5
0
ファイル: deepsleepuntil.c プロジェクト: fvigotti/skalibs
void deepsleepuntil (tain_t const *deadline, tain_t *stamp)
{
  iopause_fd x ;
  while (tain_less(stamp, deadline)) iopause_stamp(&x, 0, deadline, stamp) ;
}