Epoll::IO is a low-level class. It does not provide fork nor GC-safety, so Ruby IO objects added via epoll_ctl must be retained by the application until IO#close is called.
Creates a new Epoll::IO object with the given flags argument. flags may currently be CLOEXEC or 0.
static VALUE s_new(VALUE klass, VALUE _flags)
{
int flags = rb_sp_get_flags(klass, _flags);
int fd = epoll_create1(flags);
VALUE rv;
if (fd < 0) {
if (errno == EMFILE || errno == ENFILE || errno == ENOMEM) {
rb_gc();
fd = epoll_create1(flags);
}
if (fd == -1)
rb_sys_fail("epoll_create1");
}
rv = INT2FIX(fd);
return rb_call_super(1, &rv);
}
Register, modify, or register a watch for a given io for events.
op may be one of EPOLL_CTL_ADD, EPOLL_CTL_MOD, or EPOLL_CTL_DEL io is an IO object or one which proxies via the to_io method. events is an integer mask of events to watch for.
Returns nil on success.
static VALUE epctl(VALUE self, VALUE _op, VALUE io, VALUE events)
{
struct epoll_event event;
int epfd = rb_sp_fileno(self);
int fd = rb_sp_fileno(io);
int op = NUM2INT(_op);
int rv;
event.events = NUM2UINT(events);
pack_event_data(&event, io);
rv = epoll_ctl(epfd, op, fd, &event);
if (rv < 0)
rb_sys_fail("epoll_ctl");
return Qnil;
}
Calls epoll_wait(2) and yields Integer events and IO objects watched for. maxevents is the maximum number of events to process at once, lower numbers may prevent starvation when used by epoll_wait in multiple threads. Larger maxevents reduces syscall overhead for single-threaded applications. maxevents defaults to 64 events. timeout is specified in milliseconds, nil (the default) meaning it will block and wait indefinitely.
Originally generated with the Darkfish Rdoc Generator 2, modified by wrongdoc.
We love to hear from you!