Low level system poll for mruby
C Ruby
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
.gitignore
LICENSE
README.md
mrbgem.rake

README.md

mruby-poll

Low level system poll for mruby

Example without a block

poll = Poll.new

pollfd = poll.add(STDOUT_FILENO, Poll::Out)

if ready_fds = poll.wait
  ready_fds.each do |ready_fd|
    puts ready_fd
  end
end

Example with a block

poll = Poll.new

pollfd = poll.add(STDOUT_FILENO, Poll::Out)

poll.wait do |ready_fd|
  if ready_fd == pollfd
    puts "got STDOUT_FILENO"
  end
end

"Documentation"

class Poll
  def add(socket, events = Poll::In) # adds a Ruby Socket/IO Object to the pollfds
  # returns a Poll::_Fd
  def remove(fd) # deletes a Poll::_Fd struct from the pollfds
  def wait((optional) (int) timeout, &block) # waits until a fd becomes ready, its using the poll function from <poll.h>
  # returns "false" when the process gets interrupted
  # returns "nil" when it times out
  # returns a array when ready fds have been found, or self when a block is passed
  # raises exceptions according to other errors
end

For other errors take a look at http://pubs.opengroup.org/onlinepubs/007908799/xsh/poll.html

class Poll
  class _Fd
    def socket() # returns the socket
    def socket=(socket) # # sets another socket
    def events() # returns the events
    def events=(events) # sets events
    def revents() # returns the events after a poll()
    def revents=(revents) # sets revents
    def readable? # returns if the socket is readable
    def writable? # returns if the socket is writable
    def err? # returns if the socket is in a error state
    def disconnected? # returns if the socket is disconnected
  end
end

Events

Poll::Err
Poll::Hub
Poll::In
Poll::NVal
Poll::Out
Poll::Pri
Poll::RdBand
Poll::RdNorm
Poll::WrBand
Poll::WrBand
Poll::WrNorm

For what these events mean take a look at http://pubs.opengroup.org/onlinepubs/007908799/xsh/poll.html