Parent

SleepyPenguin::Epoll::IO

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.

Public Class Methods

SleepyPenguin::Epoll::IO.new(flags) → Epoll::IO object view method source

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);
}

Public Instance Methods

__epoll_wait(maxevents = 64, timeout = nil) view method source
Alias for: epoll_wait
epoll_ctl(op, io, events) → nil view method source

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;
}
epoll_wait(maxevents = 64, timeout = nil) view method source

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.

Also aliased as: __epoll_wait

Originally generated with the Darkfish Rdoc Generator 2, modified by wrongdoc.

We love to hear from you!
Email patches (with git send-email), pull requests, questions, bug reports, suggestions, etc. to us publically at sleepy.penguin@librelist.org.
To subscribe, just send any email to sleepy.penguin@librelist.org, and respond to the automated confirmation message.
Do not waste bandwidth with HTML, HTML mail will not be read.
Quote only parts you're responding to and do not top post.
For sensitive topics, email us privately at sleepy.penguin@bogomips.org.