Sha256: 8a17b6cb896595ef10671a859ac291247124dd196bae7431dc16847499036260

Contents?: true

Size: 1.31 KB

Versions: 3

Compression:

Stored size: 1.31 KB

Contents

#pragma once

#include <sys/epoll.h>

static struct epoll_event qevents[MAX_E];

static void ADD_E(int fd, uint64_t etype) {
  struct epoll_event e;
  e.events = EPOLLIN;
  e.data.u64 = (etype << 32) | (uint64_t)fd;

  // todo timeout
# ifdef NDEBUG
  epoll_ctl(qfd, EPOLL_CTL_ADD, fd, &e);
# else
  if (epoll_ctl(qfd, EPOLL_CTL_ADD, fd, &e))
    printf("%s: %s\n", __func__, strerror(errno));
# endif
}

static void DEL_E(int fd) {
  struct epoll_event e;
  e.events = EPOLLIN;
  e.data.ptr = NULL;

# ifdef NDEBUG
  epoll_ctl(qfd, EPOLL_CTL_DEL, fd, &e);
# else
  if (epoll_ctl(qfd, EPOLL_CTL_DEL, fd, &e))
    printf("%s: %s\n", __func__, strerror(errno));
# endif
}

static void INIT_E() {
  qfd = epoll_create(10); // size not important
  if (qfd == -1) {
    printf("%s\n", strerror(errno));
    exit(-1);
  }
}

static void LOOP_E() {
  while (1) {
    // heart beat of 0.1 sec, allow ruby signal interrupts to be inserted
    int sz = epoll_wait(qfd, qevents, MAX_E, 100);

    for (int i = 0; i < sz; i++) {
      switch (qevents[i].events) {
        case EPOLLIN: {
          int fd = (int)(qevents[i].data.u64 & 0xFFFFFFFF);
          int etype = (int)(qevents[i].data.u64 >> 32);
          loop_body(fd, etype);
          break;
        }
      }
    }
    // execute other thread / interrupts
    rb_thread_schedule();
  }
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nyara-0.0.1.pre.2 ext/inc/epoll.h
nyara-0.0.1.pre.1 ext/inc/epoll.h
nyara-0.0.1.pre ext/inc/epoll.h