All Projects → ksss → epoll

ksss / epoll

Licence: MIT License
epoll(7) binding in Ruby

Programming Languages

ruby
36898 projects - #4 most used programming language
c
50402 projects - #5 most used programming language

Labels

Projects that are alternatives of or similar to epoll

fancy
High performance web server
Stars: ✭ 20 (-9.09%)
Mutual labels:  epoll
hev-task-system
A simple, lightweight multi-task system (coroutines) for Unix (Linux/BSD/macOS)
Stars: ✭ 41 (+86.36%)
Mutual labels:  epoll
tunnel
一款单线程、轻量级和高性能的内网穿透程序,支持TCP流量转发(支持所有TCP上层协议,包括HTTP,SSH等),支持多客户端同时连接
Stars: ✭ 39 (+77.27%)
Mutual labels:  epoll
async
⏱ Promises and reactive-streams in Swift built for high-performance and scalability.
Stars: ✭ 35 (+59.09%)
Mutual labels:  epoll
ZLToolKit
一个基于C++11的轻量级网络框架,基于线程池技术可以实现大并发网络IO
Stars: ✭ 1,302 (+5818.18%)
Mutual labels:  epoll
liblw
An asynchronous application framework built on C++ coroutines and epoll.
Stars: ✭ 34 (+54.55%)
Mutual labels:  epoll
WebServer
High-performance multi-threaded tcp network server in c++11
Stars: ✭ 58 (+163.64%)
Mutual labels:  epoll
Tiginx
Tiginx is a Shanzhai Nginx project , please buyao use it xian , if meet problem , I no fuze ...
Stars: ✭ 29 (+31.82%)
Mutual labels:  epoll
netman
高性能的TCP网络框架、支持TLS、可配置的路由、websocket、基于事件循环(epoll),百万连接(C1000K)
Stars: ✭ 96 (+336.36%)
Mutual labels:  epoll
libapenetwork
Fast cross-platform async network library
Stars: ✭ 17 (-22.73%)
Mutual labels:  epoll
connect
tiny cross-platform socket API library
Stars: ✭ 46 (+109.09%)
Mutual labels:  epoll
WebServer
C++高性能网络服务器
Stars: ✭ 53 (+140.91%)
Mutual labels:  epoll
Mgx
🌈 A high performance network framework written in c++ (support tcp and http)
Stars: ✭ 15 (-31.82%)
Mutual labels:  epoll
netpoll
Package netpoll implements a network poller based on epoll/kqueue.
Stars: ✭ 38 (+72.73%)
Mutual labels:  epoll
epump
ePump是一个基于I/O事件通知、非阻塞通信、多路复用、多线程等机制开发的事件驱动模型的 C 语言应用开发框架,利用该框架可以很容易地开发出高性能、大并发连接的服务器程序。
Stars: ✭ 26 (+18.18%)
Mutual labels:  epoll
cherry
cherry: A Minimal HTTP Server
Stars: ✭ 22 (+0%)
Mutual labels:  epoll
lce
linux网络编程框架(C++)基于Reactor事件机制,支持线程池,异步非阻塞,高并发,高性能
Stars: ✭ 61 (+177.27%)
Mutual labels:  epoll
30dayMakeCppServer
30天自制C++服务器,包含教程和源代码
Stars: ✭ 432 (+1863.64%)
Mutual labels:  epoll
sol
Lightweight MQTT broker, written from scratch. IO is handled by a super simple event loop based upon the most common IO multiplexing implementations.
Stars: ✭ 72 (+227.27%)
Mutual labels:  epoll
epoller
epoll implementation for connections in Linux, MacOS and Windows
Stars: ✭ 58 (+163.64%)
Mutual labels:  epoll

epoll

Build Status

A binding of epoll(7) on Ruby.

epoll(7) can use Linux only. (because must be installed sys/epoll.h)

Usage

require 'epoll'

# Epoll < IO

# Epoll.create
#   call epoll_create(2)
#   it's just alias of `open`
#   Epoll object stock a File Descriptor returned by epoll_create(2)
#   return: instance of Epoll (kind of IO)
epoll = Epoll.create

# IO object add to interest list
#   call epoll_ctl(2)
epoll.add(io, Epoll::IN)  # same way to epoll.ctl(Epoll::CTL_ADD, io, Epoll::IN)

# change waiting events
#   call epoll_ctl(2)
epoll.mod(io, Epoll::OUT) # same way to epoll.ctl(Epoll::CTL_MOD, io, Epoll::OUT)

# remove from interest list
#   call epoll_ctl(2)
epoll.del(io)             # same way to epoll.ctl(Epoll::CTL_DEL, io)

loop do
  # Epoll#wait(timeout=-1)
  #   call epoll_wait(2)
  #   timeout = -1: block until receive event or signals
  #   timeout = 0: return all io's can I/O on non block
  #   timeout > 0: block when timeout pass miri second or receive events or signals
  #   return: Array of Epoll::Event
  evlist = epoll.wait

  # ev is instance of Epoll::Event like `struct epoll_event`
  # it's instance of `class Epoll::Event < Struct.new(:data, :events); end`
  evlist.each do |ev|
    # Epoll::Event#events is event flag bits (Fixnum)
    if (ev.events & Epoll::IN) != 0
      # Epoll::Event#data is notified IO (IO)
      # e.g. it's expect to I/O readable
      puts ev.data.read
    elsif (ev.events & Epoll::HUP|Epoll::ERR) != 0
      ev.data.close
      break
    end
  end
end

# you can close File Descriptor for epoll when finish to use
epoll.close #=> nil

# and you can check closed
epoll.closed? #=> true

# and very useful way is that call `create` with block like `IO.open`
# return: block result
Epoll.create do |epoll|
  # ensure automatic call `epoll.close` when out block
end

ctl options

ctl options description
Epoll::CTL_ADD add to interest list for created epoll fd
Epoll::CTL_MOD change io events
Epoll::CTL_DEL delete in interest list

Event flags

event flags ctl wait description
Epoll::IN o o readable
Epoll::PRI o o high priority read
Epoll::HUP o o peer socket was shutdown
Epoll::OUT o o writable
Epoll::ET o x use edge trigger
Epoll::ONESHOT o x auto watching stop when notified(but stay in list)
Epoll::ERR x o raise error
Epoll::HUP x o raise hang up

see also man epoll(7)

Installation

Add this line to your application's Gemfile:

gem 'epoll'

And then execute:

$ bundle

Or install it yourself as:

$ gem install epoll

Pro Tips

  • Support call without GVL in CRuby (use rb_thread_call_without_gvl())
  • Close on exec flag set by default if you can use (use epoll_create1(EPOLL_CLOEXEC))
  • Epoll#wait max return array size is 256 on one time (of course, overflowing and then carried next)

Fork Me !

This is experimental implementation. I'm waiting for your idea and Pull Request !

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].