Skip to content

Asmod4n/mruby-poll

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 <sys/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

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

About

Low level system poll for mruby

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •