src/event.c
static inline int
event_loop_dispatch (kk_event_loop_t *loop)
{
  kk_event_handler_t *handler;
  struct timeval tv;
  fd_set rfds;
  int r;
  int e;

  FD_ZERO (&rfds);
  for (handler = loop->handler; handler < loop->handler + loop->len; handler++)
    FD_SET (handler->fd, &rfds);

  tv.tv_sec = 10;
  tv.tv_usec = 0;

  /**
   * Timers might interrupt our select call. In this case errno gets set to
   * EINTR and we won't return a value < 0 to avoid exiting the event loop.
   */
  errno = 0;
  r = select (loop->mfd + 1, &rfds, NULL, NULL, &tv);
  e = errno;

  /**
   * The return value of select is zero if the timeout expired and nothing
   * happened.
   */
  if (r == 0)
    return 0;

  /**
   * On error, -1 is returned and errno is set the error code. We don't
   * treat interrupts as errors here.
   */
  if (r < 0)
    return -(e != EINTR);

  for (handler = loop->handler; handler < loop->handler + loop->len; handler++) {
    if (FD_ISSET (handler->fd, &rfds))
      handler->func (loop, handler->fd, handler->arg);
    if (loop->exit)
      return -1;
  }
  return 0;
}
/**
 * Note: With some older glibc versions (pre 2.16), the calls FD_SET and
 * FD_ISSET will cause compiler warnings about conversions from int to
 * unsigned long int conversions. There's nothing we can do about. This
 * was fixed in glibc 2.16.
 */
With some older glibc versions (pre 2.16), the calls FD_SET and
FD_ISSET will cause compiler warnings about conversions from int to
unsigned long int conversions. There's nothing we can do about. This
was fixed in glibc 2.16.
With some older glibc versions ( pre 2 . 16 ) the calls FD_SET and FD_ISSET will cause compiler warnings about conversions from int to unsigned long int conversions . There ' s nothing we can do about . This was fixed in glibc 2 . 16 .
static inline int
event_loop_dispatch (kk_event_loop_t *loop)
{
  kk_event_handler_t *handler;
  struct timeval tv;
  fd_set rfds;
  int r;
  int e;
  FD_ZERO (&rfds);
  for (handler = loop->handler; handler < loop->handler + loop->len; handler++)
    FD_SET (handler->fd, &rfds);
  tv.tv_sec = 10;
  tv.tv_usec = 0;
  errno = 0;
  r = select (loop->mfd + 1, &rfds, NULL, NULL, &tv);
  e = errno;
  if (r == 0)
    return 0;
  if (r < 0)
    return -(e != EINTR);
  for (handler = loop->handler; handler < loop->handler + loop->len; handler++) {
    if (FD_ISSET (handler->fd, &rfds))
      handler->func (loop, handler->fd, handler->arg);
    if (loop->exit)
      return -1;
  }
  return 0;
}
static inline int event_loop_dispatch ( kk_event_loop_t * loop ) { kk_event_handler_t * handler ; struct timeval tv ; fd_set rfds ; int r ; int e ; FD_ZERO ( & rfds ) ; for ( handler = loop -> handler ; handler < loop -> handler + loop -> len ; handler ++ ) FD_SET ( handler -> fd , & rfds ) ; tv . tv_sec = 10 ; tv . tv_usec = 0 ; errno = 0 ; r = select ( loop -> mfd + 1 , & rfds , NULL , NULL , & tv ) ; e = errno ; if ( r == 0 ) return 0 ; if ( r < 0 ) return - ( e != EINTR ) ; for ( handler = loop -> handler ; handler < loop -> handler + loop -> len ; handler ++ ) { if ( FD_ISSET ( handler -> fd , & rfds ) ) handler -> func ( loop , handler -> fd , handler -> arg ) ; if ( loop -> exit ) return -1 ; } return 0 ; }
Note: With some older glibc versions (pre 2.16), the calls FD_SET and
 FD_ISSET will cause compiler warnings about conversions from int to
 unsigned long int conversions.
Note : With some older glibc versions ( pre 2 . 16 ) the calls FD_SET and FD_ISSET will cause compiler warnings about conversions from int to unsigned long int conversions .
/**
   * Timers might interrupt our select call. In this case errno gets set to
   * EINTR and we won't return a value < 0 to avoid exiting the event loop.
   */ /**
   * The return value of select is zero if the timeout expired and nothing
   * happened.
   */ /**
   * On error, -1 is returned and errno is set the error code. We don't
   * treat interrupts as errors here.
   */