https://github.com/asmod4n/mruby-poll
Low level system poll for mruby
https://github.com/asmod4n/mruby-poll
mruby networking
Last synced: 11 months ago
JSON representation
Low level system poll for mruby
- Host: GitHub
- URL: https://github.com/asmod4n/mruby-poll
- Owner: Asmod4n
- License: mit
- Created: 2016-06-30T16:46:12.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-10-24T16:48:01.000Z (over 1 year ago)
- Last Synced: 2025-04-07T03:34:23.409Z (12 months ago)
- Topics: mruby, networking
- Language: C
- Size: 43.9 KB
- Stars: 1
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mruby-poll
Low level system poll for mruby
Example without a block
=======================
```ruby
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
====================
```ruby
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"
=============
```ruby
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
# 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
```ruby
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
```ruby
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